View Full Version : [Resolved] UI holding up OpenGL view
Apr 28, 2011, 10:21 PM
In my application when I click and hold down on a NSButton it stops the NSTimer loop that calls my drawRect. And I'm wondering why that is so, and how to prevent it.
I tried making my own subclass of NSButtonCell and overriding trackMouse:inRect:ofView:untilMouseUp: and the other subsequent tracking method associated with it. But that didn't help, though I still assume there's something in there I can do to prevent this.
I also tried running OpenGL on another thread but it still seems to get blocked when I hold down the button.
Apr 28, 2011, 11:22 PM
Override -mouseDown:, -mouseDragged: and -mouseUp:
Do not call super in any of those overrides, except perhaps to do highlighting/unhighlighting (even the, self would be fine)
In -mouseDown:, handle the click, then leave (do not wait for mouse-up, handle the tracking asynchronously through the other methods)
This should hand control over to the main runloop more often so that your UI can update as required.
Apr 28, 2011, 11:32 PM
It sounds like NSButton (or NSButtonCell) is shifting the NSRunLoop into a different mode while it tracks the mouse.
I'm assuming you're using either scheduledTimerWithTimeInterval:target:selector:userInfo:repeats: or scheduledTimerWithTimeInterval:invocation:repeats: to create your timer. These methods will only add the timer to the default run-loop mode.
Instead try using timerWithTimeInterval:target:selector:userInfo:repeats: or timerWithTimeInterval:invocation:repeats:, and then manually adding the timer to the run loop for the common mode.
Apr 28, 2011, 11:41 PM
Thanks you two, I had just worked it out when I checked the thread just now to update it. It was as you said jiminaus I was creating my timer using scheduledTimerWithTimeInterval:target:selector:userInfo:repeats: on my main thread. But I solved it by just creating another thread and creating the timer from there, but I'm going to checkout your solution cause it might be more appropriate.
Just tested it and adding it to the common mode works perfectly, thanks again.