-
Notifications
You must be signed in to change notification settings - Fork 4
WxRenderWidget cannot be used on its own (segfault) #91
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
Comments
a follow up question (not sure if it's a bug or my misunderstanding of how import pygfx.renderers
import rendercanvas.wx
import wx
app = wx.App()
canvas = rendercanvas.wx.WxRenderWidget()
renderer = pygfx.renderers.WgpuRenderer(canvas) # this line blocks and prevents further setup it gets caught in a loop here, which was triggered by rendercanvas/rendercanvas/wx.py Lines 188 to 189 in 557cb3f
|
From what I understand, a toplevel widget should inherit from |
Yes, I was going to be placing it within the context of a larger widget. But it still doesn’t work. Even if I pass in a parent frame it doesn’t work Can you show me a simple example of embedding that doesn’t segfault or freeze? |
Trying your original sample on Linux, I get not a segfault but it indeed errors at
When trying to come up with a minimal example, I indeed run into errors and segfaults rather easily. The order of operations matters. Simplest form: import rendercanvas.wx
import wx
app = wx.App()
frame = wx.Frame(None)
canvas = rendercanvas.wx.WxRenderWidget(parent=frame)
frame.SetSize(640, 480)
frame.Show()
app.MainLoop() Slightly more advanced: import rendercanvas.wx
import wx
import numpy as np
app = wx.App()
frame = wx.Frame(None)
canvas = rendercanvas.wx.WxRenderWidget(parent=frame)
frame.SetSize(640, 480)
frame.Show()
context = canvas.get_context("bitmap")
bitmap= np.full((100, 100, 4), 255, np.uint8)
bitmap[:,:,0] = 0
context.set_bitmap(bitmap)
app.MainLoop() With an animation: import rendercanvas.wx
import wx
import numpy as np
app = wx.App()
frame = wx.Frame(None)
canvas = rendercanvas.wx.WxRenderWidget(parent=frame, update_mode='continuous')
frame.SetSize(640, 480)
frame.Show()
context = canvas.get_context("bitmap")
@canvas.request_draw
def animate():
w, h = canvas.get_logical_size()
shape = int(h) // 4, int(w) // 4
bitmap = np.random.uniform(0, 255, shape).astype(np.uint8)
context.set_bitmap(bitmap)
app.MainLoop() And then there is https://github.com/pygfx/rendercanvas/blob/main/examples/wx_app.py |
ok, fair enough! sorry I missed that example. was trying something too simple I guess. do you think it would be worth guarding rendercanvas/rendercanvas/wx.py Line 359 in 557cb3f
behind if parent is not None? |
See #92 I also found that if you use |
I commented at #92. The warning is fine, but I think it slightly misses the point that this is a little bit of a bug/limitation in rendercanvas. There shouldn’t be anything conceptually wrong with creating a widget without a parent and then later putting it into another widget before the event loop starts. It’s still not using it as a top level widget and I would have expected it to be a supported pattern |
Uh oh!
There was an error while loading. Please reload this page.
running the following example causes a segfault (rendercanvas v2.1.2, wxpython 4.2.3, macos, python 3.12)
while
WxRenderCanvas()
works just fine...the fault seems to be happening in a size-related method:
and I tracked it down to this line in
_rc_set_logical_size
(which is triggered by_final_canvas_init
)rendercanvas/rendercanvas/wx.py
Line 359 in 557cb3f
The text was updated successfully, but these errors were encountered: