mvlabat / bevy_egui

This crate provides an Egui integration for the Bevy game engine. πŸ‡ΊπŸ‡¦ Please support the Ukrainian army: https://savelife.in.ua/en/
MIT License
915 stars 242 forks source link

Ui not redrawing correctly when using `WinitSettings::desktop_app()` #292

Closed ThomasAlban closed 1 month ago

ThomasAlban commented 3 months ago

Hi, this issue was fixed a few months ago in #240 but it seems to have cropped back up ever since I updated to bevy 0.14. I'm using WinitSettings::desktop_app(), and when e.g. clicking a button, the UI does not redraw until I move the mouse. This might have been broken by #278!

ThomasAlban commented 3 months ago

Here is a demonstration of the issue. When I click a button, it only appears blue after I wiggle the mouse:

https://github.com/mvlabat/bevy_egui/assets/98399119/a4edca91-31a6-48f9-a0f7-4402579389bc

mvlabat commented 3 months ago

Hi! I'm sorry to hear the update has broken the redraw functionality for you. Could you help me to reproduce the issue? I've tried to come up with an example based on your description, but I guess I'm missing something because it's still working for me. Can you please take a look at #293? Feel free to suggest edits.

ThomasAlban commented 2 months ago

Hi, Thanks very much for attempting to reproduce the issue. Weird that it works for you but not for me! I've also had another redraw issue elsewhere in my project ever since I updated: I have a flycam which uses WASD to move. Normally holding a key doesn't continuously trigger redraws, so I added a piece of code to the fly cam system to check if the keys are pressed and if so send a redraw event. This always worked in previous versions, but now there's a delay of half a second before the redraws are sent, which is very odd. I'm going to do some more investigating into this, but it could even be that this issue is nothing to do with bevy_egui! Do you have any idea what could be happening to cause these things breaking?

mvlabat commented 2 months ago

No idea atm. :( Have you tried running the example from the linked MR? I'm wondering if it works ok for you. If you can reproduce the issue there, that means the problem might be platform-specific. If not, then it means I've come up with a wrong example.

jabuwu commented 2 months ago

I'm having the issue as well, with that PR (#293). MacOS.

https://github.com/user-attachments/assets/aa50c784-5f8e-4fab-bb09-3791a6b5dcd4

I was coming at this issue from a different angle. I have a particular interest in spinners continuing to work after this change. if I add a spinner, you can see the buttons behave properly.

https://github.com/user-attachments/assets/f811707e-64b9-451f-90cd-dd0849979c2f

Which makes sense, because spinners cause constant redraws. I will try to investigate this further.

ThomasAlban commented 2 months ago

@jabuwu ah brilliant, I'm on macOS (M1) as well so it seems like it could be a Mac-related issue! I'll have to test the example and see if the issue still occurs, will let you know the results

mvlabat commented 2 months ago

The thing is, I'm also on MacOS, and I still couldn't reproduce it. Now I can though. I don't know what has changed, maybe I was just unlucky or clumsy with my trackpad (e.g. moving the pointer accidentally after pressing a button), but that gives an opportunity to debug it at least πŸ™ƒ

ThomasAlban commented 2 months ago

Just tested your example, and I can reproduce the issue - but only some of the time - sometimes when I click, everything works fine, and other times it doesn't fire enough redraws to show the button becoming blue. So seems like a luck thing, maybe the frequency of the issue happening is influenced by things like the refresh rate or your monitor or maybe ui complexity in the project.....? I can tell you that in my project it happens p much 100% of the time, and the UI there is quite a lot more complex

mvlabat commented 2 months ago

I've just pushed another commit to #293 that should fix the issue. Please let me know if it indeed fixes it for you.

@Maximetinu if you can double-check that it doesn't break redraws again, I'll also be grateful :D

ThomasAlban commented 2 months ago

Yes, that fixes it for me. Thank you!

Maximetinu commented 2 months ago

@Maximetinu if you can double-check that it doesn't break redraws again, I'll also be grateful :D

I just double checked, it doesn't!

Maximetinu commented 2 months ago

It'd be nice writing an automatic test to cover this, replicating the repro steps that I described in #277

Given that no egui systems are running
When I move the cursor on top of the screen
Then no RequestRedraw event is sent

The given and the then are easy to set up in code, but I don't know how I can simulate the when reliably with no real window πŸ€”

Sending a CursorMoved event myself tricks the EguiPlugin to think that the cursor moved, but the EguiPlugin panics if I add it in a unit test with no real window.

mvlabat commented 1 month ago

The initial issue seems to be fixed. But there may be other issues related to the energy saving settings: #295, #302.