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

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #18494: NSRunAlertPanel crash problems (threads?)

Submitted by:  Riccardo Mottola <rmottola>
Submitted on:  Sat 09 Dec 2006 12:20:17 PM UTC  
 
Category: Gui/AppKitSeverity: 3 - Normal
Item Group: BugStatus: Fixed
Privacy: PublicAssigned to: None
Open/Closed: Closed

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>
Project 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>
Project 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>
Project 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>
Project 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>
Project Member

 

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by FredKiefer (Posted a comment)
  • -unavailable- added by ayers (Posted a comment)
  • -unavailable- added by CaS (Posted a comment)
  • -unavailable- added by rmottola (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 3 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Mon 02 Apr 2007 12:56:58 PM UTCCaSStatusConfirmed=>Fixed
      Open/ClosedOpen=>Closed
    Sun 01 Apr 2007 09:31:39 AM UTCCaSStatusNone=>Confirmed

    Back to the top


    Powered by Savane 3.1-cleanup1