Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6767989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:01:05+00:00 2026-05-26T15:01:05+00:00

I was reading the box2d manual and I saw that inter-frame contacts could only

  • 0

I was reading the box2d manual and I saw that inter-frame contacts could only be picked up using b2ContactListener.

I created a class ActorListener (all active world objects are actors)

class ActorListener : public b2ContactListener
{ 
    public :
    ActorListener();
    ~ActorListener();

    virtual void BeginContact(b2Contact* contact);
    virtual void EndContact(b2Contact* contact);
    virtual void PreSolve(b2Contact* contact, const b2Manifold* oldManifold);    
    virtual void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse);
};

And added it to my world when the game is initializing:

    Listener = new ActorListener();
    world->SetContactListener(Listener);

But as soon as an there is a collision I get an error in b2Contact.cpp

    if (wasTouching == false && touching == true && listener)
{
    listener->BeginContact(this); //EXC_BAD_ACCESS
}

Any ideas? Am I doing it wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:01:06+00:00Added an answer on May 26, 2026 at 3:01 pm

    The setup code is correct. I would suggest some changes to the ActorListener class:

    class ActorListener : public b2ContactListener
    { 
        private :
        void BeginContact(b2Contact* contact);
        void EndContact(b2Contact* contact);
        void PreSolve(b2Contact* contact, const b2Manifold* oldManifold);    
        void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse);
    };
    

    I’m not sure if these fixes change your problem. Changing my contact listener by adding constructor, destructor and changing to public virtual methods still did not cause a crash. So I assume it’s unlikely that the class interface is the problem.

    Nevertheless, unless you need a constructor or destructor you can omit those. You should also remove the virtual keyword, as you provide the concrete implementation and don’t plan on subclassing ActorListener (right?). Non-virtual methods are a bit faster. Finally the methods should be private because only Box2D will call them, no other code should be allowed to call the methods in the ActorListener class. If you get compile errors after making these changes, then it may be related to the crash.

    The crash indicates that in all likelihood the listener no longer points to valid memory, ie it has been deallocated. The other possibility might be that the actual code in BeginContact causes the crash but for some reason the debugger halts at the line making the call. You might want to set a breakpoint in BeginContact. And add the BeginContact implementation to your question.

    Finally, even though I assume the compiler will check this, is the file extension of the ActorListener implementation file set to .mm?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Reading through the following instruction table manual I see that integer multiplication is often
Reading Apple documentation i found that UIEventTypeMotion is useful only to intercept Shake. It
Reading across difference lineage of CPU created by intel , many questions aroused in
Reading manual about Sling http://sling.apache.org/site/46-line-blog.html added folder blog and blog.html to destination: \launchpad\content\src\main\resources\content\ but
reading the documentation for java org.w3c.dom.ls it seems as a Element only can be
Reading source code of my current project, I see: [self retain] in one class,
Reading through the CKEditor documentation , I see that they have an option to
I was reading Microsoft's Class Room Training Materil. I read the following Unboxing Unboxing
I've been reading about using ExternalInterface to have Flash communicate with JavaScript. I need
Reading the code of many javascript libraries, I see that many developers use to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.