Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG FIX] ext/pyrender/viewer: resolve macOS crashes when initialising Tk() #92

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

NekoAsakura
Copy link

This PR should resolve Issue#91.
On macOS, a Tk instance should be initiated before creating the viewer.

Comment on lines -17 to -25
try:
from Tkinter import Tk
from Tkinter import tkFileDialog as filedialog
except Exception:
try:
from tkinter import Tk
from tkinter import filedialog as filedialog
except Exception:
pass
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The purpose of this code is to ensure compatibility with Tkinter, supporting both Python 2 and Python 3. Genesis requires Python 3.9 or higher, such compatibility adjustments are unnecessary.

requires-python = ">=3.9"

@@ -16,6 +16,8 @@

from tkinter import Tk
from tkinter import filedialog
root = Tk()
root.withdraw()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hide root window as we only use filedialog to save image.

@zhouxian
Copy link
Collaborator

Thank you for this!!!! Could you test and make sure it doesn't interfere with other os? if not we can merge

@NekoAsakura
Copy link
Author

I have tested viewer on macOS 15.2 and Ubuntu 22.04 w/ cu118, and it worked as expected. It should also function correctly on Windows, but I don't have a testing platform to confirm this.

To test it, run any script containing genesis.Scene(...).viewer.start(). When viewer window appears, press "s" to save an image.

The use of root.withdraw() can also be found in CPython:
https://github.com/python/cpython/blob/09d15aa9a87f69867e69f00d0e9671d70a4a49c5/Lib/tkinter/__init__.py#L329-L343

So I assume it works well across multiple platforms.

@zhouxian
Copy link
Collaborator

@zhenjia-xu could you take care of this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ext/pyrender/viewer: NSException when save image
2 participants