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 <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)
その他の注目された症状:
- printf コマンドがコメントアウトされていない場合、osfinfo.c、dbgheap.c、および mlock.c が交互にクラッシュする
- printf ISがコメントアウトされている場合にのみ、glut.h でクラッシュします。
- glGenBuffers がコメント アウトされている場合、未処理の例外エラーは発生しません。プログラムはクラッシュしません。
- printf ステートメントの出力は次のとおりです。 My OpenGL version is (null) - プログラムがクラッシュするかどうかに関係なく発生します
私はこれに完全に困惑しています。インターネット上には、私を助けるものは文字通り何もないようです。最初に「OpenGL version = null」の問題を解決することに集中しましたが、この Web サイトのアドバイスに間違って従った (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: 未解決の外部シンボル ___gewGenBuffers