• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Bug in Cocoa drawing? (was 'Changing subviews during drawing')
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bug in Cocoa drawing? (was 'Changing subviews during drawing')


  • Subject: Bug in Cocoa drawing? (was 'Changing subviews during drawing')
  • From: Drew McCormack <email@hidden>
  • Date: Fri, 2 Apr 2004 08:18:43 +0200

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.


  • Follow-Ups:
    • Warning about NS_DURING (was "Bug in Cocoa drawing?")
      • From: Drew McCormack <email@hidden>
    • Re: Bug in Cocoa drawing? (was 'Changing subviews during drawing')
      • From: Nick Zitzmann <email@hidden>
    • Re: Bug in Cocoa drawing? (was 'Changing subviews during drawing')
      • From: j o a r <email@hidden>
  • Prev by Date: An NSShadow question
  • Next by Date: Re: Bug in Cocoa drawing? (was 'Changing subviews during drawing')
  • Previous by thread: Re: An NSShadow question
  • Next by thread: Re: Bug in Cocoa drawing? (was 'Changing subviews during drawing')
  • Index(es):
    • Date
    • Thread