Skip to content

Conversation

@panxinmiao
Copy link
Contributor

When the window is minimized, the application crashes.

Traceback (most recent call last):
  File "F:\rendercanvas\rendercanvas\_coreutils.py", line 50, in log_exception
    yield
  File "F:\rendercanvas\rendercanvas\_loop.py", line 241, in wrapper
    await async_func(*args)
  File "F:\rendercanvas\rendercanvas\_scheduler.py", line 164, in __scheduler_task
    canvas._process_events()
  File "F:\rendercanvas\rendercanvas\base.py", line 390, in _process_events
    self.__maybe_emit_resize_event()
  File "F:\rendercanvas\rendercanvas\base.py", line 361, in __maybe_emit_resize_event
    self._canvas_context._rc_set_size_dict(self._size_info)
  File "F:\rendercanvas\rendercanvas\contexts\basecontext.py", line 54, in _rc_set_size_dict
    self._wgpu_context.set_physical_size(*size_info["physical_size"])
  File "F:\wgpu-py\wgpu\_classes.py", line 277, in set_physical_size
    raise ValueError("Physical size values must be positive.")
ValueError: Physical size values must be positive.

I think physical_size can be (0, 0).

@panxinmiao panxinmiao requested a review from Korijn as a code owner December 24, 2025 01:48
Copy link
Collaborator

@Korijn Korijn left a comment

Choose a reason for hiding this comment

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

I checked with git blame, this PR indeed restores the original behavior. Thank you!

@Korijn Korijn merged commit e36ad2a into pygfx:main Dec 30, 2025
19 checks passed
@almarklein
Copy link
Member

mmm, from what I can find, the original behavior was different from bitmap and screen presenting:

For bitmap, the case was basically ignored, making a texture of at least 1 pixel:

wgpu-py/wgpu/_classes.py

Lines 461 to 462 in 44a8943

width, height = canvas.get_physical_size()
width, height = max(width, 1), max(height, 1)

For screen it failed also for zero-size textures:

new_size = tuple(self._get_canvas().get_physical_size())
if new_size[0] <= 0 or new_size[1] <= 0:
# It's the responsibility of the drawing /scheduling logic to prevent this case.
raise RuntimeError("Cannot get texture for a canvas with zero pixels.")

I think the latter was done because zero-sized textures cause a crash later in the pipeline. Not sure if this behavior has changed in recent releases of wgpu-native.


Anyway ... thanks for the fix! I will probably dig a bit more into it though, because I feel I don't fully understand the consequences, and in what cases we can expect a zero-sized array.

I suspect that a zero-sized canvas can happen, but it will never be drawn to by rendercanvas, so the aforementioned pipeline error should not happen...

I just tried on MacOS, and for both glfw and Qt, a minimized window does not change its size. I can test on Windows and Linux next week when I am back in my office. Was the original issue on Windows @panxinmiao ?

@Vipitis
Copy link
Contributor

Vipitis commented Jan 3, 2026

This definitely happened to me on windows with glfw too

@panxinmiao
Copy link
Contributor Author

Was the original issue on Windows @panxinmiao ?

Yes, I encountered this issue on Windows.

@almarklein
Copy link
Member

I can easily reproduce on Windows too. So yeah, the window size can be (0, 0), but in that case there are no draws.

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.

4 participants