开发者

C++ Segmentation Fault Only External to Eclipse

I have developed a C++ application in Eclipse. When run outside of Eclipse, it takes a segmentation fault after a consistent number (4) of user actions. It did not seem like anything special at first. I thought I would just use Eclipse to debug through the application and find the bug. However, when I run the application from Eclipse, it runs just fine. Does anyone have recommendations on how to troubleshoot this problem??

Thanks.

The codebase is too large to display here, but I've narrowed down the line of code which causes the segmentation fault:

SDL_Surface* textSurface = TTF_RenderText_Solid( font, text.c_str(), color );

The odd part about this is it calls this line of code hundreds of times before failing on the exact same call. The values of font and color are constants defined elsewhere and passed in each time. So they are the exact same every time. The value of tex开发者_如何转开发t is "-".


First make sure you run the same version within eclipse as on the commandline release vs debug.

Some bugs will change because of different compiler settings or just being debugged. These are often caused by uninitialized data. Memory debugger tools like valgrind can you help find these kind of problems as they can randomize the contents of uninitialized data.

Also make sure all warnings are on in your compile settings. The compiler will then warn you about potentialy incorrect stuff.

Edit: Yes -Wall and -pedantic is fine for getting all warnings.

Sometimes with hard to find memory errors the error is not actually where the segfault occurs. The segfault only occurs because of earlier errors that went unnoticed. Best to use a memory debugger like valgrind. Otherwise you will have to scrutinize a lot of code.


At the recommendation of Node (see comments on original question, I ran my app through Valgrind. After cleaning up memory management issues identified by Valgrind, my problem is gone. Thank you!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜