簡體   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