Skip to content

Commit

Permalink
Improved error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
complexlogic committed Feb 5, 2022
1 parent 8707680 commit a6e8643
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
23 changes: 12 additions & 11 deletions src/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,18 @@ SDL_Texture *load_texture_from_file(const char *path)
{
SDL_Surface *surface = NULL;
SDL_Texture *texture = NULL;

surface = IMG_Load(path);
if (surface == NULL) {
output_log(LOGLEVEL_ERROR,
"Error: Could not load image %s\n%s\n",
path,
IMG_GetError()
);
}
else {
texture = load_texture(surface);
if (path != NULL) {
surface = IMG_Load(path);
if (surface == NULL) {
output_log(LOGLEVEL_ERROR,
"Error: Could not load image %s\n%s\n",
path,
IMG_GetError()
);
}
else {
texture = load_texture(surface);
}
}
return texture;
}
Expand Down
9 changes: 7 additions & 2 deletions src/launcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,12 @@ int main(int argc, char *argv[])

// Render background
if (config.background_mode == MODE_IMAGE) {
background_texture = load_texture_from_file(config.background_image);
if (config.background_image == NULL) {
output_log(LOGLEVEL_ERROR, "Error: BackgroundImage not specified in config file\n");
}
else {
background_texture = load_texture_from_file(config.background_image);
}

// Switch to color mode if loading background image failed
if (background_texture == NULL) {
Expand Down Expand Up @@ -1261,7 +1266,7 @@ int main(int argc, char *argv[])
else if (event.window.event == SDL_WINDOWEVENT_LEAVE) {
output_log(LOGLEVEL_DEBUG, "Lost mouse focus\n");
}
break;
break;
}
}

Expand Down

0 comments on commit a6e8643

Please sign in to comment.