Re: Debugging kCGErrorIllegalArgument: CGSUnionRegionWithRect : Invalid region

2013-09-06 Thread Graham Cox

On 05/09/2013, at 1:52 PM, Jonathan Taylor  
wrote:

> That suggestion for a breakpoint is a great one. Sadly the condition you 
> quoted doesn't seem to be parsed correctly by the debugger, even with 
> casting. Even just "po (NSThread*)[NSThread currentThread]" fails on my 
> machine.

Hmm, works OK for me.

> Fortunately, though, there were only a couple of dozen hits on the breakpoint 
> per iteration of the code, and sure enough it immediately pinpointed a case 
> where I was erroneously calling willChangeValueForKey from a secondary 
> thread, which was causing a GUI update as a side-effect.


Glad you found the problem ;-)

--Graham


___

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: Debugging kCGErrorIllegalArgument: CGSUnionRegionWithRect : Invalid region

2013-09-05 Thread Jonathan Taylor
> Do you have any secondary threads? I assume you do.

Indeed!

> Any code that touches a view, no matter how indirectly, could be the culprit. 
> Bear in mind that sending any message to any view (controls, etc) might 
> invoke -setNeedsDisplay: which in turn could be the trigger for the problem. 
> Try setting a breakpoint on -setNeedsDisplay: though of course it will be hit 
> a lot, so you might need a clever condition to avoid being overwhelmed. Even 
> one that excludes the main thread might help, e.g. [NSThread currentThread] 
> != [NSThread mainThread]

That suggestion for a breakpoint is a great one. Sadly the condition you quoted 
doesn't seem to be parsed correctly by the debugger, even with casting. Even 
just "po (NSThread*)[NSThread currentThread]" fails on my machine.

Fortunately, though, there were only a couple of dozen hits on the breakpoint 
per iteration of the code, and sure enough it immediately pinpointed a case 
where I was erroneously calling willChangeValueForKey from a secondary thread, 
which was causing a GUI update as a side-effect.

Cheers
Jonny.
___

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: Debugging kCGErrorIllegalArgument: CGSUnionRegionWithRect : Invalid region

2013-09-05 Thread Graham Cox

On 05/09/2013, at 12:37 PM, Jonathan Taylor  
wrote:

> Yes, I understand that. I am not aware of doing any drawing from secondary 
> threads, although evidently it appears that somewhere in the program this is 
> happening. My question is whether I can do anything to help track down the 
> problem, because right now I am limited to code reading and/or the very slow 
> process of disabling sections of code (slow because it's an intermittent 
> problem and each time I would need to run for long enough that I can be 
> reasonably sure I would have hit the error if I was going to...).


Do you have any secondary threads? I assume you do.

Any code that touches a view, no matter how indirectly, could be the culprit. 
Bear in mind that sending any message to any view (controls, etc) might invoke 
-setNeedsDisplay: which in turn could be the trigger for the problem. Try 
setting a breakpoint on -setNeedsDisplay: though of course it will be hit a 
lot, so you might need a clever condition to avoid being overwhelmed. Even one 
that excludes the main thread might help, e.g. [NSThread currentThread] != 
[NSThread mainThread]

--Graham


___

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: Debugging kCGErrorIllegalArgument: CGSUnionRegionWithRect : Invalid region

2013-09-05 Thread Jonathan Taylor
> You can't do any UI-related updates from a secondary thread, you must ask the 
> main thread to do it.
> 
> It might not be progress bars but anything at all that's being drawn from a 
> secondary thread. The error itself could indicate that an internal data 
> structure was used or updated by another thread while in an inconsistent 
> state.

Yes, I understand that. I am not aware of doing any drawing from secondary 
threads, although evidently it appears that somewhere in the program this is 
happening. My question is whether I can do anything to help track down the 
problem, because right now I am limited to code reading and/or the very slow 
process of disabling sections of code (slow because it's an intermittent 
problem and each time I would need to run for long enough that I can be 
reasonably sure I would have hit the error if I was going to...).



___

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: Debugging kCGErrorIllegalArgument: CGSUnionRegionWithRect : Invalid region

2013-09-05 Thread Graham Cox

On 05/09/2013, at 12:21 PM, Jonathan Taylor  
wrote:

> Searching for those terms finds suggestions that this may be associated with 
> updating progress bars from a secondary thread. I still see the error even 
> after removing the only progress bar from my program; I don't know whether 
> the cause is something genuinely associated with progress bars, or whether 
> it's just that it's easy to slip up and update them from a secondary thread, 
> triggering this error.


You can't do any UI-related updates from a secondary thread, you must ask the 
main thread to do it.

It might not be progress bars but anything at all that's being drawn from a 
secondary thread. The error itself could indicate that an internal data 
structure was used or updated by another thread while in an inconsistent state.

--Graham


___

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

Debugging kCGErrorIllegalArgument: CGSUnionRegionWithRect : Invalid region

2013-09-05 Thread Jonathan Taylor
Can anybody help me diagnose an error that I see intermittently? The errors are 
as follows:

Thu Sep  5 10:11:11 Jonathan-Taylors-Mac-Pro.local Spim GUI[34152] : 
kCGErrorIllegalArgument: CGSUnionRegionWithRect : Invalid region
Thu Sep  5 10:11:11 Jonathan-Taylors-Mac-Pro.local Spim GUI[34152] : 
kCGErrorFailure: Set a breakpoint @ CGErrorBreakpoint() to catch errors as they 
are logged.
(gdb) continue
Thu Sep  5 10:11:17 Jonathan-Taylors-Mac-Pro.local Spim GUI[34152] : 
kCGErrorIllegalArgument: CGSGetRegionBounds : Invalid region

Searching for those terms finds suggestions that this may be associated with 
updating progress bars from a secondary thread. I still see the error even 
after removing the only progress bar from my program; I don't know whether the 
cause is something genuinely associated with progress bars, or whether it's 
just that it's easy to slip up and update them from a secondary thread, 
triggering this error.

The error is very intermittent which makes narrowing it down hard, and setting 
the breakpoint as advised hasn't helped me since there isn't anything of mine 
in the call stack when the condition is encountered:

#0  0x97a7610a in CGErrorBreakpoint
#1  0x97b0b9e0 in CGSGlobalErrorv
#2  0x978e96d5 in CGSUnionRegionWithRect
#3  0x984ea84c in -[NSRegion addRegion:]
#4  0x984ea69d in -[NSWindow _setNeedsDisplayInRegion:]
#5  0x9843ae86 in -[NSWindow _absorbDeferredNeedsDisplayRegion]
#6  0x98439a54 in -[NSView 
_sendViewWillDrawInRect:clipRootView:suppressRecursion:]
#7  0x9839c80e in -[NSView displayIfNeeded]
#8  0x98365b64 in -[NSWindow displayIfNeeded]
#9  0x9839707e in _handleWindowNeedsDisplay
#10 0x94f04dd2 in __CFRunLoopDoObservers
#11 0x94ec0ced in __CFRunLoopRun
#12 0x94ec03c4 in CFRunLoopRunSpecific
#13 0x94ec01f1 in CFRunLoopRunInMode
#14 0x92e8ce04 in RunCurrentEventLoopInMode
#15 0x92e8cbb9 in ReceiveNextEventCommon
#16 0x92e8ca3e in BlockUntilNextEventMatchingListInMode
#17 0x9836d595 in _DPSNextEvent
#18 0x9836cdd6 in -[NSApplication 
nextEventMatchingMask:untilDate:inMode:dequeue:]
#19 0x9832f1f3 in -[NSApplication run]
#20 0x98327289 in NSApplicationMain
#21 0x2b69 in start at vector.tcc:244


Can anyone advise on anything I can do to help diagnose this? Even something 
that made it happen much more frequently would be some help, as I might then 
have more of a chance of narrowing down the cause by disabling chunks of code.

Cheers
Jonny


___

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