Jump to content
  • Advertisement
KarimIO

OpenGL SwapBuffer Nvidia Crash

This topic is 511 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

EDIT: I thought this was restricted to Attribute-Created GL contexts, but it isn't, so I rewrote the post.

Hey guys, whenever I call SwapBuffers(hDC), I get a crash, and I get a "Too many posts were made to a semaphore." from Windows as I call SwapBuffers. What could be the cause of this?

Update: No crash occurs if I don't draw, just clear and swap.

static  PIXELFORMATDESCRIPTOR pfd =             // pfd Tells Windows How We Want Things To Be
    {
        sizeof(PIXELFORMATDESCRIPTOR),              // Size Of This Pixel Format Descriptor
        1,                                          // Version Number
        PFD_DRAW_TO_WINDOW |                        // Format Must Support Window
        PFD_SUPPORT_OPENGL |                        // Format Must Support OpenGL
        PFD_DOUBLEBUFFER,                           // Must Support Double Buffering
        PFD_TYPE_RGBA,                              // Request An RGBA Format
        32,                                         // Select Our Color Depth
        0, 0, 0, 0, 0, 0,                           // Color Bits Ignored
        0,                                          // No Alpha Buffer
        0,                                          // Shift Bit Ignored
        0,                                          // No Accumulation Buffer
        0, 0, 0, 0,                                 // Accumulation Bits Ignored
        24,                                         // 24Bit Z-Buffer (Depth Buffer)  
        0,                                          // No Stencil Buffer
        0,                                          // No Auxiliary Buffer
        PFD_MAIN_PLANE,                             // Main Drawing Layer
        0,                                          // Reserved
        0, 0, 0                                     // Layer Masks Ignored
    };

if (!(hDC = GetDC(windowHandle)))
    return false;

unsigned int PixelFormat;
if (!(PixelFormat = ChoosePixelFormat(hDC, &pfd)))
    return false;

if (!SetPixelFormat(hDC, PixelFormat, &pfd))
    return false;

hRC = wglCreateContext(hDC);
if (!hRC) {
    std::cout << "wglCreateContext Failed!\n";
    return false;
}

if (wglMakeCurrent(hDC, hRC) == NULL) {
    std::cout << "Make Context Current Second Failed!\n";
    return false;
}

... // OGL Buffer Initialization

glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
glBindVertexArray(vao);
glUseProgram(myprogram);
glDrawElements(GL_TRIANGLES, indexCount, GL_UNSIGNED_SHORT, (void *)indexStart);
SwapBuffers(GetDC(window_handle));

 

Edited by KarimIO
Update

Share this post


Link to post
Share on other sites
Advertisement
SwapBuffers(GetDC(window_handle));

This is a resource leak; you need to call ReleaseDC to match your GetDC.  You should also create your window class with CS_OWNDC if you use this pattern (otherwise store the window DC once only at startup in a global of some kind).

Share this post


Link to post
Share on other sites
4 hours ago, mhagain said:

SwapBuffers(GetDC(window_handle));

This is a resource leak; you need to call ReleaseDC to match your GetDC.  You should also create your window class with CS_OWNDC if you use this pattern (otherwise store the window DC once only at startup in a global of some kind).

I tried to use the same DC, but still get issues.

EDIT: To be clear, you mean to ReleaseDC when cleaning up / exiting the process, correct?

Edited by KarimIO
Question of Clarification

Share this post


Link to post
Share on other sites
36 minutes ago, KarimIO said:

I tried to use the same DC, but still get issues.

EDIT: To be clear, you mean to ReleaseDC when cleaning up / exiting the process, correct?

I mean ReleaseDC after each GetDC; as it stands now you call GetDC each frame so eventually you're going to run out of DCs.  Use something like this instead:

HDC hDC;

if ((hDC = GetDC (window_handle)) != NULL)
{
	SwapBuffers (hDC);
	ReleaseDC (hDC);
}

 

Share this post


Link to post
Share on other sites
38 minutes ago, mhagain said:

I mean ReleaseDC after each GetDC; as it stands now you call GetDC each frame so eventually you're going to run out of DCs.  Use something like this instead:


HDC hDC;

if ((hDC = GetDC (window_handle)) != NULL)
{
	SwapBuffers (hDC);
	ReleaseDC (hDC);
}

 

I've instead used the same hDC stored in my graphics class, but it solves nothing. I'm sorry, but can you think of anything else?

Share this post


Link to post
Share on other sites

Also, by "crash", I mean the program freezes, screen goes black, and then I get a fatal error called in Visual Studio from Nvidia's DLL

Share this post


Link to post
Share on other sites
44 minutes ago, KarimIO said:

I've instead used the same hDC stored in my graphics class, but it solves nothing. I'm sorry, but can you think of anything else?

You're still making a call to GetDC each frame though - that's a resource leak.  You need to fix that first because otherwise you've two potential problems going on and you won't know whether any issues you have are coming from either.

Share this post


Link to post
Share on other sites
5 minutes ago, mhagain said:

You're still making a call to GetDC each frame though - that's a resource leak.  You need to fix that first because otherwise you've two potential problems going on and you won't know whether any issues you have are coming from either.

I have. Now it's this:

SwapBuffers(hDC);

Which means I get it once in the beginning and remove it once in the end of the process.

Share this post


Link to post
Share on other sites

I found the answer. The SwapBuffer(hDC) command was simply where the error occurred, but did not have anything to do with it. I believe my error was due to something related to my indices, as if I draw only the first mesh in the model,  everything works as intended. Nvidia crashed with this error, Intel went on and disregarded it.

Nonetheless, thank you to Chris Becke for pointing out a future memory leak using GetDC(hwnd).

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!