Warning about NS_DURING (was "Bug in Cocoa drawing?")
Warning about NS_DURING (was "Bug in Cocoa drawing?")
- Subject: Warning about NS_DURING (was "Bug in Cocoa drawing?")
- From: Drew McCormack <email@hidden>
- Date: Sun, 4 Apr 2004 16:37:39 +0200
Just to follow up on this thread, and hopefully save others a lot of
trouble, it seems my problem had nothing to do with drawing. It had to
do with how I was using NS_DURING blocks. I had added some return
statements in the middle of the exception handling blocks, which caused
the problems. With hindsight, I should have known that the old
exception handing macros would break if you do this, but it just hadn't
occurred to me.
So, be warned: Don't put return statements in NS_DURING blocks.
Drew McCormack
On Apr 2, 2004, at 8:18 AM, Drew McCormack wrote:
>
To follow up my earlier post, it turns out the problem has nothing to
>
do with changing a subview in the drawRect: method. Even when I don't
>
do this, the exception occurs. It seems like it might be a bug in the
>
Cocoa drawing code, to do with exception handling.
>
>
If I add an NS_DURING block to code executed during drawing, the
>
problem occurs. Even when no exception arises, the crash occurs: the
>
presence of the NS_DURING block seems to cause it.
>
>
I am doing the following:
>
- In the drawRect: method of an NSView, I am locking focus on an
>
NSImage, and drawing to that for caching reasons.
>
- The problem occurs when I call the unlock method for the NSImage.
>
- If I leave out the NS_DURING block, there is no problem.
>
>
>
Here is a cut down version of the code in the NRTPlotView class:
>
>
- (void)drawRect:(NSRect)rect
>
{
>
[_cachedImage release];
>
_cachedImage = [[NSImage alloc] initWithSize:[self
>
frame].size];
>
[_cachedImage lockFocus];
>
>
[_component drawInPlotView:self]; // This code includes the
>
NS_DURING block
>
>
[_cachedImage unlockFocus];
>
[_cachedImage compositeToPoint:rect.origin fromRect:rect
>
operation:NSCompositeSourceOver];
>
}
>
>
>
Here is part of the backtrace where the problem arises:
>
>
Program received signal: "EXC_BAD_ACCESS".
>
(gdb) bt
>
#0 0x909f22c4 in _NSAddExceptionHandlerForLock ()
>
#1 0x92dc2dd8 in -[NSViewHierarchyLock
>
lockForReadingWithExceptionHandler:] ()
>
#2 0x92dd30f0 in -[NSWindow flushWindow] ()
>
#3 0x92e13e38 in -[NSImage unlockFocus] ()
>
#4 0x3f00866c in -[NRTPlotView drawRect:] (self=0x11e7bc0,
>
_cmd=0x90874160, rect={origin = {x = 0, y = 0}, size = {width = 464,
>
height = 310}}) at NRTPlotView.m:131
>
>
>
Clearly this has to do with exception handling. But why is the
>
flushWindow being called from the unlockFocus method of the NSImage? I
>
suspect this is the problem, because the NRTPlotView object has not yet
>
completed it's drawing when this occurs.
>
>
Is this a bug, or am I doing something illegal with when I lock focus
>
on the NSImage?
>
>
Drew McCormack
>
>
Trade Strategist
>
Stock market strategy design software
>
>
http://www.trade-strategist.com
>
_______________________________________________
>
cocoa-dev mailing list | email@hidden
>
Help/Unsubscribe/Archives:
>
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>
Do not post admin requests to the list. They will be ignored.
>
>
Trade Strategist
Stock market strategy design software
http://www.trade-strategist.com
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.