Skip to content

Commit 2c6ce9a

Browse files
authored
Use len(draw_data.cmd_lists) in imgui backend (#830)
* Draw a frame in test_examples_run <details><summary>Claude's draft</summary> test_examples_run() ran an example's __main__ block and stopped there. Under the offscreen canvas that only constructs the canvas and registers a draw function, so nothing is drawn and the draw function -- the bulk of most examples -- was never executed. Draw one frame for every example that exposes a canvas. Drawing is not enough on its own: rendercanvas calls the draw function inside its log_exception() context, so an exception there is logged to the "rendercanvas" logger and swallowed, and a frame still comes out. Assert that nothing was logged there. This makes the imgui examples fail against imgui_bundle 1.92.900, which is the bug reported in #829 and is fixed in the next commit. Resume this Claude session: ``` cd /home/mark/git/wgpu-py claude --resume 590dd7bc-312c-419e-ad3d-2c69d00943cd ``` </details> * Use len(draw_data.cmd_lists) in imgui backend <details><summary>Claude's draft</summary> `ImDrawData.cmd_lists_count` was a legacy alias, documented in the imgui_bundle stubs as `== CmdLists.Size`, and imgui_bundle removed it in 1.92.900. Every `ImguiWgpuBackend.render()` call raises AttributeError against that release. Fixes #829. `len(draw_data.cmd_lists)` is exactly what the removed attribute equalled, and works across the whole supported `imgui-bundle>=1.92.0,<2` range: verified against 1.92.0, 1.92.3, 1.92.4, 1.92.5, 1.92.600, 1.92.601, 1.92.700, 1.92.801 and 1.92.900. No shim or version check is needed, and the pin does not need narrowing. The test from the previous commit fails without this change and passes with it. Resume this Claude session: ``` cd /home/mark/git/wgpu-py claude --resume 590dd7bc-312c-419e-ad3d-2c69d00943cd ``` </details>
1 parent 9d59b27 commit 2c6ce9a

3 files changed

Lines changed: 23 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ Possible sections in each release:
3333
Downstream code should capture that error and skip the frame, optionally invoking some sort of sleep to save energy.
3434
See https://github.com/pygfx/wgpu-py/pull/820 for context.
3535

36+
### Fixed:
37+
* The imgui backend no longer uses ``ImDrawData.cmd_lists_count``, which was removed in imgui-bundle 1.92.900.
38+
See https://github.com/pygfx/wgpu-py/issues/829.
39+
3640

3741
## [v0.31.1] - 23-06-2026
3842

examples/tests/test_examples.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import os
66
import importlib
7+
import logging
78
import runpy
89
import sys
910
from unittest.mock import patch
@@ -177,11 +178,24 @@ def update_diffs(module, is_similar, img, stored_img, *, atol):
177178

178179

179180
@pytest.mark.parametrize("module", examples_to_run)
180-
def test_examples_run(module, force_offscreen):
181+
def test_examples_run(module, force_offscreen, caplog):
181182
"""Run every example marked to see if they can run without error."""
182-
# use runpy so the module is not actually imported (and can be gc'd)
183-
# but also to be able to run the code in the __main__ block
184-
runpy.run_module(f"examples.{module}", run_name="__main__")
183+
with caplog.at_level(logging.ERROR, logger="rendercanvas"):
184+
# use runpy so the module is not actually imported (and can be gc'd)
185+
# but also to be able to run the code in the __main__ block
186+
module_globals = runpy.run_module(f"examples.{module}", run_name="__main__")
187+
188+
# The main block only sets up the canvas and hands it a draw function;
189+
# the offscreen canvas does not draw until asked. So ask, otherwise the
190+
# draw function (the bulk of most examples) is never executed.
191+
canvas = module_globals.get("canvas")
192+
if canvas is not None:
193+
canvas.draw()
194+
195+
# rendercanvas calls the draw function inside a log_exception() context, so
196+
# errors in it do not propagate; they only show up in the log.
197+
errors = [r for r in caplog.records if r.name == "rendercanvas"]
198+
assert not errors, caplog.text
185199

186200

187201
if __name__ == "__main__":

wgpu/utils/imgui/imgui_backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ def render(
445445
fb_width = int(display_width * draw_data.framebuffer_scale.x)
446446
fb_height = int(display_height * draw_data.framebuffer_scale.y)
447447

448-
if fb_width <= 0 or fb_height <= 0 or draw_data.cmd_lists_count == 0:
448+
if fb_width <= 0 or fb_height <= 0 or len(draw_data.cmd_lists) == 0:
449449
return
450450

451451
if draw_data.textures is not None:

0 commit comments

Comments
 (0)