Note that there are some explanatory texts on larger screens.

plurals
  1. POEXC_BAD_ACCESS when simply casting a pointer in Obj-C
    text
    copied!<p>Frequent visitor but first post here on StackOverflow, I'm hoping that you guys might be able to help me out with this. I'm fairly new to Obj-C and XCode, and I'm faced with this really... weird... problem. Googling hasn't turned up anything whatsoever. Basically, I get an EXC_BAD_ACCESS signal on a line that doesn't do any dereferencing or anything like that that I can see. Wondering if you guys have any idea where to look for this. I've found a work around, but no idea <em>why</em> this works... The line the broken version barfs out on is the line:</p> <pre><code>LevelEntity *le = entity; </code></pre> <p>where I get my bad access signal.</p> <p>Here goes:</p> <p><strong><em>THIS VERSION WORKS</em></strong></p> <pre><code> NSArray *contacts = [self.body getContacts]; for (PhysicsContact *contact in contacts) { PhysicsBody *otherBody; if (contact.bodyA == self.body) { otherBody = contact.bodyB; } if (contact.bodyB == self.body) { otherBody = contact.bodyA; } id entity = [otherBody userData]; if (entity != nil) { LevelEntity *le = entity; CGPoint point = [contact contactPointOnBody:otherBody]; } } </code></pre> <p><strong><em>THIS VERSION DOESNT WORK</em></strong></p> <pre><code> NSArray *contacts = [self.body getContacts]; for (NSUInteger i = 0; i &lt; [contacts count]; i++) { PhysicsContact *contact = [contacts objectAtIndex:i]; PhysicsBody *otherBody; if (contact.bodyA == self.body) { otherBody = contact.bodyB; } if (contact.bodyB == self.body) { otherBody = contact.bodyA; } id entity = [otherBody userData]; if (entity != nil) { LevelEntity *le = entity; CGPoint point = [contact contactPointOnBody:otherBody]; } } </code></pre> <p>Here, the <em>only</em> difference between the two examples is the way I enumerate through my array. In the first version (which works) I use for (... in ...), where as in the second I use for (...; ...; ...). As far as I can see, these should be the same.</p> <p>This is seriously weirding me out. Anyone have any similar experience or idea whats going on here? Would be really great :)</p> <p>Cheers, Alex</p>
 

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