bugGNUstep - Bugs: bug #18494, NSRunAlertPanel crash problems...

Group
 
 

bug #18494: NSRunAlertPanel crash problems (threads?)

Submitter:  Riccardo Mottola <rmottola>
Submitted:  Sat 09 Dec 2006 12:20:17 PM UTC
   
 
Category:  Gui/AppKit Severity:  3 - Normal
Item Group:  Bug Status:  Fixed
Privacy:  Public Assigned to:  None
Open/Closed:  Closed
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 02 Apr 2007 12:56:58 PM UTC, comment #4: 

I changed the code to perform the operation in the main appkit thread (not as simple as I had hoped) and added an NSWarnFLog().

I don't think this will make debugging much harder ... the thread where the problem ocurred will block, waiting for the main thre3ad to finish displaying the alert panel, so it should be fairly easy to locate and examine it.

Of course, Riccardo's code may not be reliably portable to MacOS-X, but I think he told me it does work on MacOS-X, so perhaps they are already doing alerts safely?

Richard Frith-Macdonald <CaS>
Group Member
Sun 01 Apr 2007 11:49:54 AM UTC, comment #3: 

Thank you for analysing this bug. Now even I understand wh this is going wrong :-)

I think for the standard use of an alert this is a great solution. If you want top put up an alert it should be started by the main thread. We might even want to put this switch to the main thread into the NSApplication runModalForWindow: method.

But what about alerts being used as error notifications by the gui code itself? I normally want to be able to fire up a debugger and look at what triggered the error condition. When we change this code  to run in a seperate thread that wont be that easy. And what should happen to the thread that run into the problem? But then again debugging multi threaded applications has never been easy.

Fred Kiefer <FredKiefer>
Group Member
Sun 01 Apr 2007 11:46:29 AM UTC, comment #2: 

FWIW, IMO it would be great if we NSLogged a warning for developers, since anyone relying on the behavior may have the same issue with Cocoa, yet then used -performSelectorOnMainThread:withObject:waitUntilDone:modes: to call the function in the main thread to minimize user impact.

David Ayers <ayers>
Group Member
Sun 01 Apr 2007 09:31:39 AM UTC, comment #1: 

I reproduced this problem ...

#0  0x00002b216024d605 in DPSgsave (ctxt=0x0)
    at ../Headers/AppKit/DPSOperators.h:715
#1  0x00002b216024d1f3 in -[NSWindow _initBackendWindow] (self=0x9ef690,
    _cmd=0x2b2160533a30) at NSWindow.m:780
#2  0x00002b216024ffa3 in -[NSWindow orderWindow:relativeTo:] (self=0x9ef690,
    _cmd=0x2b2160533cf0, place=NSWindowAbove, otherWin=-1) at NSWindow.m:1576
#3  0x00002b216024fd2a in -[NSWindow orderFrontRegardless] (self=0x9ef690,
    _cmd=0x2b216045c240) at NSWindow.m:1508
#4  0x00002b21600cd037 in -[NSApplication beginModalSessionForWindow:] (
    self=0x69fa60, _cmd=0x2b216045c970, theWindow=0x9ef690)
    at NSApplication.m:1461
#5  0x00002b21600cd40b in -[NSApplication runModalForWindow:] (self=0x69fa60,
    _cmd=0x2b2160455490, theWindow=0x9ef690) at NSApplication.m:1535
#6  0x00002b21600c210c in -[GSAlertPanel runModal] (self=0x9ef690,
    _cmd=0x2b21604555a0) at NSAlert.m:725
#7  0x00002b21600c330d in NSRunAlertPanel (title=0x50fbe0, msg=0x964c90,
    defaultButton=0x50fb60, alternateButton=0x0, otherButton=0x0)
    at NSAlert.m:983
#8  0x0000000000405898 in -[AppController showAlertDialog:] (self=0x88bde0,
    _cmd=0x5136c0, message=0x964c90) at AppController.m:621
#9  0x00000000004074af in -[ftpclient storeFile:from:beingAt:] (self=0x9f9410,
    _cmd=0x510fc0, file=0x9dcd80, localClient=0x9ca500, depth=0)
    at ftpclient.m:491
#10 0x00000000004033bf in -[AppController performStoreFile:] (self=0x88bde0,
    _cmd=0x510f20, parameters=0x0) at AppController.m:308
#11 0x00002b216078a654 in -[NSObject performSelector:withObject:] (
    self=0x88bde0, _cmd=0x2b2160b19000, aSelector=0x510f20, anObject=0x0)
    at NSObject.m:1947
#12 0x00002b21607ed08e in -[NSThread _sendThreadMethod] (self=0x8fe760,
    _cmd=0x2b2160b18fc0) at NSThread.m:780
#13 0x00002b2160c878d7 in ?? () from /usr/lib/libobjc.so.1
#14 0x00002b2160b65f1a in start_thread () from /lib/libpthread.so.0
#15 0x00002b21610ea602 in clone () from /lib/libc.so.6
#16 0x0000000000000000 in ?? ()


The issue is plainly that the call to NSRunAlertPanel() is not from the main thread and is running up against the fact that gui is not thread-safe so and there is no graphics context available in other threads.

The problem is, I don't know what policy is on how to solve this ... should we aim to make NSRunAlertpanel() and similar functions work from any thread?
I don't think we can hope to make gui thread-safe (even if that term was well defined, which it isn't) in any reasonable timeframe, but we could relatively easily solve the immediate issue by making these functions use the -performSelectorOnMainThread:withObject:waitUntilDone:modes: method to ensure that the actual management of the alert panel is done in the main thread.

Thoughts/comments from core developers solicited ... if nobody tells me about a better solution, I'll probably just modify the alert functions to work in the main thread when I have time.



Richard Frith-Macdonald <CaS>
Group Member
Sat 09 Dec 2006 12:20:17 PM UTC, original submission:  

when running FTP from gap (as of CVS sources in today's date) the application crashes when a NSRunAlertPanel should be shown. The easiest way to reproduce it is to log in anonymously into an FTP site and upload a file in a place you don't have permissions to uypload into. Other errors could work too, if they are trapped.
The same code works fine on Macintosh.
The complication is that the download or upload aciton is done in a different thread to maintain the gui responsive so that the progress panel can be updated.
Previously, FTP would run the alert panel direclty in the transfer class, now it sends a message to the controller, but it still crashes.

when the alert panel should ocme up, I get
2006-12-09 11:56:30.107 FTP[11006] The font specified for NSFont, Helvetica, can't be found.

an error log which I do not get wwhen running alert panels from non-threaded applications. Maybe it is a hint to the problem.

Riccardo Mottola <rmottola>
Group Member

 

(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 ayers (Posted a comment)
  • -email is unavailable- added by CaS (Posted a comment)
  • -email is unavailable- added by rmottola (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 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2007-04-02 CaS StatusConfirmed Fixed
        Open/ClosedOpen Closed
    2007-04-01 CaS StatusNone Confirmed

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code