Box2d Create Shape Error

Discussion in 'iOS Programming' started by Wellington2k, Jan 5, 2012.

  1. Wellington2k macrumors regular

    Joined:
    Jun 4, 2011
    #1
    Hello.

    Once again I am having trouble with physics.

    I have this code:
    Code:
    bound->CreateShape(bounddef);
    It gives me the error:
    Here is my entire code for making a floor object:
    Code:
    -(void)makebound {
        b2PolygonShape bounddef;
        b2FixtureDef boundfix;
        b2BodyDef boundbodydef;
        b2Body* bound;
        b2Vec2 verticies [4];
        b2Vec2(verticies [0]).Set(0 / ratio, 0 / ratio);
        b2Vec2(verticies [1]).Set(550 / ratio, 0 / ratio);
        b2Vec2(verticies [2]).Set(550 / ratio, 10 / ratio);
        b2Vec2(verticies [3]).Set(0 / ratio, 10 / ratio);
        bounddef.Set(verticies, 6);
        boundfix.shape=&bounddef;
        boundfix.density = 0.0;
        boundfix.friction=0.5;
        boundfix.restitution = 0.3;
        bound->CreateFixture(&boundfix);
        boundbodydef.position.Set(0 / ratio, 390 / ratio);
        bound = World->CreateBody(&boundbodydef);
        bound->CreateShape(bounddef);
        
    }
    What's wrong?
     
  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #2
    You have this type declaration:
    Code:
    b2Body* bound
    Ask yourself: Does the b2Body class have a CreateShape method?

    I assume you can look this up in the reference doc.

    If your answer is "Yes", then point to it in the reference doc. That is, post the URL of the ref doc, showing the existence of that method.


    Also, this code:
    Code:
        bound->CreateFixture(&boundfix);
    
    may be calling CreateFixture on an uninitialized pointer.
     
  3. Wellington2k, Jan 5, 2012
    Last edited: Jan 5, 2012

    Wellington2k thread starter macrumors regular

    Joined:
    Jun 4, 2011
    #3
    I get you.

    Well I'm having an issue with b2World.cpp and b2BlockAllocator.cpp.

    When ever I run my app I get this:
     
  4. Wellington2k thread starter macrumors regular

    Joined:
    Jun 4, 2011
    #4
    I found the problem is not with this error, it's with this code:
    Code:
    -(void)createagain {
        b2BodyDef groundBodyDef;
        groundBodyDef.position.Set(0, 0);
        b2PolygonShape groundBox;
        b2Vec2 verticies [4];
        (verticies [0]).Set(0, 0);
        (verticies [1]).Set(550 / ratio, 0);
        (verticies [2]).Set(550 / ratio, 10 / ratio);
        (verticies [3]).Set(0, 10 / ratio);
        int32 vcount = 4;
        groundBox.Set(verticies, vcount);
        b2Body* groundBody = World->CreateBody(&groundBodyDef);
        groundBody->CreateFixture(&groundBox, 0);
    }
    
    What's wrong with this code?
     
  5. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #5
    What is the error message?

    Or are you saying the code compiles but doesn't run? In that case, post the crash log or other debugging information.

    Posting uncommented code with nothing but a "What's wrong?" isn't a useful description.

    You should describe what you expected to happen, and then describe what actually happened. "I expected it to compile. It didn't, producing the following error message: Actual error message goes here". That's an example of a description.
     
  6. Wellington2k thread starter macrumors regular

    Joined:
    Jun 4, 2011
    #6
    Found out the problem was that is needed to be in the viewdidload function.

    Stay tuned!

    I might need some more help!
     
  7. Wellington2k thread starter macrumors regular

    Joined:
    Jun 4, 2011

Share This Page