I keep getting a crash when using UIKit Dynamics
. It doesn't happen every time the code runs, but it happens fairly often. Has anyone come across this?
Assertion failed: (a.x >= 0.0f && a.y >= 0.0f),
function SolveVelocityConstraints, file
/SourceCache/PhysicsKit/PhysicsKit-
4.6/PhysicsKit/Box2D/Dynamics/Contacts/b2ContactSolver.cpp, line 422.
This is the code that generates the error. I'm guessing it has something to do with the collision boundaries.
UIDynamicAnimator *animator =
[[UIDynamicAnimator alloc] initWithReferenceView:self];
UIGravityBehavior *gravityBehavior =
[[UIGravityBehavior alloc] initWithItems:@[self.rewardButton]];
gravityBehavior.gravityDirection = CGVectorMake(0.0, 1.0);
gravityBehavior.magnitude = 1.0f;
UICollisionBehavior* collisionBehavior =
[[UICollisionBehavior alloc] initWithItems:@[self.rewardButton,
self.processingView]];
collisionBehavior.collisionDelegate = self;
UIEdgeInsets insets = UIEdgeInsetsMake(-700, 60, 200, 60);
[collisionBehavior setTranslatesReferenceBoundsIntoBoundaryWithInsets:insets];
UIDynamicItemBehavior* propertiesBehavior =
[[UIDynamicItemBehavior alloc] initWithItems:@[self.rewardButton]];
float elasticity = arc4random() % 4 * 0.1 + 0.1f;
propertiesBehavior.elasticity = elasticity;
[animator addBehavior:propertiesBehavior];
[animator addBehavior:gravityBehavior];
[animator addBehavior:collisionBehavior];
self.animator = animator;