Version/Branch of Dear ImGui:
Version: 1.72
Branch: _master_
NO changes to ImGUI backend (neither main.cpp)
Back-end/Renderer/Compiler/OS
Back-ends: imgui_impl_sdl.cpp + imgui_impl_opengl3.cpp but also imgui_impl_dx11.cpp
Operating System: Windows 10
My Issue:
_symptoms_
While the ImGUI + SDL + OpenGL (directX11) window runs, I move the mouse to an other portion of the screen free from the main window. The primary window would loose focus and I start dragging the mouse around. After few seconds of fast mouse moves, the main window got freezed. If an high priority event (as a Ctrl+Alt+Canc signal) would de-freeze the main window.
_observation_
To me, looks as the event queue of the main window is not being properly emptied by the main window thread. Decompiling the assembly of the program, it looks that the program get stocked in the SDL_PollEvent(), an other sign that is concerning the event queue dedicated to that process
_question_
I am not expecting this to be stricly _Dear ImGUI_ related, but can be beneficial for this community, since the bug is effecting the sdl integration and examples. Moreover someone might had already observed this behaviour and we can work together for fixing it in the _Dear ImGUI_ main branch. In fact the problem is present in the example application
_additional observations_
MSG msg;
if (::PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE)){
::TranslateMessage(&msg);
::DispatchMessage(&msg);
continue;
}
SDL_PumpEvents();
SDL_PeepEvents(&event, 100, SDL_PEEKEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT);
SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT);
Video

Standalone, minimal, complete and verifiable example:
As a even more minimalist version of the imgui example using SDL with openGL
#define SDL_MAIN_HANDLED
#include "imgui.h"
#include "imgui_impl_sdl.h"
#include "imgui_impl_opengl3.h"
#include <stdio.h>
#include <SDL.h>
#if defined(IMGUI_IMPL_OPENGL_LOADER_GL3W)
#include <GL/gl3w.h> // Initialize with gl3wInit()
#endif
// Main code
int main()
{
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER); // GL 3.0 + GLSL 130
const char* glsl_version = "#version 130";
// Create window with graphics context
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
SDL_Window* window = SDL_CreateWindow("Dear ImGui SDL2+OpenGL3 example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, window_flags);
SDL_GLContext gl_context = SDL_GL_CreateContext(window);
SDL_GL_MakeCurrent(window, gl_context);
SDL_GL_SetSwapInterval(1); // Enable vsync
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
ImGui_ImplSDL2_InitForOpenGL(window, gl_context);
ImGui_ImplOpenGL3_Init(glsl_version);
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
bool done = false;
while (!done)
{
SDL_Event event;
while (SDL_PollEvent(&event))
{
ImGui_ImplSDL2_ProcessEvent(&event);
if (event.type == SDL_QUIT)
done = true;
}
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplSDL2_NewFrame(window);
ImGui::NewFrame();
{
ImGui::Begin("Hello, world!");
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
ImGui::End();
}
ImGui::Render();
glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y);
glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
glClear(GL_COLOR_BUFFER_BIT);
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
SDL_GL_SwapWindow(window);
}
// Cleanup
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplSDL2_Shutdown();
ImGui::DestroyContext();
SDL_GL_DeleteContext(gl_context);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
Anyway, thank you for this amazing piece for software that Dear ImGUI is. I am using it since years, and it got better and better and better.
_Happy Anniversary_
Valentina
Ciao, Valentina
I tried your standalone example (apropos, gl3wInit(); is missing), but the problem does not occur to me.
I compiled it (w/o changing a comma) with vs2019 and vs2017, SDL v.2.0.10 (release) and ImGui v.1.73 (release), and tested outside (and also inside) VS IDE, without (but also with) window focus, in Windows 10 19H1 (alias 1903) with i7 8700k CPU/RTX 2070 GPU... both: Debug and Release version (both, x86 & x64).
~Tonight I try it even on a slower CPU/GPU (i5 6400) and a different Windows 10 version (RS3/1709)
(though the windows version should be irrelevant, since works with PeekMessage())~
More...
Tested also on i5 6400 CPU/GTX 1050TI GPU and Windows 10 version (RS3/1709), with SDL 2.0.6 and ImGui 1.72 (ver. of 31/07), but I'm sorry I could not reproduce the issue.
Allow me a question: have you also a game pad/controller attached... or game-pad emulator installed?
Or using mouse + mouse-pad installed together?
Try also to remove SDL_INIT_GAMECONTROLLER from SDL_Init call.
(are only hypotheses because this seems like an anomalous production of inputs).
But same code w/o ImGui parts, what happen?
(just to understand if is SDL or SDL+ImGui trouble)
Hi Michele,
You got the point: was the SDL_INIT_GAMECONTROLLER from the SDL_Init call.
For ensuring it wasn't the joystick fault, in my rushy debugging I removed line 298 from imgui_impl_sdl.cpp ImGui_ImplSDL2_UpdateGamepads(); but clearly, it wasn't enough. Just for being double sure it was uncareful SDL usage and not ImGUI+SDL I removed all the ImGUI in the rendering loop, kept SDL_INIT_GAMECONTROLLER and still the executable was freezing.
Solution
Removing the SDL_INIT_GAMECONTROLLER from SDL_Init
Setup
For the benefit of the community, my setup was the following: an external mouse via USB dongle, a touchpad and the Lenovo's red trackpad. I think (might you confirm) that the external mouse would be misunderstood as a joypad: might this be the case?
Thanks
Thank you for taking the time and the care of trying my code and replying to this.
Thanks to this heartwarming community of desktop frontend-er dedicated to realtime.
No problem, Vanelntina, You're welcome.
I remember, some year ago, an analogue issue with multi beam bathymetric data acquisition and a strange slowdown/lost input data: in that case we had Desktop PC with a keyboard with integrated touch-pad + external mouse. (ImGui was not present and using still Windows 7)
Thanks your analysis (with PeekMessage), and your smartphone video (instead of desktop recording via software) I noticed that you were using a notebook (with possible touch-pad+mouse) and that episode came back to me.
Honestly I don't know the casuistry or frequency of how this becomes a problem, rather I believe (can imagine) that some touch-pad drivers are developed expressly to detect it (also) like a game/joy-pad (to play a game) in presence of other mouse (or also alone).
Thank you for appreciations to me... and mostly to the whole community.
Michele
Thank you Valentina and Michele for your digilence and detailed explanations.
I'd like to also point out #2484 where an opposite problem was raised: when _NOT_ setting SDL_INIT_GAMECONTROLLER SDL would behave erratically and apparently a bug was fixed in SDL 2.0.10 (quite recently).
@ValentinaTibs Could you clarify which version of SDL you are using?
It might be useful to know, and in case your version is not the latest it might be worth trying to use 2.0.10 to confirm it.
As Michele pointed it might be a driver bug, but that is also the sort of things that library like SDL attempt to work-around one way or another, so if the bug still happens with latest SDL it may be worth reporting it on SDL side.
Hello everyone,
I watched issue #2484 and to me looks really close to the same I am experiencing, especially effects-wise. The SDL version I was using was 2.0.8.0
From the fast test I made with SDL new version, (aka moving the mouse around as crazy while the click is clicked and the window is out of focus) updating SDL to version 2.0.10.0 solved the issue. So...
Alternative Solution _(in case SDL_INIT_GAMECONTROLLER is really needed)_
use SDL version 2.0.10.0
I would give you further updates and if necessary I would be happy to help you with the SDL ticket
Thanks!
My gut feeling is that there's no point opening a SDL ticket if they fixed it in 2.0.10, we should just be encouraging people to use the latest version of SDL and make sure that most package managers have it. It is surprising 2.0.8 would have just glaring bug but then modern OS and drivers are so complex and confusing we can't expect any software to be perfect.
Action taken: added comments in example_sdl_*/main.cpp about this and to encourage people to update SDL.
Most helpful comment
Hello everyone,
I watched issue #2484 and to me looks really close to the same I am experiencing, especially effects-wise. The SDL version I was using was 2.0.8.0
From the fast test I made with SDL new version, (aka moving the mouse around as crazy while the click is clicked and the window is out of focus) updating SDL to version 2.0.10.0 solved the issue. So...
Alternative Solution _(in case SDL_INIT_GAMECONTROLLER is really needed)_
use SDL version 2.0.10.0
I would give you further updates and if necessary I would be happy to help you with the SDL ticket