2021年2月4日星期四

gladLoadGLLoader throws a runtime error for me

I am trying to use openGL and have just setup glad, however when I call gladLoadGLLoader it give mes the error "Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention. ". I have never seen this error before, the exact line of code is the following

    glGetString = (PFNGLGETSTRINGPROC)load("glGetString");  

my code is just in a window wrapper class

Window::Window(int _width, int _height, int x, int y, const char* title)      {                width = _width;          height = _height;          windowX = x;          windowY = y;          windowTitle = title;              RECT wr;          wr.left = 100;          wr.right = width + wr.left;          wr.top = 100;          wr.bottom = height + wr.top;          if (AdjustWindowRect(&wr, WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU, FALSE) == 0)          {              Exception::WindowException e("AdjustWindowRect failed", __FILE__, __LINE__, -1);              throw e;          }              ///           /// temporary window          ///                   HWND temporaryHandle = CreateWindowExA(0l, WindowClass::getInstance().getClassName(), "temporary Window", WS_CLIPSIBLINGS | WS_CLIPCHILDREN,              0, 0, 1, 1, NULL, NULL, WindowClass::getInstance().getHInstance(), NULL);            HDC temporaryDeviceContext = GetDC(temporaryHandle);            PIXELFORMATDESCRIPTOR temporaryPFD = { 0 };          temporaryPFD.nSize = sizeof(PIXELFORMATDESCRIPTOR);          temporaryPFD.nVersion = 1;          temporaryPFD.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;          temporaryPFD.iPixelType = PFD_TYPE_RGBA;          temporaryPFD.cColorBits = 32;          temporaryPFD.cAlphaBits = 8;          temporaryPFD.cDepthBits = 24;              int temporaryPFDSuccess = ChoosePixelFormat(temporaryDeviceContext, &temporaryPFD);            if (temporaryPFDSuccess == 0)          {              Exception::WindowException e("ChoosePixelFormat failed", __FILE__, __LINE__, -1);              throw e;          }              if (SetPixelFormat(temporaryDeviceContext, temporaryPFDSuccess, &temporaryPFD) == false)          {              Exception::WindowException e("SetPixelFormat failed", __FILE__, __LINE__, -1);              throw e;          }              HGLRC temporaryContext = wglCreateContext(temporaryDeviceContext);          if (temporaryContext == 0)          {              Exception::WindowException e("wglCreateContext failed", __FILE__, __LINE__, -1);              throw e;          }            if (wglMakeCurrent(temporaryDeviceContext, temporaryContext) == 0)          {              Exception::WindowException e("wglMakeCurrent failed", __FILE__, __LINE__, -1);              throw e;            }                  PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = nullptr;          wglChoosePixelFormatARB = reinterpret_cast<PFNWGLCHOOSEPIXELFORMATARBPROC>(wglGetProcAddress("wglChoosePixelFormatARB"));          if (wglChoosePixelFormatARB == nullptr)          {              Exception::WindowException e("wglChoosePixelFormatARB did not load properly", __FILE__, __LINE__, -1);              throw e;          }            PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = nullptr;          wglCreateContextAttribsARB = reinterpret_cast<PFNWGLCREATECONTEXTATTRIBSARBPROC>(wglGetProcAddress("wglCreateContextAttribsARB"));          if (wglCreateContextAttribsARB == nullptr)          {              Exception::WindowException e("wglCreateContetAttribsARB did not load properly", __FILE__, __LINE__, -1);              throw e;          }                ///          /// real window          ///               windowHandle = CreateWindowExA(0l, WindowClass::getInstance().getClassName(),              windowTitle, WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,              windowX, windowY, wr.right - wr.left, wr.bottom - wr.top, nullptr, nullptr, WindowClass::getInstance().getHInstance(), this);            HDC realDeviceContext = GetDC(windowHandle);            const int pixelAttribs[] = {          WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,          WGL_SUPPORT_OPENGL_ARB, GL_TRUE,          WGL_DOUBLE_BUFFER_ARB, GL_TRUE,          WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,          WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB,          WGL_COLOR_BITS_ARB, 32,          WGL_ALPHA_BITS_ARB, 8,          WGL_DEPTH_BITS_ARB, 24,          WGL_STENCIL_BITS_ARB, 8,          WGL_SAMPLE_BUFFERS_ARB, GL_TRUE,          WGL_SAMPLES_ARB, 4,          0          };              int pixelFormatID;          UINT numFormats;          bool status = wglChoosePixelFormatARB(realDeviceContext, pixelAttribs, NULL, 1, &pixelFormatID, &numFormats);                if (status == false || numFormats == 0)          {              Exception::WindowException e("wglChoosePixelFormatARB", __FILE__, __LINE__, -1);              throw e;          }              PIXELFORMATDESCRIPTOR realPFD;          DescribePixelFormat(realDeviceContext, pixelFormatID, sizeof(realPFD), &realPFD);          SetPixelFormat(realDeviceContext, pixelFormatID, &realPFD);            const int major_min = 4, minor_min = 5;          int  contextAttribs[] = {              WGL_CONTEXT_MAJOR_VERSION_ARB, major_min,              WGL_CONTEXT_MINOR_VERSION_ARB, minor_min,              WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,              0          };                HGLRC realContext = wglCreateContextAttribsARB(realDeviceContext, 0, contextAttribs);          if (realContext == NULL)          {              Exception::WindowException e("wglCreateContextAttribsARB failed", __FILE__, __LINE__, -1);              throw e;          }                  wglMakeCurrent(NULL, NULL);          wglDeleteContext(temporaryContext);          ReleaseDC(temporaryHandle, temporaryDeviceContext);          DestroyWindow(temporaryHandle);          int madeCurrent = wglMakeCurrent(realDeviceContext, realContext);          if (madeCurrent == 0)          {              Exception::WindowException e("wglMakeCurrent failed", __FILE__, __LINE__, -1);              throw e;          }                      if (!gladLoadGLLoader((GLADloadproc)wglGetProcAddress))          {              PostQuitMessage(0);              return;          }              glClear(GL_COLOR_BUFFER_BIT);          SwapBuffers(realDeviceContext);              ShowWindow(windowHandle, SW_SHOW);          }  
https://stackoverflow.com/questions/66057453/gladloadglloader-throws-a-runtime-error-for-me February 05, 2021 at 12:08PM

没有评论:

发表评论