이 오류는 실제 장치에서만 발생합니다. Xcode 6에서 시뮬레이터를 실행할 때 충돌이 발생하지 않습니다.장치에서 시뮬레이션을 진행할 때 exc_bad_access
나는 외부 공간을 만들고 하늘을 가로 질러 무작위로 별을 긋습니다. 3 개의 SKEmitterNodes를 사용하여 심도를 시뮬레이트하여 별 모양을 설정하는 장면 [goToSpace]가 호출됩니다. 그런 다음 스타 촬영을 보내는 타이머가 초기화됩니다.
별의 초기화에서 3 개의 SKEmitterNode의 시뮬레이션을 진행시켜 별이 하늘을 가득 채울 필요가 있습니다. [emitterNode1 advanceSimulationTime : lifetime] 행이 호출되면 나는 exc_bad_access를 얻는다. 튜토리얼을 따라 NSZombie를 활성화 시켰습니다.
exc_bad_access를 얻는 이유는 내 트랙의 수명을 단축시킬 수 없습니다. 내가 사용이 스택을 제공 Parse.com의 충돌보고 :
> Stack Trace Thread 0 (crashed) 0 libsystem_platform.dylib
> OSSpinLockLock @ 0x4 1 SpriteKit SKSpinLockSync(int*, void()
> block_pointer) @ 0x20 2 SpriteKit
> -[SKTexture loadImageData] @ 0xec 3 SpriteKit
> -[SKTexture size] @ 0x28 4 SpriteKit SKCEmitterSprite::update(double) @ 0x117c 5 CorpBoard @ 0x48d44 6 CorpBoard @ 0xfbc50 7 CorpBoard @
> 0xfa6f0 8 CorpBoard @ 0xfa070 9 UIKit
> -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] @ 0x21c 10 UIKit
> -[UITableView _updateVisibleCellsNow:isRecursive:] @ 0x934 11 UIKit
> -[UITableView layoutSubviews] @ 0xa8 12 UIKit
> -[UIView(CALayerDelegate) layoutSublayersOfLayer:] @ 0x238 13 QuartzCore
> -[CALayer layoutSublayers] @ 0xa4 14 QuartzCore CA::Layer::layout_if_needed(CA::Transaction*) @ 0x13c 15 QuartzCore
> CA::Layer::layout_and_display_if_needed(CA::Transaction*) @ 0x1c 16
> QuartzCore CA::Context::commit_transaction(CA::Transaction*) @ 0x110
> 17 QuartzCore CA::Transaction::commit() @ 0x1b0 18 QuartzCore
> CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned
> long, void*) @ 0x4c 19 CoreFoundation
> __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ @ 0x1c 20 CoreFoundation
> __CFRunLoopDoObservers @ 0x164 21 CoreFoundation
> __CFRunLoopRun @ 0x340 22 CoreFoundation CFRunLoopRunSpecific @ 0x188 23 GraphicsServices GSEventRunModal @ 0xa4 24 UIKit UIApplicationMain
> @ 0x5cc 25 CorpBoard @ 0x5be80 26 libdyld.dylib start @ 0x0 Thread 1 0
> libsystem_kernel.dylib kevent64 @ 0x8 1 libdispatch.dylib
> _dispatch_mgr_invoke @ 0x110 2 libdispatch.dylib
> _dispatch_mgr_thread @ 0x30 Thread 2 0 libsystem_kernel.dylib
> __workq_kernreturn @ 0x8 1 libsystem_pthread.dylib
> _pthread_wqthread @ 0x3dc 2 libsystem_pthread.dylib start_wqthread @ 0x0 Thread 3 0 libsystem_kernel.dylib
> __workq_kernreturn @ 0x8 1 libsystem_pthread.dylib
> _pthread_wqthread @ 0x3dc 2 libsystem_pthread.dylib start_wqthread @ 0x0 Thread 4 0 libsystem_kernel.dylib
> __workq_kernreturn @ 0x8 1 libsystem_pthread.dylib
> _pthread_wqthread @ 0x3dc 2 libsystem_pthread.dylib start_wqthread @ 0x0 Thread 5 0 libsystem_kernel.dylib
> __workq_kernreturn @ 0x8 1 libsystem_pthread.dylib
> _pthread_wqthread @ 0x3dc 2 libsystem_pthread.dylib start_wqthread @ 0x0 Thread 6 0 libsystem_kernel.dylib
> __workq_kernreturn @ 0x8 1 libsystem_pthread.dylib
> _pthread_wqthread @ 0x3dc 2 libsystem_pthread.dylib start_wqthread @ 0x0 Thread 7 0 libsystem_kernel.dylib mach_msg_trap @ 0x8 1
> libsystem_kernel.dylib mach_msg @ 0x44 2 CoreFoundation
> __CFRunLoopServiceMachPort @ 0xc4 3 CoreFoundation
> __CFRunLoopRun @ 0x3a8 4 CoreFoundation CFRunLoopRunSpecific @ 0x188 5 Foundation
> -[NSRunLoop(NSRunLoop) runMode:beforeDate:] @ 0x138 6 Foundation
> -[NSRunLoop(NSRunLoop) run] @ 0x5c 7 CorpBoard @ 0x206a28 8 Foundation
> __NSThread__main__ @ 0x42c 9 libsystem_pthread.dylib
> _pthread_body @ 0xa0 10 libsystem_pthread.dylib
> _pthread_start @ 0x9c 11 libsystem_pthread.dylib thread_start @ 0x0 Thread 8 0 libsystem_kernel.dylib mach_msg_trap @ 0x8 1
> libsystem_kernel.dylib mach_msg @ 0x44 2 CoreFoundation
> __CFRunLoopServiceMachPort @ 0xc4 3 CoreFoundation
> __CFRunLoopRun @ 0x3a8 4 CoreFoundation CFRunLoopRunSpecific @ 0x188 5 CFNetwork
> +[NSURLConnection(Loader) _resourceLoadLoop:] @ 0x1b4 6 Foundation
> __NSThread__main__ @ 0x42c 7 libsystem_pthread.dylib
> _pthread_body @ 0xa0 8 libsystem_pthread.dylib
> _pthread_start @ 0x9c 9 libsystem_pthread.dylib thread_start @ 0x0 Thread 9 0 libsystem_kernel.dylib
> __select @ 0x8 1 CoreFoundation
> __CFSocketManager @ 0x290 2 libsystem_pthread.dylib
> _pthread_body @ 0xa0 3 libsystem_pthread.dylib
> _pthread_start @ 0x9c 4 libsystem_pthread.dylib thread_start @ 0x0 Thread 10 0 libsystem_kernel.dylib mach_msg_trap @ 0x8 1
> libsystem_kernel.dylib mach_msg @ 0x44 2 CoreFoundation
> __CFRunLoopServiceMachPort @ 0xc4 3 CoreFoundation
> __CFRunLoopRun @ 0x3a8 4 CoreFoundation CFRunLoopRunSpecific @ 0x188 5 CoreFoundation CFRunLoopRun @ 0x6c 6 CoreMotion @ 0x4298c 7
> libsystem_pthread.dylib
> _pthread_body @ 0xa0 8 libsystem_pthread.dylib
> _pthread_start @ 0x9c 9 libsystem_pthread.dylib thread_start @ 0x0 Thread 11 0 libsystem_kernel.dylib
> __workq_kernreturn @ 0x8 1 libsystem_pthread.dylib
> _pthread_wqthread @ 0x3dc 2 libsystem_pthread.dylib start_wqthread @ 0x0
관련 코드 :
NSTimer *space;
-(void)goToSpace {
[self shootingStar];
double lifetime;
SKEmitterNode *emitterNode1 = [self starFieldEmitter:[SKColor lightGrayColor] starSpeedY:1 starsPerSecond:.1 starScaleFactor:0.08];
lifetime = self.frame.size.height * [[UIScreen mainScreen] scale]/1;
[emitterNode1 advanceSimulationTime:lifetime];
emitterNode1.zPosition = -10;
[self addChild:emitterNode1];
SKEmitterNode *emitterNode2 = [self starFieldEmitter:[SKColor lightGrayColor] starSpeedY:.8 starsPerSecond:.08 starScaleFactor:0.06];
emitterNode2.zPosition = -11;
lifetime = self.frame.size.height * [[UIScreen mainScreen] scale]/.8;
[emitterNode2 advanceSimulationTime:lifetime];
[self addChild:emitterNode2];
SKEmitterNode *emitterNode3 = [self starFieldEmitter:[SKColor grayColor] starSpeedY:.5 starsPerSecond:.5 starScaleFactor:0.03];
emitterNode3.zPosition = -12;
lifetime = self.frame.size.height * [[UIScreen mainScreen] scale]/.5;
[emitterNode3 advanceSimulationTime:lifetime];
[self addChild:emitterNode3];
space = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(shootingStar) userInfo:nil repeats:YES];
}
-(SKEmitterNode *)starFieldEmitter:(SKColor *)color starSpeedY:(CGFloat)starSpeedY starsPerSecond:(CGFloat)starsPerSecond starScaleFactor:(CGFloat) starScaleFactor {
SKEmitterNode *emitterNode = [SKEmitterNode node];
CGFloat lifetime = self.frame.size.height * [[UIScreen mainScreen] scale]/starSpeedY;
emitterNode.particleTexture = [SKTexture textureWithImage:[UIImage imageNamed:@"stars"]];
emitterNode.particleBirthRate = starsPerSecond;
emitterNode.particleColor = [SKColor lightGrayColor];
emitterNode.particleSpeed = starSpeedY * -1;
emitterNode.particleScale = starScaleFactor;
emitterNode.particleColorBlendFactor = 1;
emitterNode.particleLifetime = lifetime;
int rndValue = 1 + arc4random() % (45 - 1);
emitterNode.particleRotation = rndValue;
emitterNode.position = CGPointMake(self.frame.size.width/2, self.frame.size.height);
emitterNode.particlePositionRange = CGVectorMake(self.frame.size.width, self.frame.size.height);
return emitterNode;
}
-(BOOL) getYesOrNo {
int tmp = (arc4random() % 30)+1;
if(tmp % 5 == 0)
return YES;
return NO;
}
-(void)shootingStar {
BOOL left = [self getYesOrNo];
int xPos = 0;
int height = self.frame.size.height;
int yPos = 1 + arc4random() % (height - 1);
if (left) {
xPos = -50;
} else {
xPos = self.frame.size.width + 50;
}
SKEmitterNode *shootingstar = [SKEmitterNode node];
shootingstar = [NSKeyedUnarchiver unarchiveObjectWithFile:[[NSBundle mainBundle] pathForResource:@"spark" ofType:@"sks"]];
CGPoint xy = CGPointMake(xPos, yPos);
shootingstar.position = xy;
shootingstar.name = @"shootingStar";
shootingstar.zPosition = -2.0;
shootingstar.targetNode = self.scene;
[self addChild:shootingstar];
//make random size to simulate distance
float val = [self randFloatBetween:.1 and:.5];
SKAction *scale = [SKAction scaleBy:val duration:0];
[shootingstar runAction: scale completion:nil];
//now set speed depending on size (smaller = farther = slower)
int dur = 0;
if (val < .2) dur = 5;
else if (val < .35) dur = 3;
else dur = 2;
int moveY = -500 + arc4random() % (500 - -500);
int moveX;
if (left) {
moveX = 500;
} else {
moveX = -500;
}
SKAction *move = [SKAction moveByX:moveX y:moveY duration:dur];
int waitDuration = 2 + arc4random() % (5 - 2);
SKAction *wait = [SKAction waitForDuration:waitDuration];
SKAction *sequence = [SKAction sequence:@[wait, move]];
[shootingstar runAction:sequence completion:^{
[shootingstar removeFromParent];
//[self shootingStar];
}];
}
-(float) randFloatBetween:(float)low and:(float)high {
float diff = high - low;
return (((float) rand()/RAND_MAX) * diff) + low;
}
space = [NSTimer scheduledTimerWith ... Sprite Kit와 함께 NSTimer를 사용하지 마십시오. 참조 : http://stackoverflow.com/a/23978854/201863 – LearnCocos2D
팁 주셔서 감사합니다. 이제 SKAction을 반복 사용하여 영원히 반복하십시오. –