繁体   English   中英

GLut.h / osfinfo.c / dbgheap.c / mlock.c中0x76fe15de的未处理异常

[英]Unhandled exception at 0x76fe15de in GLut.h/ osfinfo.c/ dbgheap.c/ mlock.c

在HP Pavilion g6上将Windows 7 Home Premium 64bit与Visual Studio 2010 Professional一起使用。 代码是用C / C ++编写的。

链接:

Additional Include Directories: N/A - Everything needed is in the VS2010 Include Directory
Additional Library Directories: N/A - Everything needed is in the VS2010 Lib Directory
Additional Dependencies (Debug Mode): glew32d.lib;glew32sd.lib;glu32.lib;opengl32.lib;gdi32.lib;winmm.lib;user32.lib;

码:

    #include "stdafx.h"
    #include <stdio.h>
    #include <GL\glew.h>
    #include <GL\wglew.h> 
    #include <GL\glut1.h>
    #include <GL\glext.h>

    using namespace std;

    int main(int argc, char** argv)
    {
        glutInit(&argc, argv);

        const unsigned char * version ;
        version = (const unsigned char *)glGetString(GL_VERSION);
        printf ("My OpenGL version is %s\n", version); //Comment this out for error in Glut, leave for the other 2 errors

        // Obtain a buffer identifier from OpenGL
        GLuint bufferID = 0;
        glGenBuffers( 1, &bufferID ); //Comment out for no reported errors

        return 0;
    }

报告的错误:

glut.h:
First-chance exception at 0x00000000 in gl_crap3.exe: 0xC0000005: Access violation.
Unhandled exception at 0x76fe15de in gl_crap3.exe: 0xC0000005: Access violation.
Error occurs on line 486 - static void APIENTRY glutInit_ATEXIT_HACK(int *argcp, char **argv) { __glutInitWithExit(argcp, argv, exit); }

osfinfo.c:
First-chance exception at 0x00000000 in gl_crap3.exe: 0xC0000005: Access violation.
Unhandled exception at 0x76fe15de in gl_crap3.exe: 0xC0000005: Access violation.
Error occurs on line 467 - return retval; // in function, int __cdecl __lock_fhandle (int fh)

dbgheap.c:
First-chance exception at 0x00000000 in gl_crap3.exe: 0xC0000005: Access violation.
Unhandled exception at 0x76fe15de in gl_crap3.exe: 0xC0000005: Access violation.
Error occurs on line 504 - __finally {_munlock(_HEAP_LOCK);}

mlock.c:
First-chance exception at 0x00000000 in gl_crap3.exe: 0xC0000005: Access violation.
Unhandled exception at 0x76fe15de in gl_crap3.exe: 0xC0000005: Access violation.
Error occurs on line 375 - } // end of function, void __cdecl _unlock (int locknum)

其他值得注意的症状:

  • osfinfo.c,dbgheap.c和mlock.c之间交替崩溃时printf命令没有被注释掉
  • 当printf IS被注释掉时,仅在glut.h上崩溃
  • 注释掉glGenBuffers时,没有未处理的异常错误-程序不会崩溃
  • printf语句的输出为:我的OpenGL版本为(null)-发生,与程序是否崩溃无关

我完全迷住了这一点,互联网上似乎没有任何东西可以帮助我。 我什至专注于首先尝试解决“ OpenGL version = null”问题,但是由于我要么错误地遵循了该网站上的建议(对OpenGL渲染上下文没有足够的了解),要么我空手而归。 0xC0000005错误的症状。


编辑:由于此问题似乎是由多个问题引起的,因此我决定放置代码的更新版本以及从中获取的相应错误。 到目前为止,感谢您对我的帮助,但是glGenBuffers似乎对我或其他事物怀恨在心。

新代码:

    #include "stdafx.h"
    #include <cmath>
    #include <math.h>
    #include <iostream>
    #include <GL\glew.h>
    #include <GL\glut.h>
    #include <GL\glext.h>
    #include <GL\wglew.h>
    #include <GL\wglext.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <stdarg.h>

    using namespace std;
    void drawScene();
    void handleKeypress(unsigned char key, int x, int y);
    void handleMouse(int button, int state, int x, int y);
    void handleResize(int w, int h);
    void update(int value);
    void printw (float x, float y, float z, char* format, ...);

    GLvoid *font_style = GLUT_BITMAP_TIMES_ROMAN_24;

    int main(int argc, char** argv)
    {
        glutInit(&argc, argv);
        glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); 
        glutInitWindowSize(960, 460);
        glutCreateWindow("Piece of Shit");
        glEnable(GL_DEPTH_TEST);
        glutDisplayFunc(drawScene);
        glutKeyboardFunc(handleKeypress);
        glutMouseFunc(handleMouse);
        glutReshapeFunc(handleResize);
        glutTimerFunc(25, update, 0);
        glutMainLoop();
        return 0;
    }

    void drawScene()
    {
        double x, z;
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        glClearColor(0.0,0.0,0.0,0.0);
        glShadeModel(GL_FLAT);
        GLuint bufferID[1];

        GLenum err = glewInit();
        if (GLEW_OK != err)
            printw(-6, 1.5, -10, "Fail: %s\n", glewGetErrorString(err));
        printw(-3, 0.3, -10, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));
        glGenBuffers( 1, &bufferID[0] ); // comment out and you have no problems********************************
        glutSwapBuffers();
    }

    void handleKeypress(unsigned char key, int x, int y)
    {
    }

    void handleMouse(int button, int state, int x, int y)
    {
    }

    void handleResize(int w, int h)
    {   
        glViewport(0,0,w,h);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(45.0, (double)w / (double)h, 1.0, 200.0);
    }

    void update(int value)
    {
        glutPostRedisplay();
        glutTimerFunc(20, update, 0);
    }

    void printw (float x, float y, float z, char* format, ...)
    {
        va_list args;   //  Variable argument list
        int len;        // String length
        int i;          //  Iterator
        char* text;     // Text

        //  Initialize a variable argument list
        va_start(args, format);

        //  Return the number of characters in the string referenced the list of arguments.
        // _vscprintf doesn't count terminating '\0' (that's why +1)
        len = _vscprintf(format, args) + 1;

        //  Allocate memory for a string of the specified size
        text = (char*) malloc (len * sizeof(char));

        //  Write formatted output using a pointer to the list of arguments
        vsprintf_s(text, len, format, args);

        //  End using variable argument list
        va_end(args);

        //  Specify the raster position for pixel operations.
        glRasterPos3f (x, y, z);

        //  Draw the characters one by one
        for (i = 0; text[i] != '\0'; i++)
        glutBitmapCharacter(font_style, text[i]);

        //  Free the allocated memory for the string
        free(text);
    }

错误:gl_crap3.obj:错误LNK2001:未解析的外部符号___glewGenBuffers

您的问题可能是未定义glGenBuffers。 我注意到您正在尝试使用GLEW解决此问题。 如您所料,您需要做更多的工作来设置GLEW。 您需要调用glewInit。 我的代码看起来像(为清楚起见简化):

GLenum err = glewInit();
if (err != GLEW_OK) {
    string error = "GLEW extension loading failed: "+string((char*)glewGetErrorString(err));
    printf("%s\n",error); getchar();
}

在设置上下文后(即在glutInit之后)添加该代码。 我不知道您的OpenGL版本是否为NULL(我上次遇到的是在相当旧的卡上),可能是集成芯片组。 如果是您的情况,则可能无需担心。

谢谢大家的帮助。 经过一周以上的研究,我相信问题可能出在Visual Studio 2010编译器本身09/08/2012上

我将尝试Linux以解决我的问题。

暂无
暂无

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

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