OpenGL窗口立即关闭,并显示错误-1073740777(0xc0000417)

问题描述:

我正在使用Visual Studio 2013和OpenGL创建一个模拟。 理想情况下,我创建的窗口应保持打开状态,以便可以使用键进行更改,并且可以在同一窗口中查看不同的结果。 但窗口是错误代码启动后立即关闭OpenGL窗口立即关闭,并显示错误-1073740777(0xc0000417)

的Program.exe”已退出,代码为-1073740777(0xc0000417)

我做了一些调试和试评论各种线,看到如果我将'glutSwapBuffers()'作为注释,窗口保持打开状态但是为空。

有人可以摆脱这一点吗?

void keyboard (unsigned char key, int x, int y) 
{ 
switch (key) 
{ 
    case 'r': case 'R': 
    if (filling==0) 
    { 
     glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); 
     filling=1; 
    } 
    else 
    { 
     glPolygonMode (GL_FRONT_AND_BACK, GL_POINT); 
     filling=0; 
    } 
    break; 
    case 27: 
    exit(0); 
    break; 
} 
} 

void display(void) 
{ 
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
glMatrixMode(GL_MODELVIEW); 
glLoadIdentity(); 
glRotatef(-90,0.0,1.0,0.0); 
glRotatef(-90,1.0,0.0,0.0); 

rotation_x = rotation_x + (rotation_x_increment - rotation_x)/50; 
rotation_y = rotation_y + (rotation_y_increment - rotation_y)/50; 
rotation_z = rotation_z + rotation_z_increment; 

if (rotation_x > 359) rotation_x = 0; 
if (rotation_y > 359) rotation_y = 0; 
if (rotation_z > 359) rotation_z = 0; 

if(rotation_x_increment > 359) rotation_x_increment = 0; 
if(rotation_y_increment > 359) rotation_y_increment = 0; 
if(rotation_z_increment > 359) rotation_z_increment = 0; 

glRotatef(rotation_x,1.0,0.0,0.0); 
glRotatef(rotation_y,0.0,1.0,0.0); 
glRotatef(rotation_z,0.0,0.0,1.0); 

glTranslatef(x_translate,0.0,0.0); 
glTranslatef(0.0,y_translate,0.0); 
glTranslatef(0,0,z_translate); 

glFlush(); // This force the execution of OpenGL commands 
glutSwapBuffers(); 
glFinish(); 
} 

int main(int argc, char **argv) 
{ 
IntroDisplay(); 
glutInit(&argc, argv); 
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); 
glutInitWindowSize(screen_width,screen_height); 
glutInitWindowPosition(0,0); 
glutCreateWindow("Ultrasonic Testing"); 
glutDisplayFunc(display); 
glutIdleFunc(display); 
glutReshapeFunc (resize); 
glutKeyboardFunc (keyboard); 
glutSpecialFunc (keyboard_s); 
glutMouseFunc(mouse); 
glutMotionFunc(mouseMove); 
init(); 
glutMainLoop(); 
return 0; 
} 
+0

STATUS_INVALID_CRUNTIME_PARAMETER - 可能是混合的crts或类似的东西,重建所有来源 – paulm

+0

@paulm尝试重建。尝试清洁和重建。仍然没有变化。 它可能是与Windows或glut32.dll相关的东西?因为我一段时间没有更改代码,并且突然开始这样做。 –

+0

包括过剩? – paulm

问题与我的司机有关。它在我重新安装了所有东西后正常工作。

我认为这是因为交换功能还取决于系统而不仅仅是图书馆。我在某处读过。

你尝试编译和运行的绝对最小的,裸露的骨头程序,什么也不做,除了创建与GLUT窗口,登记显示功能,只是清除和切换缓冲区,就是这样。即这

#include <GL/glut.h> 
static void display(void) 
{ 
    glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); 
    glutSwapBuffers(); 
} 
int main(int argc, char *argv[]) 
{ 
    glutInit(&argc, argv); 
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); 
    glutCreateWindow("test"); 
    glutDisplayFunc(display); 
    glutIdleFunc(glutPostRedisplay); 
    glutMainLoop(); 
    return 0; 
} 

我在你的故障原因的猜测是,您使用的是一些库是在不同的编译器比您正在使用,并在运行时预期的差异导致一些hickups为你修造了。如果上面给出的最小程序崩溃,那么这是最可能的原因。

请注意,在您的代码中,对glFinishglFlush的调用是多余的,因为冲洗和完成是由缓冲区交换隐含的。另外,将显示功能注册为GLUT闲置处理程序通常不是一个好主意;如果您需要连续显示更新,请注册glutPostRedisplay。

+0

我试过最简单的程序,它也崩溃了。你建议我如何解决运行时错误? –

+0

@RahulK:既然你提到glutSwapBuffers被调用时出现问题,你的GLUT的特定版本似乎是罪魁祸首。你最好采取的行动是为FreeGLUT提供源代码(http://prdownloads.sourceforge.net/freeglut/freeglut-3.0.0.tar.gz?download),并用你自己的编译器自己构建它。实际上,将FreeGLUT放入您的项目并将其作为解决方案添加到您的VisualStudio项目中会很有意义,因此它将与您的主程序一起构建。 – datenwolf

+0

我弄明白了。我重新安装了整个Visual Studio和所有更新。仍然不确定究竟是什么问题。非常感谢您的帮助。 :) –