Fix crash when loading resource without a map
authorP. F. Chimento <philip.chimento@gmail.com>
Mon, 22 Nov 2010 20:54:41 +0000 (21:54 +0100)
committerP. F. Chimento <philip.chimento@gmail.com>
Mon, 22 Nov 2010 20:54:41 +0000 (21:54 +0100)
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
libchimara/graphics.c

index eba6a23d8944c9fd2732ba72b329ac9fe7b342f9..622117591e2da39be487fbb5e850be8e21713fa5 100644 (file)
@@ -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();
index c87a148390aa0dc05fdd17a7114ac1ca6aa883e4..7f59915dafb3402ea94b1e7b32a408e0b705151c 100644 (file)
@@ -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) );