Dev-Cpp
Dev-Cpp copied to clipboard
debugger gets stuck at function referenced by wglGetProcAddress
When OpenGL extensions are used that have been referenced by wglGetProcAddress, the debugger gets stuck when calling this extension, i.e. executing a single step with that extension is not possible:

As a possible workaround, I usually set a further breakpoint after the critical line (containing the extension) and press "Continue" to jump to that breakpoint.
The example code above unfortunately does need some preparation, you also need to use -lopengl32 -lgdi32 as a linker setting. The minimal working example is:
#define APIENTRY
#define APIENTRYP APIENTRY *
#include <gl/gl.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
// some init, needed for wglGetProcAddress
WNDCLASSEX windowClass;
ZeroMemory(&windowClass, sizeof(WNDCLASSEX));
windowClass.cbSize = sizeof(WNDCLASSEX);
windowClass.style = CS_OWNDC;
windowClass.lpfnWndProc = (WNDPROC)(DefWindowProc);
windowClass.hInstance = hInstance;
windowClass.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE);
windowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
windowClass.lpszClassName = "OpenGLTest";
RegisterClassEx(&windowClass);
HWND hWnd = CreateWindowEx(WS_EX_APPWINDOW, "OpenGLTest", "Test Title", WS_OVERLAPPEDWINDOW, 0, 0, 640, 480, HWND_DESKTOP, 0, hInstance, NULL);
HDC hDC = GetDC(hWnd);
PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), 1, PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL, PFD_TYPE_RGBA, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 8, 0, PFD_MAIN_PLANE, 0, 0, 0, 0 };
GLuint PixelFormat = ChoosePixelFormat(hDC, &pfd);
SetPixelFormat(hDC, PixelFormat, &pfd);
HGLRC hRC = wglCreateContext(hDC);
wglMakeCurrent(hDC, hRC);
// interesting part
typedef void (APIENTRYP PFNGLGENERATEMIPMAPPROC) (GLenum target);
PFNGLGENERATEMIPMAPPROC glGenerateMipmap = (PFNGLGENERATEMIPMAPPROC)wglGetProcAddress("glGenerateMipmap");
if (glGenerateMipmap) {
// watch: debug with single step not possible here
glGenerateMipmap(GL_TEXTURE_2D);
}
// clean up
wglMakeCurrent(hDC, 0);
wglDeleteContext(hRC);
ReleaseDC(hWnd, hDC);
DestroyWindow(hWnd);
UnregisterClass("OpenGLTest", hInstance);
return 0;
}