Re: Cocoa window stops responding
On Apr 29, 2015, at 12:38 AM, Nisar Ahmed nisar@gmail.com wrote: I think I have found the culprit, I have subclassed NSOpenGLView where in drawRect, I am rendering a IOSurface based texture using CVDisplayLink, although I don't know why it is causing the screen to freeze but when I moved the rendering code from CVDisplayLink to dispatch timer the problem seems to have disappeared. Inside CVDisplay callback I was calling [view setNeedsDisplay:YES] which I think is a correct way of calling drawRect from background thread? No. You should shunt the call to -setNeedsDisplay: to the main thread. Use an asynchronous mechanism to do so, though (e.g. dispatch_async(dispatch_get_main_queue(), …)); avoid blocking the display link thread. while inside timer I am directly calling [view drawRect:NSZeroRect]. It is never correct to call a view's -drawRect: like that. If you need to a view to draw itself immediately, you can call -display. However, you generally shouldn't do that, either. Just call -setNeedsDisplay: from your timer, if you're going to use a timer. But better to continue to use CVDisplayLink. Regards, Ken ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Cocoa window stops responding
I think I have found the culprit, I have subclassed NSOpenGLView where in drawRect, I am rendering a IOSurface based texture using CVDisplayLink, although I don't know why it is causing the screen to freeze but when I moved the rendering code from CVDisplayLink to dispatch timer the problem seems to have disappeared. Inside CVDisplay callback I was calling [view setNeedsDisplay:YES] which I think is a correct way of calling drawRect from background thread? while inside timer I am directly calling [view drawRect:NSZeroRect]. I still need to know why... On Mon, Apr 27, 2015 at 3:22 PM, Uli Kusterer witness.of.teacht...@gmx.net wrote: On 27 Apr 2015, at 10:53, Nisar Ahmed nisar@gmail.com wrote: My application has a UI having a main window which contains many views such as NSTableView, NSOutlineView, NSOpenGLView, many NSTextFields etc... The applications works normally but after some time the UI stops responding to the mouse clicks, the application does not hang but it seems that all the views stop redrawing itself. I have tried many things but fails to prevent or reproduce the behaviour. Need some advice on how to fix or atleast find out what is causing such behaviour. I am updating all UI controls on the main thread and using Cocoa bindings heavily.. apparently there is no memory leaks, I am using Xcode 6.1 on Mavericks My first suspects if a window stops drawing are always: 1) Drawing attributes that bleed out (e.g. setting the color to white at some point but never back to black, so the next iteration starts out with white instead of the default black) and aren’t wrapped in saveGState 2) Calls to setNeedsDisplay: or display or the like while a drawRect: is running (e.g. setNeedsDisplay: causes drawRect: which sets a property that calls setNeedsDisplay: again which causes a drawRect: on the next run loop iteration, making your Mac constantly redraw stuff until that’s all it does, or even worse manipulating the view hierarchy while the OS is iterating views to draw them). 3) Threaded code that manipulates the UI from another thread than the main thread. There are very few, very specific circumstances under which you may manipulate and draw views and view hierarchies on a non-main thread (or call setNeedsDisplay: or display), so if you do not for a fact know that this is documented as being OK, you probably shouldn’t do it. This case in particular has often screwed up drawing in such a way that the entire window just became a white sheet. I presume you’ve done the usual, i.e. ran Analyze and fixed all it complained about, as well as Instruments. Cheers, -- Uli Kusterer “The Witnesses of TeachText are everywhere...” http://zathras.de ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Cocoa window stops responding
My application has a UI having a main window which contains many views such as NSTableView, NSOutlineView, NSOpenGLView, many NSTextFields etc... The applications works normally but after some time the UI stops responding to the mouse clicks, the application does not hang but it seems that all the views stop redrawing itself. I have tried many things but fails to prevent or reproduce the behaviour. Need some advice on how to fix or atleast find out what is causing such behaviour. I am updating all UI controls on the main thread and using Cocoa bindings heavily.. apparently there is no memory leaks, I am using Xcode 6.1 on Mavericks Please help! ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Cocoa window stops responding
On 27 Apr 2015, at 10:53, Nisar Ahmed nisar@gmail.com wrote: My application has a UI having a main window which contains many views such as NSTableView, NSOutlineView, NSOpenGLView, many NSTextFields etc... The applications works normally but after some time the UI stops responding to the mouse clicks, the application does not hang but it seems that all the views stop redrawing itself. I have tried many things but fails to prevent or reproduce the behaviour. Need some advice on how to fix or atleast find out what is causing such behaviour. I am updating all UI controls on the main thread and using Cocoa bindings heavily.. apparently there is no memory leaks, I am using Xcode 6.1 on Mavericks My first suspects if a window stops drawing are always: 1) Drawing attributes that bleed out (e.g. setting the color to white at some point but never back to black, so the next iteration starts out with white instead of the default black) and aren’t wrapped in saveGState 2) Calls to setNeedsDisplay: or display or the like while a drawRect: is running (e.g. setNeedsDisplay: causes drawRect: which sets a property that calls setNeedsDisplay: again which causes a drawRect: on the next run loop iteration, making your Mac constantly redraw stuff until that’s all it does, or even worse manipulating the view hierarchy while the OS is iterating views to draw them). 3) Threaded code that manipulates the UI from another thread than the main thread. There are very few, very specific circumstances under which you may manipulate and draw views and view hierarchies on a non-main thread (or call setNeedsDisplay: or display), so if you do not for a fact know that this is documented as being OK, you probably shouldn’t do it. This case in particular has often screwed up drawing in such a way that the entire window just became a white sheet. I presume you’ve done the usual, i.e. ran Analyze and fixed all it complained about, as well as Instruments. Cheers, -- Uli Kusterer “The Witnesses of TeachText are everywhere...” http://zathras.de ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Cocoa window stops responding
On 27 Apr 2015, at 09:53, Nisar Ahmed nisar@gmail.com wrote: My application has a UI having a main window which contains many views such as NSTableView, NSOutlineView, NSOpenGLView, many NSTextFields etc... The applications works normally but after some time the UI stops responding to the mouse clicks, the application does not hang but it seems that all the views stop redrawing itself. I have tried many things but fails to prevent or reproduce the behaviour. Need some advice on how to fix or atleast find out what is causing such behaviour. I am updating all UI controls on the main thread and using Cocoa bindings heavily.. apparently there is no memory leaks, I am using Xcode 6.1 on Mavericks Personally I would try and follow the flow of events: https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/EventOverview/EventArchitecture/EventArchitecture.html#//apple_ref/doc/uid/1060i-CH3-SW11 You could try overriding NSWindow -sendEvent: This action method dispatches mouse and keyboard events sent to the window by the NSApplication object. This should help you to narrow down the location of the problem. Jonathan ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com