Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This might be a bit late but since there has been no answers...</p> <p>I do not think, your selector is called once more, but rather the display link's thread is in the middle of your draw frame method. In any case, the problem is quite the same.. This is multithreading and by trying to dealloc some objects in one thread while using them in another will usually result in a conflict.</p> <p>Probably the easiest solution would be putting a flag and an "if statement" in your draw frame method as </p> <pre><code>if(schaduledForDestruction) { [self destroy]; return; } </code></pre> <p>and then wherever you are invalidating your display link set "schaduledForDestruction" to YES.</p> <p>If you really think the display link calls tis method again, you could use another if inside that one "destructionInProgress".</p> <p>If you do not want to change the draw frame method, you could try forcing a new selector to the display link...</p> <pre><code>CADisplayLink *myDisplayLink; BOOL resourcesLoaded; SEL drawSelector; - (void)destroy { if(resourcesLoaded) { [myDisplayLink invalidate]; //free resources resourcesLoaded = NO; } } - (void)metaLevelDraw { [self performSelector:drawSelector]; } - (void)drawFrame { //draw stuff } - (void)beginAnimationing { drawSelector = @selector(drawFrame); myDisplayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(metaLevelDraw)]; [myDisplayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; } - (void)endAnimationing { drawSelector = @selector(destroy); } </code></pre> <p>or just consider something like this (but I can't say this is safe. If the newly created display link can run the selector on a different thread then the original, it solves nothing)..</p> <pre><code>CADisplayLink *myDisplayLink; BOOL resourcesLoaded; - (void)destroy { if(resourcesLoaded) { [myDisplayLink invalidate]; //free resources resourcesLoaded = NO; } } - (void)drawFrame { //draw stuff } - (void)beginAnimationing { myDisplayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(drawFrame)]; [myDisplayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; } - (void)endAnimationing { [myDisplayLink invalidate]; myDisplayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(destroy)]; [myDisplayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload