Question

Using Box2D 2.2.0, I'm working on a game using Box2D. The player shoots AABBs. In each step() I move the AABB and handle collisions by going through b2World->QueryAABB( &queryCallback, aabb ). However, my game world is made up of chain shapes. So b2World->QueryAABB is only detecting the AABBs of inclined chain shapes. So my goal at the moment is to get the child index from ReportFixture() so that I can test the AABB against the chainshape's specified edge.

I found this: http://www.box2d.org/forum/viewtopic.php?f=3&t=8902

Following that post, I added the child index to Report Fixture, as seen in the code below.

My problem is that when I get back the childIndex, it's always something along the lines of -1082069312, -1053558930, -1073540884.

//in b2WorldCallbacks.h
class b2QueryCallback
{
public:
   virtual ~b2QueryCallback() {}

   /// Called for each fixture found in the query AABB.
   /// @return false to terminate the query.
   virtual bool ReportFixture(b2Fixture* fixture, int32 childIndex) = 0;
};

and

//in b2World.cpp
struct b2WorldQueryWrapper
{
   bool QueryCallback(int32 proxyId)
   {
      b2FixtureProxy* proxy = (b2FixtureProxy*)broadPhase->GetUserData(proxyId);
      return callback->ReportFixture(proxy->fixture, proxy->childIndex);
   }

   const b2BroadPhase* broadPhase;
   b2QueryCallback* callback;
};

Here is my b2QueryCallback:

class MyQueryCallback : public b2QueryCallback {

    public:
        vector<b2Fixture*> foundFixtures;
        vector<int32> foundIndex;

        bool ReportFixture(b2Fixture* fixture, int32 childIndex) {
            foundFixtures.push_back ( fixture );
            foundIndex.push_back( childIndex );
            return true;
        }
};

In testbed:

// PolyShapes.h, line 85
bool ReportFixture(b2Fixture* fixture, int32 childIndex)

and

//Test.cpp, line 113
bool ReportFixture(b2Fixture* fixture, int32 childIndex)
Was it helpful?

Solution

It looks like you are doing everything correctly. My suspicion would be that part of your project is not being fully compiled afresh with the newly modified headers, so the second parameter to ReportFixture is not even being passed. That is, the calling code is still using the original single parameter version of the function, so childIndex is never pushed onto the callstack.

Are you using Xcode by any chance? Xcode is great at screwing this up when you have precompiled headers - it simply does not detect when they need refreshing. In addition to cleaning and rebuilding, you could try also deleting the 'derived data' - another wonderful idea from Apple that I'm sure is well intentioned, but the implementation seems rushed. Apparently, placing an option to delete the 'derived data' alongside the Build and Clean options would be too obvious, so you can find it hidden away in the Projects tab of the Organizer window. </rant>

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top