QCView race condition crash when removing from superview

Originator:me
Number:rdar://10235887 Date Originated:04-Oct-2011 10:20 PM
Status:Open Resolved:
Product:Mac OS X Product Version:10.7.2
Classification:Crash/Hang/Data Loss Reproducible:Often
 
While a QCView is rendering, removing it from its superview causes the rendering thread to crash.

Background:
I have a source list-style application, where one of the "sources" displays a QCView. When the source's view becomes visible, the source (an NSViewController subclass) sends -startRendering to its QCView. When the view is about to be removed, the source sends -stopRendering to the QCView, and then the source selection code swaps out that view hierarchy for another source's. 

When the source's view is swapped out, often the rendering thread will crash. It seems that if a frame is in progress, rendering continues until the frame has completed (that is, the -stopRendering call is asynchronous). But the view has already been removed, and the OpenGL context is now invalid, so the renderer crashes.

Using -pauseRendering instead of -stopRendering, I haven't seen any crashes.


To reproduce:
Have a QCView running a composition.

    [self.qcView startRendering];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 5.0 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
        [self.qcView stopRendering]; // Omit this to crash every time; include this to crash most times
        [self.qcView removeFromSuperview];
    });


Desired behavior:
QC should handle its OpenGL context going away (btw that's speculation). Make it not crash like -pauseRendering. Or, make -stopRendering synchronous so it doesn't return until it's safe to remove the view.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!