I’m writing a game editor that has a tkinter GUI, and certain tabs have a 3D view powered by panda. I have this working fine on Windows and Linux, but I just tested on Mac for the first time, and panda is segfaulting when I call open_window. I understand that tkinter’s winfo_id isn’t meaningful on Mac, so I’m guessing that’s the problem. I’ve seen some examples online of using the pyobjc library to get a handle to the window itself, but I’m trying to embed panda in a specific widget, and I’m not sure how to go about getting a usable handle for that. What’s the ideal way to do this? For reference, here’s my code that’s working on other platforms. self is a ttk.Frame and self.base is the ShowBase object.
I just tried your example and it works on Linux (if I insert a call to base.tkRoot.update() before creating the WindowProperties, which is necessary to ensure the X window is ready) but it segfaults on Mac. This is on Python 3.12 with panda3d 1.10.14.
I can. My application doesn’t open any panda windows when it first starts, the user has to create or open a project first. The Tk window opens and works fine prior to that. Only once a project is opened and I start creating panda windows do I get a segfault on the first call to base.open_window.
if self._window is None:
self.update()
width = self.winfo_width()
height = self.winfo_height()
props = WindowProperties()
props.setParentWindow(NativeWindowHandle.makeInt(self.winfo_id()))
props.setOrigin(0, 0)
props.setSize(width, height)
if self.current_cursor is not None:
props.setCursorFilename(self.current_cursor.filename)
# FIXME: this segfaults on Mac
self._window = self.base.open_window(props)
I can’t remember exactly now, but I saw information somewhere that the problem may be with multithreading. Did you accidentally include multithreaded rendering on Mac in the configuration file?
I haven’t provided any configuration file, so I should be using the default for everything. I see the docs say to use an empty string for single-threaded, so as a test, I added this to your example right before app = AppTk():
You misunderstood me, I warned against enabling multithreading. I just assumed that you installed it on a Mac. I think you need to create a bug report on github.
Well I thought that setting threading-model to an empty string would ensure that multithreading was disabled, which is what you were suggesting, right? The docs for threading-model say: “This is the default threading model to use for new windows. Use empty string for single-threaded”
Regardless, I will go ahead with opening a bug report (I tried the loadPrcFileData form and that didn’t work either). Even if my window handle is invalid, a segfault is probably not the desired behavior. Thanks for your help!