swift - Odd EXC_BAD_ACCESS when calling contactTestBetweenBody -
i have 3d scene created in scene kit comprising area surrounded invisible walls , want lob physics objects area in such way can't escape once they're in. had mind achieve in following fashion:
- create wall object
- create 'solidifier' fits neatly inside walls
- set each object's
isinscene
variable false - lob them in vague direction of solidifier
- upon each update, if object touching solidifier not touching walls, change collision mask include walls , set
isinscene
true don't have check again.
this seems work well, every (and sadly quite often) exc_bad_access error out of nowhere. offending method seems contacttestbetweenbody, using determine when object touching either walls or solidifier @ times when normal collision detection turned off. necessary prevent objects bouncing off outside of wall object.
here's small snippet of code illustrate. incidentally, 'objects' structure retains reference node along other useful details:
if let solid = solidifier?.physicsbody, let wall = walls?.physicsbody { let world = scene.physicsworld in 0 ..< objects.count { if objects[i].isinscene == false, let body = objects[i].node.physicsbody { let contactsolidifier = world.contacttestbetweenbody(body, andbody: solid, options: nil) if contactsolidifier != nil { let contactwall = world.contacttestbetweenbody(body, andbody: wall, options: nil) if contactwall == nil { objects[i].isinscene = true body.collisionbitmask = collisionmask.allsolids.rawvalue } } } } }
i found much, better solution problem plain didn't think of reason. forget ridiculously convoluted means of keeping objects in view. instead, make area want retain objects within , reverse facet direction , normals.
what didn't realise scenekit uses backface culling on collision detection too, if physics object hits outside of object inside out pass clean through.
i still interested know reason bad access error still though, contact test methods useful , may want use them other reasons in future.
Comments
Post a Comment