简体   繁体   English

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

[英]OpenGL window immediately closes with error -1073740777 (0xc0000417)

I'm using Visual Studio 2013 and OpenGL to create a simulation. 我正在使用Visual Studio 2013和OpenGL创建模拟。 Ideally, the window that I'm creating should stay open so that I can make changes using the keys and I can view a different result on the same window. 理想情况下,我正在创建的窗口应保持打开状态,以便可以使用键进行更改,并且可以在同一窗口上查看不同的结果。 But the window closes immediately after it launches with error code 但是窗口启动后会立即关闭并显示错误代码

program.exe' has exited with code -1073740777 (0xc0000417) program.exe'已退出,代码为-1073740777(0xc0000417)

I did some debugging and tried commenting on various lines and saw that if I made 'glutSwapBuffers()' as a comment, the window stays open but empty. 我进行了一些调试,并尝试在不同的行上进行注释,然后看到如果我将“ glutSwapBuffers()”作为注释,则该窗口保持打开状态但为空。

Can someone please shed any light on this? 有人可以对此进行说明吗?

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;
}

Did you try compiling and running an absolutely minimal, bare bones program that does nothing except creating a window with GLUT, registering a display function that just clears and swaps the buffers and that's it. 您是否尝试过编译并运行一个绝对最小的裸机程序,除了使用GLUT创建一个窗口,注册一个仅清除和交换缓冲区的显示函数,它什么也没做。 Ie this 即这个

#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;
}

My guess at the cause of your troubles is, that some library you're using was built with a different compiler than the one you're using and differences in the expected runtimes cause some hickups for you. 我对造成麻烦的原因的猜测是,您使用的某些库是使用与您使用的库不同的编译器构建的,并且预期运行时中的差异会为您带来一些麻烦。 If the minimal program given above crashes, then this is the most likely cause. 如果以上给出的最小程序崩溃,则这是最可能的原因。

Note that in your code the calls to glFinish and glFlush are superfluous, because flushing and finishing is implied by a buffer swap. 请注意,在您的代码中对glFinishglFlush的调用是多余的,因为缓冲区交换隐含了刷新和精加工。 Also it's usually not a good idea to register the display function as GLUT idle handler; 同样,将显示功能注册为GLUT空闲处理程序通常也不是一个好主意。 register glutPostRedisplay instead if you need a continuous display update. 如果需要连续显示更新,请注册glutPostRedisplay。

The problem was something to do with my drivers. 问题出在我的司机身上。 It worked fine after I reinstalled everything. 重新安装所有组件后,它运行良好。

I think it's because swap function also depends on the system and not the just the library. 我认为这是因为交换功能还取决于系统,而不仅仅是库。 I read that somewhere. 我在某处阅读过。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM