C++ SDL 分段错误

2022-01-12 00:00:00 opengl debugging sdl segmentation-fault c++

我让我的游戏正常运行,然后决定尝试使用以下教程来实现一个菜单.

I had my game working and then decided to try and implement a menu using the following tutorial.

我没有使用教程来创建他之前创建的教程中的游戏.

I did not use the tutorial to create the game that was in prior tutorials that he created.

每当我编译并运行程序时,它会短暂加载,然后关闭并在 code::blocks.

Whenever I compile and run the program it loads briefly, then closes and says Process terminated with status 3 (0 minutes, 1 seconds) in the build log of code::blocks.

更新:我已将 pastebin 链接的代码更新为我现在所拥有的,我现在从调试器得到的错误是

UPDATE: I have updated the code for the pastebin link to what I have now, the error I am now getting from the debugger is

Program received signal SIGSEGV, Segmentation fault.
In TTF_SizeUNICODE () (E:gameponginDebugSDL_ttf.dll)
At E:gamepongmain.cpp:27

更新 2:似乎我很尴尬地没有安装字体.我已经安装了字体 &现在调试器到达屏幕显示开始"和退出"字体的位置,但是,在执行此操作后程序立即冻结,调试器中没有错误,如果我正常运行程序,它只是在显示文本后停止响应,奇怪.刚从code::blocks启动程序后强行关闭窗口后发现,返回:Process terminate with status -805306369 (0 minutes,13 seconds).

UPDATE 2: Seems that I embarrasingly didn't have the font installed. I've installed the font & now the debugger gets to a point where the screen displays with the font of "Start" and "Exit", however, immediately after doing this the program freezes, no error's what so ever in the debuggger, and if I run the program normally, it just stops responding after the text is displayed, strange. Just realised after forcefully closing the window after launching the program from code::blocks, it returns this: Process terminated with status -805306369 (0 minutes, 13 seconds).

更新 3:已解决.

推荐答案

在将 screen (第 220 行)传递给 showMenu (第 224 行).AFAIK SDL_SetVideoMode 返回可用于 screen 的表面.

You're not initializing screen (line 220) before you're passing it to showMenu (line 224). AFAIK SDL_SetVideoMode returns a surface you could use for your screen.

相关文章