mirror of https://github.com/axmolengine/axmol.git
invalidate NSTimer instance in destroy to prevent memory leak
This commit is contained in:
parent
013b3a328f
commit
2e70380dd9
|
@ -34,6 +34,7 @@
|
|||
}
|
||||
@property (readwrite) int interval;
|
||||
-(void) startMainLoop;
|
||||
-(void) stopMainLoop;
|
||||
-(void) doCaller: (id) sender;
|
||||
-(void) setAnimationInterval:(double)interval;
|
||||
+(id) sharedDirectorCaller;
|
||||
|
|
|
@ -58,6 +58,7 @@ static id s_sharedDirectorCaller;
|
|||
|
||||
+(void) destroy
|
||||
{
|
||||
[s_sharedDirectorCaller stopMainLoop];
|
||||
[s_sharedDirectorCaller release];
|
||||
s_sharedDirectorCaller = nil;
|
||||
}
|
||||
|
@ -76,25 +77,29 @@ static id s_sharedDirectorCaller;
|
|||
-(void) startMainLoop
|
||||
{
|
||||
// Director::setAnimationInterval() is called, we should invalidate it first
|
||||
[displayLink invalidate];
|
||||
displayLink = nil;
|
||||
|
||||
displayLink = [NSClassFromString(@"CADisplayLink") displayLinkWithTarget:self selector:@selector(doCaller:)];
|
||||
[displayLink setFrameInterval: self.interval];
|
||||
[displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
|
||||
[self stopMainLoop];
|
||||
|
||||
displayLink = [NSClassFromString(@"CADisplayLink") displayLinkWithTarget:self selector:@selector(doCaller:)];
|
||||
[displayLink setFrameInterval: self.interval];
|
||||
[displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
|
||||
}
|
||||
|
||||
-(void) stopMainLoop
|
||||
{
|
||||
[displayLink invalidate];
|
||||
displayLink = nil;
|
||||
}
|
||||
|
||||
-(void) setAnimationInterval:(double)intervalNew
|
||||
{
|
||||
// Director::setAnimationInterval() is called, we should invalidate it first
|
||||
[displayLink invalidate];
|
||||
displayLink = nil;
|
||||
// Director::setAnimationInterval() is called, we should invalidate it first
|
||||
[self stopMainLoop];
|
||||
|
||||
self.interval = 60.0 * intervalNew;
|
||||
self.interval = 60.0 * intervalNew;
|
||||
|
||||
displayLink = [NSClassFromString(@"CADisplayLink") displayLinkWithTarget:self selector:@selector(doCaller:)];
|
||||
[displayLink setFrameInterval: self.interval];
|
||||
[displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
|
||||
displayLink = [NSClassFromString(@"CADisplayLink") displayLinkWithTarget:self selector:@selector(doCaller:)];
|
||||
[displayLink setFrameInterval: self.interval];
|
||||
[displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
|
||||
}
|
||||
|
||||
-(void) doCaller: (id) sender
|
||||
|
|
Loading…
Reference in New Issue