简体   繁体   English

SDL 1.2-> SDL 2.0(崩溃程序)

[英]SDL 1.2 -> SDL 2.0 (crashing program)

So I used the SDL 2.0 migration guide, and finally made the code compile without errors... but now it crashes, this is the first time I had a program crash, and there is no compiler to guide me. 因此,我使用了SDL 2.0迁移指南,最终使代码编译时没有错误……但是现在它崩溃了,这是我第一次程序崩溃,并且没有编译器可以指导我。 I am using LazyFoo's 29th sdl tutorial, to see if I can migrate it. 我正在使用LazyFoo的第29个sdl教程,以查看是否可以迁移它。 I honestly think I made an abomination of a program, and I'm tossing it to you guys because I'm clueless. 老实说,我认为我很讨厌某个程序,因为我一无所知,所以我把它扔给了你们。 Here is my progress: http://www.pastebucket.com/21174 这是我的进度: http : //www.pastebucket.com/21174

You appear to have a couple of issues. 您似乎有几个问题。

First of all you are not loading any of the images in the load_images() function so whenever you call anything on them ie rendering they will be NULL pointers. 首先,您不会在load_images()函数中加载任何图像,因此无论何时调用它们,即渲染它们都将是NULL指针。

Next is your init() function. 接下来是您的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: %s\n", SDL_GetError());
      SDL_DestroyWindow(window);
    }
  }
  else {
    printf("Could not create window: %s\n", SDL_GetError());
    return false;
  }
}

Give that a try for now and see how you get on. 现在尝试一下,看看您的情况如何。 I recommend you look to use an IDE to help you out as these were all very simple errors that would be picked up straight away normally. 我建议您使用IDE来帮助您,因为这些都是非常简单的错误,通常会立即被发现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM