From ed0cf79ce1308ed8b41372a2372573577f47379f Mon Sep 17 00:00:00 2001 From: Harry Jeffery Date: Tue, 10 Nov 2015 11:25:05 +0000 Subject: Fix a crash when no input files were valid --- main.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index a223fc3..53dfacf 100644 --- a/main.c +++ b/main.c @@ -360,6 +360,11 @@ int main(int argc, char** argv) } } + if(!imv_navigator_get_current_path(&nav)) { + fprintf(stderr, "No input files. Exiting.\n"); + exit(1); + } + if(SDL_Init(SDL_INIT_VIDEO) != 0) { fprintf(stderr, "SDL Failed to Init: %s\n", SDL_GetError()); exit(1); @@ -388,7 +393,7 @@ int main(int argc, char** argv) toggle_fullscreen(); } - const char* last_path = NULL; + const char* current_path = NULL; double last_time = SDL_GetTicks() / 1000.0; @@ -446,13 +451,19 @@ int main(int argc, char** argv) break; } - while(imv_navigator_get_current_path(&nav) != last_path) { - last_path = imv_navigator_get_current_path(&nav); - if(load_image(&tex, last_path) != 0) { + while(imv_navigator_get_current_path(&nav) != current_path) { + current_path = imv_navigator_get_current_path(&nav); + + if(!current_path) { + fprintf(stderr, "No input files left. Exiting\n."); + exit(1); + } + + if(load_image(&tex, current_path) != 0) { imv_navigator_remove_current_path(&nav); } else { char title[128]; - snprintf(&title[0], sizeof(title), "imv - %s", last_path); + snprintf(&title[0], sizeof(title), "imv - %s", current_path); SDL_SetWindowTitle(g_window, (const char*)&title); reset_view(); } -- cgit v1.2.3