2017-07-17 105 views
-3

編輯:我認爲這是限制在屬性創建GL上下文,但它不是,所以我重寫了這篇文章。SwapBuffer Nvidia崩潰

嘿傢伙,每當我打電話給SwapBuffers(hDC),我都會崩潰。如果我用WGL_CONTEXT_DEBUG_BIT_ARB創建它,我會得到一個「信號量太多的帖子」。從Windows我打電話SwapBuffers。這可能是什麼原因?

更新:如果我沒有繪製,只要清除並交換,就不會發生崩潰。

這裏有點用不相關的位碼的切出:

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)); 
+3

發佈[最小,完整且可驗證的示例](https://stackoverflow.com/help/mcve) – BDL

+0

@BDL完成。這很難,因爲代碼量很大,我不確定可能導致錯誤的原因。如果這是相關的,我會得到一個GL_VALIDATE_STATUS爲假但沒有信息日誌。但GL_LINK_STATUS返回true。 –

+0

您應該使用傳遞給'wglMakecurrent'的HDC調用'SwapBuffers'。 –

回答

0

我找到了答案。 SwapBuffer(hDC)命令只是發生錯誤的地方,但沒有任何關係。我相信我的錯誤是由於與我的指數有關的事情,就好像我只在模型中繪製第一個網格一樣,一切都按預期工作。 Nvidia與這個錯誤墜毀,英特爾繼續並忽視它。

儘管如此,感謝Chris Becke指出使用GetDC(hwnd)將來的內存泄漏。