Mac crash in direct tools?

I’ve extremely new (day one) to Panda3d, so I hope I’m doing something wrong here.

I’m using Panda3d 1.7.2 and Mac OS X 10.6.7 (MacBook Pro). I’ve run some samples and gone through the hello world tutorial and everything has worked fine. However, when I run the following trivial program, it crashes:

from pandac.PandaModules import loadPrcFileData
loadPrcFileData("", "want-directtools #t")
loadPrcFileData("", "want-tk #t")

import direct.directbase.DirectStart
run()

Am I doing something wrong or is this a known issue? Stack trace:

2012-01-21 09:07:58.504 ppython[11152:903] -[NSApplication _setup:]: unrecognized selector sent to instance 0x5e89890
2012-01-21 09:07:58.505 ppython[11152:903] An uncaught exception was raised
2012-01-21 09:07:58.505 ppython[11152:903] -[NSApplication _setup:]: unrecognized selector sent to instance 0x5e89890
2012-01-21 09:07:58.506 ppython[11152:903] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSApplication _setup:]: unrecognized selector sent to instance 0x5e89890'
*** Call stack at first throw:
(
        0   CoreFoundation                      0x945296ba __raiseError + 410
        1   libobjc.A.dylib                     0x98877509 objc_exception_throw + 56
        2   CoreFoundation                      0x9457690b -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
        3   CoreFoundation                      0x944cfc36 ___forwarding___ + 950
        4   CoreFoundation                      0x944cf802 _CF_forwarding_prep_0 + 50
        5   Tk                                  0x1a6afea8 TkpInit + 601
        6   Tk                                  0x1a61b60a Tk_PkgInitStubsCheck + 2489
        7   _tkinter.so                         0x1a4f9fe8 Tcl_AppInit + 130
        8   _tkinter.so                         0x1a4f9f09 var_perform + 2295
        9   Python                              0x0007ad1f PyEval_EvalFrameEx + 16275
        10  Python                              0x0007caaa PyEval_EvalCodeEx + 1734
        11  Python                              0x00027472 PyClassMethod_New + 2213
        12  Python                              0x0000c268 PyObject_Call + 50
        13  Python                              0x00015d77 PyClass_New + 1710
        14  Python                              0x0000c268 PyObject_Call + 50
        15  Python                              0x000760e0 PyEval_CallObjectWithKeywords + 211
        16  Python                              0x0001562f PyInstance_New + 330
        17  Python                              0x0000c268 PyObject_Call + 50
        18  Python                              0x0007c319 PyEval_EvalFrameEx + 21901
        19  Python                              0x0007caaa PyEval_EvalCodeEx + 1734
        20  Python                              0x0007af76 PyEval_EvalFrameEx + 16874
        21  Python                              0x0007caaa PyEval_EvalCodeEx + 1734
        22  Python                              0x0007cb4f PyEval_EvalCode + 87
        23  Python                              0x0008bbd4 PyImport_ExecCodeModuleEx + 240
        24  Python                              0x0008c771 PyImport_AppendInittab + 1145
        25  Python                              0x0008e3a4 PyImport_ReloadModule + 1369
        26  Python                              0x0008e6d5 PyImport_ReloadModule + 2186
        27  Python                              0x0008ed36 PyImport_ReloadModule + 3819
        28  Python                              0x0008edde PyImport_ImportModuleLevel + 50
        29  Python                              0x00074f7f _PyBuiltin_Init + 13603
        30  Python                              0x0000c268 PyObject_Call + 50
        31  Python                              0x000760e0 PyEval_CallObjectWithKeywords + 211
        32  Python                              0x0007a0f9 PyEval_EvalFrameEx + 13165
        33  Python                              0x0007caaa PyEval_EvalCodeEx + 1734
        34  Python                              0x0007af76 PyEval_EvalFrameEx + 16874
        35  Python                              0x0007caaa PyEval_EvalCodeEx + 1734
        36  Python                              0x0007af76 PyEval_EvalFrameEx + 16874
        37  Python                              0x0007aeae PyEval_EvalFrameEx + 16674
        38  Python                              0x0007caaa PyEval_EvalCodeEx + 1734
        39  Python                              0x00027472 PyClassMethod_New + 2213
        40  Python                              0x0000c268 PyObject_Call + 50
        41  Python                              0x00015d77 PyClass_New + 1710
        42  Python                              0x0000c268 PyObject_Call + 50
        43  Python                              0x000760e0 PyEval_CallObjectWithKeywords + 211
        44  Python                              0x0001562f PyInstance_New + 330
        45  Python                              0x0000c268 PyObject_Call + 50
        46  Python                              0x0007c319 PyEval_EvalFrameEx + 21901
        47  Python                              0x0007caaa PyEval_EvalCodeEx + 1734
        48  Python                              0x0007cb4f PyEval_EvalCode + 87
        49  Python                              0x0008bbd4 PyImport_ExecCodeModuleEx + 240
        50  Python                              0x0008c771 PyImport_AppendInittab + 1145
        51  Python                              0x0008e3a4 PyImport_ReloadModule + 1369
        52  Python                              0x0008e81a PyImport_ReloadModule + 2511
        53  Python                              0x0008ec2b PyImport_ReloadModule + 3552
        54  Python                              0x0008edde PyImport_ImportModuleLevel + 50
        55  Python                              0x00074f7f _PyBuiltin_Init + 13603
        56  Python                              0x0000c268 PyObject_Call + 50
        57  Python                              0x000760e0 PyEval_CallObjectWithKeywords + 211
        58  Python                              0x0007a0f9 PyEval_EvalFrameEx + 13165
        59  Python                              0x0007caaa PyEval_EvalCodeEx + 1734
        60  Python                              0x0007cb4f PyEval_EvalCode + 87
        61  Python                              0x00094a03 Py_CompileString + 111
        62  Python                              0x00094aaf PyRun_FileExFlags + 139
        63  Python                              0x00095f34 PyRun_SimpleFileExFlags + 784
        64  Python                              0x000a1f2c Py_Main + 3226
        65  ppython                             0x00001eb5 0x0 + 7861
        66  ???                                 0x00000002 0x0 + 2
)
Trace/BPT trap

Hi, welcome to the forums!

Hmm, odd. I haven’t seen this issue before. It seems to be something deep within the Tcl framework. There’s not enough information in there for me to be able to tell exactly what’s going wrong, though. Maybe you could use the Python debugger to find out which line in Panda’s Python modules is giving trouble? Does importing Tkinter normally work?

ImportingTkinter works fine. I tried pdb and I think I found out where it’s getting tripped up (though I wasn’t able to list source or set breakpoints, but this could just be my ignorance with pdb). Here’s the problem function:

    def startTk(self, fWantTk = 1):
        self.wantTk = fWantTk
        if self.wantTk:
            initAppForGui()
            from direct.showbase import TkGlobal
            taskMgr.remove('tkLoop')
            TkGlobal.spawnTkLoop()

FWIW, If I call

from direct.showbase import TkGlobal

without having previously called initAppForGui(), a tk window shows up just fine.

I grepped the source and I couldn’t find the definition of initAppForGui.

Interesting, thanks. I’ve been able to reproduce the crash on the latest CVS version on my mac, and I’m looking into it.

For the record, init_app_for_gui is defined in direct/src/showbase/showBase.cxx. It is automatically exposed as initAppForGui by the (automatically generated) Python wrappers.

All right, it seems that all that needed to fix the crash was move initAppForGui() after the TkGlobal import call in ShowBase.py. I’ve just checked in that fix, thanks for reporting the bug!

You could either manually apply this fix into your local copy of ShowBase.py, or grab the latest OSX snapshot SDK build, which incorporates the fix.

I applied the fix, and the tk window now shows up, but it’s completely non-responsive. The main window has all the nifty features enabled (e.g. toggling wireframe), but the scene graph window does nothing when I click on the controls (it does not even animate button presses).

A little more info. Empirically, it appears that tk is dropping events.

If I click to expand a node in the scene graph tree nothing happens, regardless of how long I wait. If I click very rapidly, eventually one of my clicks gets processed and the node expands. Keyboard shortcuts in the main window work just fine.

I played around and removed tkinter.DONT_WAIT from the dooneevent call and the tk window started behaving normally (at the cost of panda3d rendering).

Right, I found that out yesterday too. I don’t know how to properly solve it yet, though - omitting DONT_WAIT will freeze Panda’s rendering. Maybe the best solution would be to create an additional thread for this, but the problem with that is that we can’t make Tk function calls from the main thread anymore.

Bah. Because Tk isn’t thread-safe, the only proper way I see to solve this would be to let tkinter take over the main loop, and create a timer to call base.taskMgr.step() every so often.

Perhaps drwr has some other ideas.

Interestingly, I just implemented just such a solution for WxPython, because I discovered it too was misbehaving on OSX unless it owned the main loop. So now, base.startWx() hands the main loop over to wx, unless you configure wx-main-loop 0.

If a similar solution also fixes Tk, then I don’t see a reason not to do it.

David

Thanks! I’ve replicated this mechanism for Tkinter, too. I’ve added a tk-main-loop config variable, and also tk-frame-rate and wx-frame-rate variables to control how often (default 60 FPS).

If you want to update your build with these changes, just grab these files:
panda3d.cvs.sourceforge.net/view … howBase.py
panda3d.cvs.sourceforge.net/view … kGlobal.py

Let me know how it goes. The direct tools work smoothly now - the only thing is that the Panda scene lags a bit when the GUI is busy, but that’s understandable.

Many thanks for letting us know about the issue!