bugGNUstep - Bugs: bug #25943, Error trying to lock focus in...

Group
 
 

bug #25943: Error trying to lock focus in offscreen window

Submitter:  Doug Simons <theeggcamefirst>
Submitted:  Fri 20 Mar 2009 06:31:27 PM UTC
   
 
Category:  Gui/AppKit Severity:  3 - Normal
Item Group:  Bug Status:  Fixed
Privacy:  Public Assigned to:  FredKiefer
Open/Closed:  Closed
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Mon 15 Jun 2009 05:38:38 PM UTC, comment #7: 

Closed as there was no further input from the original poster and the first problem mentioned in the topic was definitly resolved.

Fred Kiefer <FredKiefer>
Group Member
Sat 02 May 2009 12:10:02 PM UTC, comment #6: 

Doug,
could you please comment whether this bug report is still open? If I wont here from you I will close it again.

Fred Kiefer <FredKiefer>
Group Member
Fri 27 Mar 2009 11:30:46 PM UTC, comment #5: 

I fixed that memory issue with XWindowBuffer, please give it another try and if it still fails, use the tips I provided to pin down the cause.

Fred Kiefer <FredKiefer>
Group Member
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...


Fred Kiefer <FredKiefer>
Group Member
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.


Doug Simons <theeggcamefirst>
Wed 25 Mar 2009 08:44:06 AM UTC, comment #2: 

Looks like the last comment I made did not make it to the system. I was suggesting two possible solutions there. Anyway, in the mean time I already implemented one of them. Now the saveGraphicsState and restoreGraphicsState methods are able to handle the case where there is no current graphics context. This is very similar to the way this methods are implemented in mySTEP, that's why I expect this to be a save change.

Please give it a try.

Fred Kiefer <FredKiefer>
Group Member
Sat 21 Mar 2009 02:36:26 PM UTC, comment #1: 

Your great debugging session shows quite clear where the problem is. It is the call to  [NSGraphicsContext saveGraphicsState], as this happens on a secondary thread there is no previous graphics context (GSCurrentContext() return nil). NSApplication takes care that the thread that calls [NSApplication init] has a graphics context set up, but similar things don't happen automatically for other threads.

You could use the method [NSGraphicsContext setCurrentContext:] in that secondary thread to do this yourself.
I would expect that behaviour of Cocoa to be different and will welcome any patches to make drawing in GNUstep work on secondary threads.

Fred Kiefer <FredKiefer>
Group Member
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)


Doug Simons <theeggcamefirst>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by FredKiefer (Posted a comment)
  • -email is unavailable- added by theeggcamefirst (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2009-06-15 FredKiefer StatusIn Progress Fixed
        Open/ClosedOpen Closed
    2009-03-27 FredKiefer StatusReady For Test In Progress
        Open/ClosedIn Test Open
    2009-03-25 FredKiefer StatusNone Ready For Test
        Assigned toNone FredKiefer
        Open/ClosedOpen In Test

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code