指针错误调试帮助
我是 C++ 新手,我正在尝试使用 freeglut 和 Visual Studio 2010 来编写 Pong 的副本。我的代码运行良好,直到我对其进行了一些修改以使其更加面向对象。当我再次运行它时,它工作了几次,直到我做了一些小的编辑(说实话,我不记得我改变了什么,因为我第二天早上才构建了我的代码),然后我收到了这个我运行程序后立即出现运行时错误:
Pong.exe 中 0x1000bbae 处出现未处理的异常:0xC0000005:访问冲突写入位置 0x000000a8。
我不是特别擅长调试,但我相信这是在我的主循环中的 glutDisplayFunc() 行出现的。我认为这与空指针有关,但我不知道是什么。有人可以帮我找到我的问题吗?
以下是我的程序的适用部分(Main.cpp):
include "header.h"
using namespace std;
int main(int argc, char** argv) {
//Initialize GLUT
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(WIDTH, HEIGHT); //Set the window size
//Create the window
//modesetup(2);
//Set handler functions for drawing, keypresses, and window resizes
glutDisplayFunc(mainDraw);
glutKeyboardFunc(handleKeypress);
glutKeyboardUpFunc(handleKeyup);
glutSpecialFunc(handleSpecial);
glutSpecialUpFunc(handleSpecialUp);
glutReshapeFunc(handleResize);
glutTimerFunc(25, update, 0);
glutMainLoop(); //Start the main loop. glutMainLoop doesn't return.
return 0; //This line is never reached
}
提前致谢!
编辑:我刚刚制作了一个新程序,它对所有内容都使用非常标准的函数,但我仍然收到此错误。我开始认为我的 freeglut 安装可能有问题。
I am new to C++, and I am trying to program a replica of Pong using freeglut with Visual Studio 2010. My code was working fine until I made some revisions to it in order to make it more object oriented. When I ran it again, it worked a couple times, until I made some minor edit (to be honest, I can't remember what it was that I changed, since I only built my code the next morning), and I received this runtime error as soon as I ran the program:
Unhandled exception at 0x1000bbae in Pong.exe: 0xC0000005: Access violation writing location 0x000000a8.
I'm not particularly good at debugging, but I believe this is coming at the line glutDisplayFunc() in my main loop. I think this has something to do with null pointers, but I have no idea what. Could somebody help me find my problem?
Below is the applicable portion of my program (Main.cpp):
include "header.h"
using namespace std;
int main(int argc, char** argv) {
//Initialize GLUT
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(WIDTH, HEIGHT); //Set the window size
//Create the window
//modesetup(2);
//Set handler functions for drawing, keypresses, and window resizes
glutDisplayFunc(mainDraw);
glutKeyboardFunc(handleKeypress);
glutKeyboardUpFunc(handleKeyup);
glutSpecialFunc(handleSpecial);
glutSpecialUpFunc(handleSpecialUp);
glutReshapeFunc(handleResize);
glutTimerFunc(25, update, 0);
glutMainLoop(); //Start the main loop. glutMainLoop doesn't return.
return 0; //This line is never reached
}
Thanks in advance!
EDIT: I just made a new program that uses very standard functions for everything, but I still get this error. I'm beginning to think that there may be something wrong with my freeglut installation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用F5在Visual Studio中运行程序并进行调试。当您收到错误时,调试器应该将您置于非法访问的行上。如果没有该位置的源代码,则检查调用堆栈。
干杯&嗯。
Use F5 to run the program with debugging in visual studio. When you get the error the debugger should place you right on the line with the illegal access. If it doesn't have source code for the location then check up the call stack.
Cheers & hth.
在 valgrind 下运行您的程序。它将为您提供有关问题的更多信息,甚至可能指出除崩溃的直接原因之外的内存错误。
Run your program under valgrind. It will give you a lot more information about the problem, and might even point out memory errors other than the immediate cause of the crash.
您可能已经解决了问题。但由于我遇到了同样的问题,并且在任何地方都找不到答案,我将回答这个问题:
编写该
您只是忘记在该部分之前
函数。
这会导致您得到异常。
You probably already solved the problem. But since I had the same problem and couldn t find an answer two it anywhere I will answer the question:
You simply forgot to write the
function before the
part.
This leads to the exception you get.