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

Merged
merged 2 commits into from
Dec 25, 2024

Conversation

NekoAsakura
Copy link
Contributor

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
Contributor 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
Contributor 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
Contributor 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?

@NekoAsakura
Copy link
Contributor Author

@zhouxian I have made a test on Windows 10 22H2 19045.5247 and it was passed. I believe it's safe to merge, and it shouldn't cause any issues with other supporting os.

@zhouxian
Copy link
Collaborator

Thank you:)

@zhouxian zhouxian merged commit 63905b0 into Genesis-Embodied-AI:main Dec 25, 2024
@zhouxian
Copy link
Collaborator

Hi, it seems this caused issue on linux via SSH, and pyrender will not be able to be imported (works fine in local terminal, but fails when doing this via ssh)

Could you fix this? it seems a bit urgent.
For now, i'll add a simple try except to the two lines you added

@NekoAsakura
Copy link
Contributor Author

NekoAsakura commented Dec 26, 2024

Oops, apologies for any trouble may caused.
I saw #324. This is because tkinter should not be initialised on a headless server unless an X window is configured with a virtual screen.
try-except block should be enough for this, as they are not expected to use a viewer on a headless server.

[Edit]

Here's a ref of how to setup X windows: https://stackoverflow.com/questions/40195740/how-to-run-openai-gym-render-over-a-server/48237220#48237220

Also need:

sudo apt install python3-tk

@zhouxian
Copy link
Collaborator

Ok thanks!

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