Debugging GLFW application with GLFW_CURSOR_DISABLED

Started by
15 comments, last by thamas_bacsi 1 year, 12 months ago

Hello,

On my up-to-date Archlinux system I am developing an OpenGL application in C++ and I am using GLFW for the window creation. For different reasons I would like to disable the cursor with

glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);

This disables the mouse, makes the "mouse_move_delta" computation easy, etc. My problem is that it makes debugging almost impossible, because when the execution is paused, my cursor is still "lost".

I tried to use the glfwSetWindowFocusCallback() function to "enable" the mouse when focus is lost, but when a breakpoint is hit, this callback is not called.

   glfwSetWindowFocusCallback(m_window, [](GLFWwindow* window, int isInFocus)
   {
      if (isInFocus == GLFW_FALSE)
      {
         std::cout << "NOT in focus" << std::endl;
         glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
      }
      else
      {
         glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
      }
   });

I didn't find too much similar questions to mine, one was this: https://github.com/glfw/glfw/issues/530 This says it is not possible to use glfwSetWindowFocusCallback for a case like this. The link proposes a solution, but I don't understand that and I don't think the solution would be to recompile the GLFW...

Now what I do when I would like to debug is to set the cursor to normal (GLFW_CURSOR_NORMAL) recompile and rerun my application, I just don't want to believe this is the way it should be done.

So my question is: is it possible to debug (with enabled mouse cursor etc) when GLFW_CURSOR_DISABLED is used?

Or more general: on other systems (with SDL for example) does debugging with captured mouse work?

Advertisement

Afaik gdb does support remote debugging, so that would be another option. Never tried that though, no idea how usable it is.

I am using the same GLFW method, but on Windows, debugging through Visual Studio. In my case, alt+tabbing away from the window “releases” the cursor, no matter if execution was paused or not. The github issue you linked also says that that alt+tab gives the cursor back. I am assuming you are doing debugging away from the paused window (in GDB or something), so you shouldn't have trouble with the cursor.

@fleabay Hello, thanks for the idea to toggle the it on / off. This may be a good idea in other cases, but when the execution is paused (breakpoint is hit, etc) I can not press a button to toggle the mode.

Alberth said:

Afaik gdb does support remote debugging, so that would be another option. Never tried that though, no idea how usable it is.

Me neither, maybe I will have to, thanks for the idea.

1024 said:

I am using the same GLFW method, but on Windows, debugging through Visual Studio. In my case, alt+tabbing away from the window “releases” the cursor, no matter if execution was paused or not. The github issue you linked also says that that alt+tab gives the cursor back. I am assuming you are doing debugging away from the paused window (in GDB or something), so you shouldn't have trouble with the cursor.

Hello, even without the callback mentioned in my original post I can alt+tab away while the program is running and in this case I get the pointer back. However when a breakpoint is hit then the cursor is “lost” (with or without the code from above).

So for example when I alt+tab to this browser window I have no mouse… (I mean when a breakpoint was hit, assertion happened, etc).

So I would say, this is a bug in GLFW but as you can see in the link above, they would never agree with this…

thamas_bacsi said:
So for example when I alt+tab to this browser window I have no mouse…

I understand now. It does seem like a bug, but it's not a GLFW bug. Program execution is paused, there is nothing GLFW can do. Since this doesn't happen on all platforms, it's possible that the bug is somewhere in your platform or DE.

1024 said:

thamas_bacsi said:
So for example when I alt+tab to this browser window I have no mouse…

I understand now. It does seem like a bug, but it's not a GLFW bug. Program execution is paused, there is nothing GLFW can do. Since this doesn't happen on all platforms, it's possible that the bug is somewhere in your platform or DE.

You are right, I will give it a try with another Desktop Environment.

thamas_bacsi said:

1024 said:

thamas_bacsi said:
So for example when I alt+tab to this browser window I have no mouse…

I understand now. It does seem like a bug, but it's not a GLFW bug. Program execution is paused, there is nothing GLFW can do. Since this doesn't happen on all platforms, it's possible that the bug is somewhere in your platform or DE.

You are right, I will give it a try with another Desktop Environment.

Thanks @1024! I switched from LXDE to XFCE (these are using different window environments) and not I get back the mouse when a breakpoint is hit, without the need of glfwSetWindowFocusCallback.

This topic is closed to new replies.

Advertisement