Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting EXC_BAD_ACCESS signal received when i tried to get collision detection
    primarykey
    data
    text
    <p>I stuck at this position and don't know what went wrong in this,</p> <p>I have enabled ARC in my project. And i made softBody as follows</p> <p><strong>Ball.h</strong></p> <pre><code> B2Body *body[NUM_SEGMENT]; CCSprite *ball; </code></pre> <p><strong>Ball.mm</strong></p> <pre><code> ball = [CCSprite spriteWithFile:@"Ball1.2.png"]; ball.tag = 1; for(int i=0;i&lt;NUM_SEGMENT;i++){ float theta = deltaAngle*i; float x = radius * cosf(theta); float y = radius * sinf(theta); b2Vec2 circlePosition = b2Vec2(x/PTM_RATIO,y/PTM_RATIO); b2BodyDef bodyDef; bodyDef.type = b2_dynamicBody; bodyDef.position = (center + circlePosition); bodyDef.userData = &amp;ball; body[i] = world-&gt;CreateBody(&amp;bodyDef); outerBodyFixture[i]=body[i]-&gt;CreateFixture(&amp;fixtureDef); [bodies addObject:[NSValue valueWithPointer:body[i]]]; } </code></pre> <p>And I have given physics to the tiles as follows,</p> <p><strong>Tile.h</strong></p> <pre><code>CCSprite *tile; </code></pre> <p><strong>Tile.mm</strong></p> <pre><code>tile = [layer1 tileAt:ccp(i, j)]; tile.tag = 0; b2BodyDef tileDef; tileDef.type = b2_staticBody; tileDef.position.Set((tile.position.x+(tile.contentSize.width/2))/(PTM_RATIO), (tile.position.y + (tile.contentSize.height/2))/PTM_RATIO); tileDef.userData = &amp;tile; tileBody = world-&gt;CreateBody(&amp;tileDef); </code></pre> <p>Now i tried to catch collision detection and I have made code which will print the tag number of colliding bodies. The code is as follows,</p> <pre><code>std::vector&lt;MyContact&gt;::iterator pos; for (pos=_contactListener-&gt;_contacts.begin(); pos != _contactListener-&gt;_contacts.end(); ++pos) { MyContact contact = *pos; b2Body *bodyA = contact.fixtureA-&gt;GetBody(); b2Body *bodyB = contact.fixtureB-&gt;GetBody(); if (bodyA-&gt;GetUserData() != NULL &amp;&amp; bodyB-&gt;GetUserData() != NULL) { </code></pre> <p><strong>At this point Getting ERROR: EXC_BAD_ACCESS</strong></p> <pre><code> CCSprite *spriteA = (__bridge CCSprite *) bodyA-&gt;GetUserData(); </code></pre> <p><strong>At this point Getting ERROR: EXC_BAD_ACCESS</strong></p> <pre><code> CCSprite *spriteB = (__bridge CCSprite *) bodyB-&gt;GetUserData(); printf("contact :%d \n",spriteB.tag); } } </code></pre> <p>Don't Know whats wrong with this code,,Give me some solution for this</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload