SDL 1.2 -> SDL 2.0(崩溃程序)
SDL 1.2 -> SDL 2.0 (crashing program)
所以我使用了 SDL 2.0 迁移指南,最终使代码编译无误...但是现在它崩溃了,这是我第一次遇到程序崩溃,没有编译器来指导我。我正在使用 LazyFoo 的第 29 个 sdl 教程,看看我是否可以迁移它。老实说,我认为我制作了一个可憎的程序,我把它扔给你们,因为我一无所知。这是我的进步:http://www.pastebucket.com/21174
您似乎有几个问题。
首先,您没有在load_images()
函数中加载任何图像,因此每当您对它们调用任何内容(即渲染)时,它们都将是 NULL 指针。
接下来是您的init()
函数。
bool init()
{
SDL_Init; // <---- REMOVE THIS LINE
//Initialize all SDL subsystems
if( SDL_Init( SDL_INIT_EVERYTHING) == -1 )
{
return false;
}
SDL_Window *sdlWindow; // <----- REMOVE THIS VARIABLE
SDL_Window *window;
SDL_Texture *sdlRenderer; // <----- REMOVE THIS VARIABLE
// Create an application window with the following settings:
// NO NEED FOR SDL_WINDOW_OPENGL replace with SDL_WINDOW_SHOWN
window = SDL_CreateWindow(
"Why is this even alive?", // window title
SDL_WINDOWPOS_UNDEFINED, // initial x position
SDL_WINDOWPOS_UNDEFINED, // initial y position
640, // width, in pixels
480, // height, in pixels
SDL_WINDOW_SHOWN // flags - see below
);
// sdlWindow should be just window and you should do a NULL check before creating the render
if (window != NULL) {
SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, 0);
if (renderer == NULL) {
printf("Could not create renderer: %sn", SDL_GetError());
SDL_DestroyWindow(window);
}
}
else {
printf("Could not create window: %sn", SDL_GetError());
return false;
}
}
现在试一试,看看你过得怎么样。我建议您使用 IDE 来帮助您,因为这些都是非常简单的错误,通常会立即拾取。
相关文章:
- 当回溯以零开始时,如何调试崩溃
- 在VS代码中交叉编译Windows与Linux上的MinGW的SDL程序
- 内联映射初始化的动态atexit析构函数崩溃
- 执行函数时导致崩溃的变量
- Mix_Init和Mix_OpenAudio SDL之间的区别是什么
- 程序崩溃并显示"std::out_of_range"错误
- SDL 窗口不会弹出
- CoInitialize()在单独的线程上崩溃而不返回
- 使用调试/崩溃报告将应用程序部署到客户端
- 为什么所有C++编译器都会崩溃或挂起此代码
- 为什么lambda在clang上崩溃而不是在gcc上崩溃
- 为什么我的多线程作业队列崩溃
- ExtractIconEx:可以工作,但偶尔会崩溃
- 为什么引用传递会导致此崩溃(C++)
- 试图创建流或fopen时程序崩溃
- 带有OpenGL(freeglut)的SDL在调用glutBitmapCharacter时崩溃
- SDL 1.2 -> SDL 2.0(崩溃程序)
- SDL C++程序在大约12秒后持续崩溃
- SDL OpenGL应用程序在发布模式下崩溃
- SDL程序在关闭时崩溃-c0000005