I ran into this a while ago but just worked around the problem instead of 
fixing it. I'm now going back and fixing my "TODOs" and hoping someone has 
some idea of what is going on here.
Basically, there seems to be some weird issue with a shared_ptr that I'm 
holding onto in the javascript layer of which causes a bad_weak_ptr when I 
call shared_from_this(). What is seriously weird about this is it only 
happens when I call directly on that object. For example, I have the 
following code on my javascript side just to test this oddity:

onReadProducts: () => {
    this.currentBusiness().data.readProductsAsync(index, count, name);

Which maps to the following methods on my C++ side

void App::testBusiness(std::shared_ptr<Business> businessArg) {
    printf("is App null - %d\n", (this == nullptr));
    printf("is App->shared_from_this null - %d\n", (this->shared_from_this() 
== nullptr));
    if (this->businessQuery->size() == 0) {
        printf("this->businessQuery->size() has no size\n");
    else {
        printf("this->businessQuery->at(0) is null - %d\n", (this->
businessQuery->at(0) == nullptr));
        printf("this->businessQuery->at(0)->shared_from_this() is null - 
%d\n", (this->businessQuery->at(0)->shared_from_this() == nullptr));
        printf("is at(0) same as passed in business %d\n", (this->
businessQuery->at(0) == businessArg));
        printf("businessArg is null - %d\n", (businessArg == nullptr));
        printf("businessArg->shared_from_this() is null - %d\n", (
businessArg->shared_from_this() == nullptr));
void Business::readProductsAsync(unsigned int index, unsigned int count, std
::string name)
    printf("businessArg is null - %d\n", (this == nullptr));
    printf("businessArg->shared_from_this() is null - %d\n", (this->
shared_from_this() == nullptr));
    // There is more here but it doesn't matter

When I run this in the browser I get the following output

App::testBusiness - is App null - 0
App::testBusiness - is App->shared_from_this null - 0
App::testBusiness - this->businessQuery->at(0) is null - 0
App::testBusiness - this->businessQuery->at(0)->shared_from_this() is null - 
App::testBusiness - is at(0) same as passed in business 1
App::testBusiness - businessArg is null - 0
App::testBusiness - businessArg->shared_from_this() is null - 0
Business::readProductsAsync - this is null - 0
Compiled code throwing an exception, 5507792,19624,3140
can_catch on 5507792
Resuming exception 5507792,5507792
Uncaught 5507792

So when I pass my handle of std::shared_ptr<Business> to App, I'm able to 
perform a shared_from_this on that handle but when I call a method on that 
handle directly I get a bad_weak_ptr? What's going on here? This seems like 
a strange and crazy bug.

You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to emscripten-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to