Fri 27 Mar 2009 08:49:56 AM UTC, comment #4:
It would be better to open a new bug report for each single problem. I know this is a lot of overhead, but it makes it easier to track, which problem was fixed and which are still open. For now I just reopen this bug report to make ti visual again.
Did you try this code in the main thread as well? The reason I am asking is that there are known problems with [NSBitmapImageRep initWithFocusedViewRect:] on the art backend (I really should fix them, not only know about them) and it could well be that you just run into these and your problem doesn't have anythign to do with the code running in a secondary thread.
You could test, whether this is the case by moving your code into the main thread or by swithcing to the cairo backend. This backend has other limitations, but this specific method works better than the art counterpart. If this is the root cause of the problem, please add some information to the already existing bug report in the backend category.
If it isn't this problem I will need some test code to regenerate the problem here. Could you please provide that?
Hmm, I just looked through the art backend code and noticed that there might be a problem in GSSetDevice:::, we don't retain the new_wi there. I may need to rethink the memory management there...
|
Thu 26 Mar 2009 11:27:52 PM UTC, comment #3:
That gets me past my call to lockFocus, but it seems something is still missing. I now crash a few lines later in a call to [NSBitmapImageRep initWithFocusedViewRect:]. Here is the relevant portion of the gdb transcript:
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb692ab90 (LWP 27413)]
0xb6f8f6a8 in -[ARTGState(ReadRect) GSReadRect:] (self=0x954fe98, _cmd=0xb6f9ab58, r=
{origin = {x = 0, y = 0}, size = {width = 54, height = 17}}) at ReadRect.m:79
79 if (x0 > wi->sx) x0 = wi->sx;
(gdb) bt
#0 0xb6f8f6a8 in -[ARTGState(ReadRect) GSReadRect:] (self=0x954fe98, _cmd=0xb6f9ab58, r=
{origin = {x = 0, y = 0}, size = {width = 54, height = 17}}) at ReadRect.m:79
#1 0xb6f29e7e in -[GSContext(NSGraphics) GSReadRect:] (self=0x86848c0, _cmd=0xb7eadc88, rect=
{origin = {x = 0, y = 0}, size = {width = 54, height = 17}}) at GSContext.m:878
#2 0xb7c6e3ee in -[NSBitmapImageRep initWithFocusedViewRect:] (self=0x9120698, _cmd=0x81def58, rect=
{origin = {x = 0, y = 0}, size = {width = 54, height = 17}}) at NSBitmapImageRep.m:354
#3 0x080e8e8b in +[TestScriptImage generateTextImageWithAttributes:] (self=0x81de760, _cmd=0x81dec30,
attributes=0x92ee388) at TestScriptImage.m:698
#4 0x080e383d in +[TestScriptImage makeTestScriptTextImageForFullAttributes:usingPlatform:] (
self=0x81de760, _cmd=0x81ce070, fullAttributes=0x92ee388, textPlatformDict=0x955aeb8)
at TestScriptImage.m:215
(gdb) p wi
$3 = (class XWindowBuffer *) 0x0
(gdb) f 3
#3 0x080e8e8b in +[TestScriptImage generateTextImageWithAttributes:] (self=0x81de760, _cmd=0x81dec30,
attributes=0x92ee388) at TestScriptImage.m:698
698 textBitmapImage = [[[NSBitmapImageRep alloc] initWithFocusedViewRect:NSMakeRect(0,0,stringSize.width,stringSize.height)] autorelease];
(gdb) l
693 [[simpleWindow contentView] lockFocus];
694 NS_DURING {
695 [bgColor set];
696 [NSBezierPath fillRect:NSMakeRect(0,0,stringSize.width,stringSize.height)];
697 [generatedString drawAtPoint:NSMakePoint(1,0)];
698 textBitmapImage = [[[NSBitmapImageRep alloc] initWithFocusedViewRect:NSMakeRect(0,0,stringSize.width,stringSize.height)] autorelease];
699 }
700 NS_HANDLER {
701 NSLog(@"Exception trying to generate text image: %@", localException);
702 [[simpleWindow contentView] unlockFocus];
The lockFocus at line 693 works fine now, but I'm still not able to draw into the new context and extract the drawn image.
|
Fri 20 Mar 2009 06:31:27 PM UTC, original submission:
I have the following two lines in my code. The lockFocus causes an exception inserting nil into an array.
NSWindow *simpleWindow = [[[NSWindow alloc]
initWithContentRect:NSMakeRect(0,0,stringSize.width,stringSize.height)
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreNonretained
defer:NO] autorelease];
[[simpleWindow contentView] lockFocus];
The following gdb transcript may be helpful. The window's frame gets set to some odd values which looks suspicious but I'm guessing may be an unrelated problem. I am executing this code in a background thread as you can see below. I wonder if the fact this is a borderless window or is nonretained has anything to do with it. This same code works fine in Cocoa.
688 NSWindow *simpleWindow = [[[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,stringSize.width,stringSize.height)
689 styleMask:NSBorderlessWindowMask
690 backing:NSBackingStoreNonretained
691 defer:NO] autorelease];
(gdb) p stringSize
$22 = {width = 54, height = 17}
(gdb) n
693 [[simpleWindow contentView] lockFocus];
(gdb) p [simpleWindow frame]
$23 = {origin = {x = -1.38111977e-41, y = 0}, size = {width = 53.9999847, height = 16.9999981}}
(gdb) s
-[NSWindow contentView] (self=0x857e660, _cmd=0x81dde30) at NSWindow.m:1103
1103 return _contentView;
(gdb)
1104 }
(gdb)
-[NSView lockFocus] (self=0x896e5d8, _cmd=0x81dde38) at NSView.m:2178
2178 [self lockFocusInRect: [self visibleRect]];
(gdb) s
-[NSView visibleRect] (self=0x896e5d8, _cmd=0xb7f392e0) at NSView.m:2505
2505 if ([self isHiddenOrHasHiddenAncestor])
(gdb) fin
Run till exit from #0 -[NSView visibleRect] (self=0x896e5d8, _cmd=0xb7f392e0) at NSView.m:2505
0xb7dd806a in -[NSView lockFocus] (self=0x896e5d8, _cmd=0x81dde38) at NSView.m:2178
2178 [self lockFocusInRect: [self visibleRect]];
Value returned is $24 =
{origin = {x = 0, y = 2.86850845e-05}, size = {width = 53.9999847, height = 16.9999981}}
(gdb) s
-[NSView lockFocusInRect:] (self=0x896e5d8, _cmd=0xb7f39648, rect=
{origin = {x = 0, y = 2.86850845e-05}, size = {width = 53.9999847, height = 16.9999981}})
at NSView.m:2173
2173 [self _lockFocusInContext: nil inRect: rect];
(gdb)
-[NSView _lockFocusInContext:inRect:] (self=0x896e5d8, _cmd=0xb7f39640, ctxt=0x0, rect=
{origin = {x = 0, y = 2.86850845e-05}, size = {width = 53.9999847, height = 16.9999981}})
at NSView.m:1917
1917 int window_gstate = 0;
(gdb)
1919 if (viewIsPrinting == nil)
(gdb)
1921 NSAssert(_window != nil, NSInternalInconsistencyException);
(gdb)
1923 if ((window_gstate = [_window gState]) == 0)
(gdb) n
1929 if (ctxt == nil)
(gdb)
1931 if (viewIsPrinting != nil)
(gdb)
1939 ctxt = [_window graphicsContext];
(gdb)
1944 [NSGraphicsContext saveGraphicsState];
(gdb) po ctxt
<ARTContext: 0x898f720>
(gdb) s
+[NSGraphicsContext saveGraphicsState] (self=0xb7ede300, _cmd=0xb7f395b0) at NSGraphicsContext.m:253
253 NSMutableDictionary *dict = [[NSThread currentThread] threadDictionary];
(gdb) n
254 NSMutableArray *stack = [dict objectForKey: NSGraphicsContextStackKey];
(gdb) po dict
{}
(gdb) info thread
- 11 Thread 0xb5fffb90 (LWP 4377) +[NSGraphicsContext saveGraphicsState] (self=0xb7ede300, _cmd=0xb7f395b0)
at NSGraphicsContext.m:254
10 Thread 0xb6a51b90 (LWP 4376) 0xb7f7c410 in __kernel_vsyscall ()
1 Thread 0xb71f08c0 (LWP 4367) 0xb7f7c410 in __kernel_vsyscall ()
(gdb) n
255 if (stack == nil)
(gdb)
257 stack = [[NSMutableArray allocWithZone: _globalGSZone] init];
(gdb)
258 [dict setObject: stack forKey: NSGraphicsContextStackKey];
(gdb)
260 ctxt = GSCurrentContext();
(gdb)
261 [ctxt saveGraphicsState];
(gdb) po ctxt
Cannot access memory at address 0x0
(gdb) n
262 [stack addObject: ctxt];
(gdb)
688 NSWindow *simpleWindow = [[[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,stringSize.width,stringSize.height)
689 styleMask:NSBorderlessWindowMask
690 backing:NSBackingStoreNonretained
691 defer:NO] autorelease];
(gdb) p stringSize
$22 = {width = 54, height = 17}
(gdb) n
693 [[simpleWindow contentView] lockFocus];
(gdb) p [simpleWindow frame]
$23 = {origin = {x = -1.38111977e-41, y = 0}, size = {width = 53.9999847, height = 16.9999981}}
(gdb) s
-[NSWindow contentView] (self=0x857e660, _cmd=0x81dde30) at NSWindow.m:1103
1103 return _contentView;
(gdb)
1104 }
(gdb)
-[NSView lockFocus] (self=0x896e5d8, _cmd=0x81dde38) at NSView.m:2178
2178 [self lockFocusInRect: [self visibleRect]];
(gdb) s
-[NSView visibleRect] (self=0x896e5d8, _cmd=0xb7f392e0) at NSView.m:2505
2505 if ([self isHiddenOrHasHiddenAncestor])
(gdb) fin
Run till exit from #0 -[NSView visibleRect] (self=0x896e5d8, _cmd=0xb7f392e0) at NSView.m:2505
0xb7dd806a in -[NSView lockFocus] (self=0x896e5d8, _cmd=0x81dde38) at NSView.m:2178
2178 [self lockFocusInRect: [self visibleRect]];
Value returned is $24 =
{origin = {x = 0, y = 2.86850845e-05}, size = {width = 53.9999847, height = 16.9999981}}
(gdb) s
-[NSView lockFocusInRect:] (self=0x896e5d8, _cmd=0xb7f39648, rect=
{origin = {x = 0, y = 2.86850845e-05}, size = {width = 53.9999847, height = 16.9999981}})
at NSView.m:2173
2173 [self _lockFocusInContext: nil inRect: rect];
(gdb)
-[NSView _lockFocusInContext:inRect:] (self=0x896e5d8, _cmd=0xb7f39640, ctxt=0x0, rect=
{origin = {x = 0, y = 2.86850845e-05}, size = {width = 53.9999847, height = 16.9999981}})
at NSView.m:1917
1917 int window_gstate = 0;
(gdb)
1919 if (viewIsPrinting == nil)
(gdb)
1921 NSAssert(_window != nil, NSInternalInconsistencyException);
(gdb)
1923 if ((window_gstate = [_window gState]) == 0)
(gdb) n
1929 if (ctxt == nil)
(gdb)
1931 if (viewIsPrinting != nil)
(gdb)
1939 ctxt = [_window graphicsContext];
(gdb)
1944 [NSGraphicsContext saveGraphicsState];
(gdb) po ctxt
<ARTContext: 0x898f720>
(gdb) s
+[NSGraphicsContext saveGraphicsState] (self=0xb7ede300, _cmd=0xb7f395b0) at NSGraphicsContext.m:253
253 NSMutableDictionary *dict = [[NSThread currentThread] threadDictionary];
(gdb) n
254 NSMutableArray *stack = [dict objectForKey: NSGraphicsContextStackKey];
(gdb) po dict
{}
(gdb) info thread
- 11 Thread 0xb5fffb90 (LWP 4377) +[NSGraphicsContext saveGraphicsState] (self=0xb7ede300, _cmd=0xb7f395b0)
at NSGraphicsContext.m:254
10 Thread 0xb6a51b90 (LWP 4376) 0xb7f7c410 in __kernel_vsyscall ()
1 Thread 0xb71f08c0 (LWP 4367) 0xb7f7c410 in __kernel_vsyscall ()
(gdb) n
255 if (stack == nil)
(gdb)
257 stack = [[NSMutableArray allocWithZone: _globalGSZone] init];
(gdb)
258 [dict setObject: stack forKey: NSGraphicsContextStackKey];
(gdb)
260 ctxt = GSCurrentContext();
(gdb)
261 [ctxt saveGraphicsState];
(gdb) po ctxt
Cannot access memory at address 0x0
(gdb) n
262 [stack addObject: ctxt];
(gdb)
|