Make SDL more reliable

This commit is contained in:
Iwan Timmer
2015-08-10 10:18:33 +02:00
parent abc9a19a9d
commit 05fc925c19
5 changed files with 44 additions and 36 deletions

View File

@@ -44,9 +44,19 @@ static void sdl_setup(int width, int height, int redrawRate, void* context, int
fprintf(stderr, "Not enough memory\n");
exit(1);
}
screen_width = width;
screen_height = height;
SDL_Window *window = (SDL_Window*) context;
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
if (!renderer) {
fprintf(stderr, "SDL: could not create renderer - exiting\n");
exit(1);
}
bmp = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_YV12, SDL_TEXTUREACCESS_TARGET, width, height);
if (!bmp) {
fprintf(stderr, "SDL: could not create texture - exiting\n");
exit(1);
}
}
static void sdl_cleanup() {
@@ -54,31 +64,6 @@ static void sdl_cleanup() {
}
static int sdl_submit_decode_unit(PDECODE_UNIT decodeUnit) {
if (window == NULL) {
if(SDL_Init(SDL_INIT_VIDEO)) {
fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError());
exit(1);
}
window = SDL_CreateWindow("Moonlight", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, screen_width, screen_height, 0);
if(!window) {
fprintf(stderr, "SDL: could not create window - exiting\n");
exit(1);
}
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_TARGETTEXTURE);
if (!renderer) {
fprintf(stderr, "SDL: could not create renderer - exiting\n");
exit(1);
}
bmp = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_YV12, SDL_TEXTUREACCESS_TARGET, screen_width, screen_height);
if (!bmp) {
fprintf(stderr, "SDL: could not create texture - exiting\n");
exit(1);
}
}
if (decodeUnit->fullLength < DECODER_BUFFER_SIZE) {
PLENTRY entry = decodeUnit->bufferList;
int length = 0;