MyContactListener in separate file

Hello,

I got a behaviour I did not expect when I created my own contact listener.
I I create my class in the Main file, as specified in the tutorial http://www.iforce2d.net/b2dtut/collision-callbacks, No problem, everything works as expected. But I tried to create the same class in a separate MyCoontactListener.cpp and MyCollisionListener.h files, and I got a segfault error form b2Contact::update().

Is there a reason for this error but my beginners' skills?
Thanks,
LH
It should not make a difference what file things are in. You must have changed something else as well. Make sure that the instance of the contact listener you use does not go out of scope while you're using it. For example, this will cause a crash:
Code:
{
    MyContactListener listener;
    world->SetContactListener( &listener );
}

... because the instance of the listener goes out of scope and is destroyed at the last curly brace there, but the world will try to use it -> crash.
Allright thanks!

It sure is not a scope problem. Well, I guess I did change something.. But I did put the same class definition back on the top of my main.cpp and the whole program is back on tracks. Good enough for me, I'd say 😉

Thanks for the answer.

Original thread: https://box2d.org/forum/viewtopic.php?t=9414