Skip to content

Commit 48b37dd

Browse files
committed
Fix race condition between first resize and save_screenshot
Don't wait when a debounced function is called the first time
1 parent c399f75 commit 48b37dd

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

webgpu/canvas.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,18 @@ def f():
3131
debounced.timer = None
3232
debounced.t_last = t
3333

34+
if debounced.t_last is None:
35+
# first call -> just call the function immediately
36+
debounced.t_last = time.time()
37+
f()
38+
return
39+
3440
t_wait = max(1 / target_fps - (time.time() - debounced.t_last), 0)
3541
debounced.timer = threading.Timer(t_wait, f)
3642
debounced.timer.start()
3743

3844
debounced.timer = None
39-
debounced.t_last = time.time()
45+
debounced.t_last = None
4046
return debounced
4147

4248
if callable(arg):
@@ -61,6 +67,7 @@ class Canvas:
6167
depth_texture: Texture
6268
multisample_texture: Texture
6369
multisample: MultisampleState
70+
target_texture: Texture
6471

6572
width: int = 0
6673
height: int = 0

0 commit comments

Comments
 (0)