Skip to content
Snippets Groups Projects
Commit 1b91a502 authored by Frederik Keens's avatar Frederik Keens
Browse files

Fix undefined behaviour by calling SDL_INITs at the start of main

parent ee0640cc
Branches
No related tags found
1 merge request!5Spritesheet
......@@ -12,18 +12,6 @@ namespace advanced_wars {
Engine::Engine(Window &window) : window(window), quit(false) {
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
throw std::runtime_error("SDL could not initialize: " +
std::string(SDL_GetError()));
}
int imgFlags = IMG_INIT_PNG;
if (!(IMG_Init(imgFlags) & imgFlags)) {
throw std::runtime_error(
"SDL_image could not initialize! SDL_image Error: " +
std::string(IMG_GetError()));
}
this->sdl_renderer =
SDL_CreateRenderer(this->window.sdl_window(), -1,
SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
......
......@@ -8,11 +8,25 @@
#include "window.hpp"
#include <cstddef>
#include <vector>
#include <SDL2/SDL.h>
#include <SDL_image.h>
using namespace advanced_wars;
int main() {
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
throw std::runtime_error("SDL could not initialize: " +
std::string(SDL_GetError()));
}
int imgFlags = IMG_INIT_PNG;
if (!(IMG_Init(imgFlags) & imgFlags)) {
throw std::runtime_error(
"SDL_image could not initialize! SDL_image Error: " +
std::string(IMG_GetError()));
}
Window window("Advanced Wars", 960, 960);
Engine engine(window);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment