Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assertion failure while waking from sleep on MacOS #5683

Closed
Guistac opened this issue Sep 15, 2022 · 13 comments
Closed

Assertion failure while waking from sleep on MacOS #5683

Guistac opened this issue Sep 15, 2022 · 13 comments

Comments

@Guistac
Copy link

Guistac commented Sep 15, 2022

Version: 1.89 (Docking)
Back-ends: imgui_impl_glfw imgui_impl_opengl3
OS: MacOS 12.3.1

When waking my machine from sleep while running my app, imgui fails to assert g.PlatformIO.Monitors.Size > 0

imgui/imgui.cpp

Line 8938 in 64b88da

IM_ASSERT(g.PlatformIO.Monitors.Size > 0 && "Platform init didn't setup Monitors list?");

It doesn't do this consistently, there is about a 50% chance it will happen on each sleep wake cycle.
How does disabling this assertion affect the integrity of imgui?
I've currently commented it out and experienced no issues.
I'm curious if anyone experiences the same issue, as I'm currently unable to test it on another system.

@ocornut
Copy link
Owner

ocornut commented Sep 15, 2022

This is needed for multi-viewport support.
Instead of disabling the assert we should be investigating what leads the GLFW backends to clear this and not restore it in time. Adding logging (withf
frame count) in the GLFW events/functions leading to change of monitor data would be useful.

@PathogenDavid
Copy link
Contributor

This might just be a quirk of how macOS handles monitors during standby:

In standby, the monitor is actually disconnected and disappears from the I/O Registry, so on system wake, it reconnects and the OS has to rearrange based on the stored settings.

GLFW on macOS filters out displays which are asleep. This seems reasonable, but according to the quirk described above that sounds like that creates a brief moment in time where GLFW could report 0 monitors.

Ignoring the assert is definitely wrong, but maybe it'd be reasonable for the GLFW backend to just ignore the monitor change event when glfwGetMonitors returns no monitors?

@ocornut
Copy link
Owner

ocornut commented Sep 15, 2022

Ignoring the assert is definitely wrong, but maybe it'd be reasonable for the GLFW backend to just ignore the monitor change event when glfwGetMonitors returns no monitors?

I agree, that sounds good (with a comment and # ref to explain why)

@phraktle
Copy link

phraktle commented Feb 7, 2023

Any plans for a fix? This does happen still.

@emoon
Copy link
Contributor

emoon commented Mar 15, 2023

I don't want to hijack this issue, but I'm getting the same assert if you try to use the glfw_opengl3 example with Emscripten on the docking branch (regular works fine)

Uncaught RuntimeError: Aborted(Assertion failed: g.PlatformIO.Monitors.Size > 0 && "Platform init didn't setup Monitors list?", at: ../../imgui.cpp,9623,ErrorCheckNewFrameSanityChecks)

@Guistac
Copy link
Author

Guistac commented Mar 15, 2023

Hi, I did manage to fix this particular issue by adding the following code to ImGui_ImplGlfw_UpdateMonitors() right after
GLFWmonitor** glfw_monitors = glfwGetMonitors(&monitors_count);

#if __APPLE__
//waking MacOS from sleep sometimes causes glfw to report 0 monitors.
//if this happens we abort updating monitors but keep WantUpdateMonitors == true to check again on the next frame
//git issue: https://github.com/ocornut/imgui/issues/5683
if(monitors_count == 0){
  bd->WantUpdateMonitors = true;
  return;
}
#endif

I wanted to do a pull request but I'm pretty new to versioning and got confused by how git works...

ocornut added a commit that referenced this issue Mar 15, 2023
@ocornut
Copy link
Owner

ocornut commented Mar 15, 2023

I'm getting the same assert if you try to use the glfw_opengl3 example with Emscripten on the docking branch (regular works fine)

This specifically was an issue with the backend erroneously setting ImGuiBackendFlags_PlatformHasViewports on Emscripten, fixed now with 85beda9.

I'm going to look at this on a Mac later.

@ocornut
Copy link
Owner

ocornut commented Mar 23, 2023

I couldn't find a way to repro the main/first issue on a Mac here.

@phraktle
Copy link

Happens on my MacBook Pro (15-inch, 2016), MacOS Monterey 12.6.3 when waking from sleep (though not deterministically). I did not yet see it on a more recent M1 mac.

@phraktle
Copy link

phraktle commented Apr 1, 2023

happens on the M2 as well, but less frequently.

@ocornut
Copy link
Owner

ocornut commented May 25, 2023

I couldn't repro this but applied the suggested fix nonetheless : 19b436f .
Sorry for being late. Thanks!

@ocornut ocornut closed this as completed May 25, 2023
@JaedanC
Copy link

JaedanC commented May 26, 2023

Sorry to bring up an closed issue but this commit 19b436f actually breaks my code and results in the IM_ASSERT(g.PlatformIO.Monitors.Size > 0 && "Platform init didn't setup Monitors list?"); being triggered on the first call to NewFrame. I'm still investigating what's going on and I'll make a separate issue once I figure it out.

@ocornut
Copy link
Owner

ocornut commented May 26, 2023

Apologies for the typo, pushed fix 2e810d5 (first time I do a code edit directly on github!).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants