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上使用带有Visual Studio 2010 Professional的Windows 7 Home Premium 64位。代码是用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 <GLglew.h>
#include <GLwglew.h>
#include <GLglut1.h>
#include <GLglext.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 %sn", 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)
其他注意到的症状:
- 当printf命令未被注释掉时,osfinfo.c、dbgheap.c和mlock.c之间交替发生崩溃
- 只有当printfIS被注释掉时,glut.h才会崩溃
- 当glGenBuffers被注释掉时,没有未处理的异常错误-程序不会崩溃
- printf语句的输出为:我的OpenGL版本为(null)-无论程序是否崩溃都会发生
我完全被这件事难住了,互联网上似乎没有任何东西可以帮助我。我甚至专注于首先解决"OpenGL version=null"问题,但我两手空空,因为我要么错误地遵循了这个网站上的建议(对OpenGL渲染上下文没有足够的了解),要么这个问题是0xC0000005错误的症状。
编辑:由于这个问题似乎是由多个问题引起的,我决定更新我的代码版本,并从中得到相应的错误。感谢您迄今为止对我的帮助,但glGenBuffers似乎对我怀恨在心。
新代码:
#include "stdafx.h"
#include <cmath>
#include <math.h>
#include <iostream>
#include <GLglew.h>
#include <GLglut.h>
#include <GLglext.h>
#include <GLwglew.h>
#include <GLwglext.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: %sn", glewGetErrorString(err));
printw(-3, 0.3, -10, "Status: Using GLEW %sn", 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 ' ' (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] != ' '; 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("%sn",error); getchar();
}
在设置上下文之后(即,在glutInit之后)添加该代码。我不知道你的OpenGL版本是NULL——我最后一次遇到它是在一个相当旧的卡上——可能是一个集成芯片组。如果你是这样的话,也许没什么好担心的。
感谢大家的帮助。经过一个多星期的讨论,我认为问题可能出在Visual Studio 2010编译器本身2012年8月9日。
我将尝试Linux来解决我的问题。
相关文章:
- 如何修复链表类实现的未处理异常0xDDDDDDDD
- VisualC++ 2010 有没有办法找出有关未处理异常错误的更多详细信息
- C++ 程序中双链表的未处理异常
- 运算符重载时未处理<<异常
- 实验室中0x6BE20E11 (ucrtbased.dll) 的未处理异常.exe: 0xC0000005:访问冲突读取
- ImageMagick 的未处理异常
- 类数组大小为的未处理异常
- 尝试将构造函数设置为 0 - c++ 的未处理异常
- Dijkstra 中0x001e1078 s_Algorithm.exe的未处理异常:0xC0000005:访问冲突读取位置0xbaadf00d
- 运算符重载未处理异常
- 尝试使用 fread 读取文本文件时发生 'System.AccessViolationException' 类型的未处理异常
- c++中的Guard,在main中未处理异常时不调用析构函数
- 某些内存位置的未处理异常
- 错误 linkedlist .exe 中0x00D0345E处的未处理异常: 0xC0000005:访问违规写入位置0x
- 仅在发布模式下使用 glGenBuffer 的未处理异常 - QT
- 如何分析VS2010在调试模式下捕获的未处理异常
- glDrawArrays上的openGL未处理异常(GL_TRIANGLES,0,model.indicesCount)
- 使用Boost Spirit解析语法的未处理异常
- 解析"%Z" C++ 中将错误作为访问 voilation 的未处理异常给出?
- 为什么在win32计时器回调中引发的未处理异常未被调试器视为未处理异常