我正在制作一个应用程序,当你触摸一个物体时,它会移动。在它移动后,它会被释放。超过 30 次移动后,抛出了一个名为 EXC_BAD_ACESS 且 CODE = 1 的异常。为什么会抛出异常?
if (myselunit!=nil) {
touch = [touches anyObject];
location = [touch locationInView:[touch view]];
location = [[CCDirector sharedDirector] convertToGL:location]; // Locks on to touch's coordinates
realx = location.x;
realy = location.y;
realDest = ccp(location.x, location.y);
int offRealX = realx - myselunit.position.x; // exception occurs here
int offRealY = realy - myselunit.position.y;
float length = sqrtf((offRealX*offRealX)+(offRealY*offRealY));
float velocity = 50*myselunit.speed; // 480pixels/1sec
float realMoveDuration = length/velocity;
[myselunit runAction:[CCSequence actions:[CCMoveTo actionWithDuration:realMoveDuration position:realDest],[CCCallFuncN actionWithTarget:self selector:@selector(spriteMoveFinished:)],nil]];
// [myselunit runAction:[CCSequence actions:[CCCallFuncN actionWithTarget:self selector:@selector(staminaUse:)],nil]];
NSLog(@"%f",location.x);
myselunit = nil;
}
这是 myselunt 的回流错误列表:
回流:
线程 1
0x1fa509f: movl (%edi), %esi
if (myselunit!=nil && myselunit.unitType != 0) {
0x19f9e99: addl $28, %esp
[handler.delegate performSelector:helper.touchesSel withObject:mutableTouches withObject:event]; [CCTouchDispatcher touches:withEvent:withTouchType:] 1 [self touches:touches withEvent:event withTouchType:kCCTouchBegan]; 4 -[CCTouchDispatcher touchesBegan:withEvent:] 1 [touchDelegate_touchesBegan:touches withEvent:event]; 5 - [EAGLView touchesBegan:withEvent:] 1 0x8562cf: movl 6769896(%esi), %eax 6 - [UIWindow_sendTouchesForEvent:] 1 0x82e626: xorl %eax, %eax 18 UIApplicationMain 1 int retVal = UIApplicationMain(argc, argv, 无,@“AppDelegate”);19 main // (内存错误) 1 0x2815: movl %eax, (%esp) 20 开始 0线程 3 0x9062690a:jae 0x9062691a;kevent + 26 0 kevent 1 libdispatch.dylib`_dispatch_mgr_thread: 2_dispatch_mgr_thread 1
- 线程 6 0x9062583e:jae 0x9062584e;__psynch_cvwait + 26 0_psynch_cvwait 1 0x97a76ed9: movl %ebx, %ecx 4_pthread_start 1