I was debugging a given C++ code with the F11 key (Step Into mode) in order to understand the precise order in which the functions in the code were called and I realized that it would never enter inside some functions unless I set a breakpoint at some line inside the function definition.
I mean, if I call a function from the main method, and the function is defined in another .cpp I expect the F11 debugging mode to enter step by step inside the function in order to analize the variable changes. Most of the times it does but in some cases it just execute the function without stepping into it, and jumps to the next line in the main method.
Why is this happening?
Example:
This is the function F11 would never step into:
void VirtualCamera::display (void) {
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Clear the background of the window
glClear(GL_COLOR_BUFFER_BIT); //Clear the colour buffer (more buffers later on)
glLoadIdentity(); // Load the Identity Matrix to reset our drawing locations
glTranslatef(0.0f, 0.0f, -5.0f);
renderPrimitive(); // Render the primitive
glFlush(); // Flush the OpenGL buffers to the window
}
This is the main method where F11 goes step by step:
void VirtualCamera::CameraMain(int argc, char **argv){
glutInit(&argc, argv); // Initialize GLUT
glutInitDisplayMode (GLUT_SINGLE);
glutInitWindowSize (500, 500); // Set the width and height of the window
glutInitWindowPosition (100, 100); // Set the position of the window
glutCreateWindow ("OpenGL Window"); // Set the title for the window
glutDisplayFunc(display); // Tell GLUT to use the method "display" for rendering
glutReshapeFunc(reshape);
glutMainLoop(); // Enter GLUT's main loop
}
Worth a quick check..
In Visual Studio, go to Tools > Options...
Click Debugging on left side
On the left look for Enable Just my Code (Managed) if it is checked, uncheck it, hit "OK"
For good measure I always exit VS and go back in
You need debugging information to enter the glutMainLoop. When no source code or no debugging info is available for glutMainLoop the debugger can't display source code. When you want to single step this function you need to add both.
Alternatively you can enter to disassembly using Shift-F11. But I dont't think that this will help in this case.
When stepping through the code in CameraMain
, do you expect to be able to step into display
on the call to glutDisplayFunc(display);
?
In that case it doesn't happen because the display
function is not called at that point. Instead it is saved by GLUT to be called from inside the GLUT main loop. You have to set a breakpoint in the display
function to be able to step through it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With