Open Azorlogh opened 3 months ago
I think I've noticed it sometimes as well. I haven't got a chance to look into that myself yet, but if anyone wants to submit a PR with a fix, I'm more than happy to merge it.
Oh, btw, could you try reproducing it with the 0.29 version? There were some changes merged that fix redraws, but I'm not sure if they cover this issue.
Just tested with 0.29, it still happens
I found a clue:
egui
ignores clicks that have been pressed for more than 0.8s. If I disable this by setting the delay 1000.0, the bug no longer appears.
This would suggest the problem is be timing related.
Without this change, even if I click super fast, the button still misses sometimes, so maybe we are somehow exceeding this click duration in a single frame or something :thinking:
Well, I think the issue is essentially caused by https://github.com/bevyengine/bevy/issues/14682
The time we report to egui is time.elapsed_seconds_f64()
, which is actually delayed by a few frames.
This means this sequence occurs (just an handwritten example):
-> tick actual_time = 1.0 time.elapsed_seconds() = 0.0
-> mouse press actual_time = 3.0 time.elapsed_seconds() = 1.0
-> mouse release actual_time = 3.1 time.elapsed_seconds() = 3.0
Even though there was only 0.1s between press and release, the reported elapsed_seconds will be delayed by a few frames, so egui will perceive it as 2s so it will not register the click.
I can see two workarounds, though I'm not sure either of them really address the root issue:
bevy_egui
internally do its own time tracking, to bypass bevy's delayed timekeeping
Button clicks are sometimes lost in reactive mode. To reproduce, run this example:
Click the button multiple times, and sometimes the counter will not increment