Skip to content

Commit

Permalink
Silence warning if loading nonexistent resource
Browse files Browse the repository at this point in the history
We would previously log a warning here, but looking up a nonexistent
resource number to see if it exists is a perfectly legal thing for a Glk
program to do.

Now the tests should pass without logging any warnings or criticals.
  • Loading branch information
ptomato committed Sep 24, 2023
1 parent 06b9ef6 commit 4b6e5e8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
5 changes: 3 additions & 2 deletions libchimara/graphics.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,9 @@ load_image_in_cache(glui32 image, gint width, gint height)
} else {
giblorb_result_t resource;
giblorb_err_t 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) );
if (blorb_error != giblorb_err_None) {
if (blorb_error != giblorb_err_NotFound)
WARNING_S("Error loading resource", giblorb_get_error_message(blorb_error));
return NULL;
}
info = load_image_from_blorb(resource, image, width, height);
Expand Down
9 changes: 6 additions & 3 deletions libchimara/schannel.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ load_resource_into_giostream(glui32 snd)
giblorb_result_t resource;
giblorb_err_t result = giblorb_load_resource(glk_data->resource_map, giblorb_method_Memory, &resource, giblorb_ID_Snd, snd);
if(result != giblorb_err_None) {
WARNING_S( "Error loading resource", giblorb_get_error_message(result) );
if (result != giblorb_err_NotFound)
WARNING_S("Error loading resource", giblorb_get_error_message(result));
return NULL;
}
retval = g_memory_input_stream_new_from_data(resource.data.ptr, resource.length, NULL);
Expand Down Expand Up @@ -888,7 +889,8 @@ glk_sound_load_hint(glui32 snd, glui32 flag)
loading a chunk more than once does nothing */
result = giblorb_load_resource(glk_data->resource_map, giblorb_method_Memory, &resource, giblorb_ID_Snd, snd);
if(result != giblorb_err_None) {
WARNING_S( "Error loading resource", giblorb_get_error_message(result) );
if (result != giblorb_err_NotFound)
WARNING_S("Error loading resource", giblorb_get_error_message(result));
return;
}
} else {
Expand All @@ -897,7 +899,8 @@ glk_sound_load_hint(glui32 snd, glui32 flag)
isn't loaded */
result = giblorb_load_resource(glk_data->resource_map, giblorb_method_DontLoad, &resource, giblorb_ID_Snd, snd);
if(result != giblorb_err_None) {
WARNING_S( "Error loading resource", giblorb_get_error_message(result) );
if (result != giblorb_err_NotFound)
WARNING_S("Error loading resource", giblorb_get_error_message(result));
return;
}
result = giblorb_unload_chunk(glk_data->resource_map, resource.chunknum);
Expand Down
10 changes: 6 additions & 4 deletions libchimara/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -527,10 +527,12 @@ glk_stream_open_resource(glui32 filenum, glui32 rock)
}

err = giblorb_load_resource(map, giblorb_method_Memory, &res, giblorb_ID_Data, filenum);
if(err) {
WARNING_S("Could not create resource stream, because the resource "
"could not be loaded", giblorb_get_error_message(err));
return 0; /* Not found, or some other error */
if (err != giblorb_err_None) {
if (err != giblorb_err_NotFound) {
WARNING_S("Could not create resource stream, because the resource "
"could not be loaded", giblorb_get_error_message(err));
}
return NULL;
}

/* We'll use the in-memory copy of the chunk data as the basis for
Expand Down
1 change: 1 addition & 0 deletions tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ stream_test = shared_module('stream', 'unit/stream.c', 'unit/glkunit.c',

test_env = environment()
test_env.set('NO_AT_BRIDGE', '1')
test_env.set('G_DEBUG', 'fatal-warnings')
test_env.set('SOURCE_DIR', meson.current_source_dir())

test('datetime', glkunit_runner, args: [datetime_test], suite: 'unit',
Expand Down

0 comments on commit 4b6e5e8

Please sign in to comment.