Jesse O
Jesse O

Reputation: 65

SDL window doesn't come up in Eclipse

#include <iostream>
#include <SDL.h>
using namespace std;

int main(int argc, char* argv[]){

    const int SCREEN_WIDTH = 800;
    const int SCREEN_HEIGHT = 600;
    if(SDL_Init(SDL_INIT_VIDEO) < 0){
        cout << "SDL init failed." << endl;
        return 1;
    }

    SDL_Window *window = SDL_CreateWindow("Particle Fire Explosion",
            SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);

    if(window == NULL){
        SDL_Quit();
        return 2;
    }

    SDL_Renderer * renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC);
    SDL_Texture *texture = SDL_CreateTexture(renderer,SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STATIC, SCREEN_WIDTH, SCREEN_HEIGHT);

    if (renderer == NULL){
        cout << "Could not create renderer" << endl;
        SDL_DestroyWindow(window);
        SDL_Quit();
        return 3;
    }

    if(texture == NULL){
        cout << "Could not create texture" << endl;
        SDL_DestroyRenderer(renderer);
        SDL_DestroyWindow(window);
        SDL_Quit();
        return 4;
    }

    Uint32 *buffer = new Uint32[SCREEN_WIDTH*SCREEN_HEIGHT];

    SDL_UpdateTexture(texture, NULL, buffer, SCREEN_WIDTH*sizeof(Uint32));
    SDL_RenderClear(renderer);
    SDL_RenderCopy(renderer, texture, NULL, NULL);
    SDL_RenderPresent(renderer);

    bool quit = false;

    SDL_Event event;

    while(!quit){
        //Update particles
        // Draw particles
        // Check for messages/events

        while(SDL_PollEvent(&event)){
            if(event.type == SDL_QUIT){
                quit = true;
            }
        }
    }

    delete [] buffer;
    SDL_DestroyRenderer(renderer);
    SDL_DestroyTexture(texture);
    SDL_DestroyWindow(window);
    SDL_Quit();

    return 0;
}

The code compiles but I keep getting an exit value of -1,073,741,515 instead of an exit value of 0. And the SDL window doesn't show up. Could it be my IDE or something is wrong with my code?

The console outputs >terminated< (exit value -1,073,741,515).

Upvotes: 1

Views: 165

Answers (1)

MSi
MSi

Reputation: 26

I had the same Problem! I copied the SDL2.dll from the ...\SDL2-2.0.5\i686-w64-mingw32\bin Directory in my workspace. It works fine.

Upvotes: 1

Related Questions