From 4884a6e823e53b0d0e61ae122cd1083ea10aebea Mon Sep 17 00:00:00 2001 From: "P. F. Chimento" Date: Mon, 22 Nov 2010 21:54:41 +0100 Subject: [PATCH] Fix crash when loading resource without a map The Glk program now fails gracefully when trying to load an image resource without having loaded a resource map first: it prints a warning and doesn't load the image, instead of crashing. --- libchimara/chimara-glk.c | 1 + libchimara/graphics.c | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/libchimara/chimara-glk.c b/libchimara/chimara-glk.c index eba6a23..6221175 100644 --- a/libchimara/chimara-glk.c +++ b/libchimara/chimara-glk.c @@ -178,6 +178,7 @@ chimara_glk_init(ChimaraGlk *self) priv->char_input_queue = g_async_queue_new(); priv->line_input_queue = g_async_queue_new(); /* Should be g_async_queue_new_full(g_free); but only in GTK >= 2.16 */ + priv->resource_map = NULL; priv->resource_lock = g_mutex_new(); priv->resource_loaded = g_cond_new(); priv->resource_info_available = g_cond_new(); diff --git a/libchimara/graphics.c b/libchimara/graphics.c index c87a148..7f59915 100644 --- a/libchimara/graphics.c +++ b/libchimara/graphics.c @@ -22,6 +22,10 @@ load_image_in_cache(glui32 image, gint width, gint height) guchar *buffer; /* Lookup the proper resource */ + if(!glk_data->resource_map) { + WARNING("No resource map has been loaded yet."); + return NULL; + } blorb_error = giblorb_load_resource(glk_data->resource_map, giblorb_method_FilePos, &resource, giblorb_ID_Pict, image); if(blorb_error != giblorb_err_None) { WARNING_S( "Error loading resource", giblorb_get_error_message(blorb_error) ); -- 2.30.2