From f26c53e8506c1a2a2cde231618de3459ae28d090 Mon Sep 17 00:00:00 2001 From: NagyD Date: Sun, 9 Oct 2022 17:31:34 +0200 Subject: [PATCH] Fixed the loading of OGG files which have no metadata. --- src/seg009.c | 4 +++- src/stb_vorbis.c | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/seg009.c b/src/seg009.c index 2d205d02..98de72f8 100644 --- a/src/seg009.c +++ b/src/seg009.c @@ -2190,8 +2190,10 @@ sound_buffer_type* load_sound(int index) { // Decoding the entire file immediately would make the loading time much longer. // However, we can also create the decoder now, and only use it when we are actually playing the file. // (In the audio callback, we'll decode chunks of samples to the output stream, as needed). - stb_vorbis* decoder = stb_vorbis_open_memory(file_contents, (int)file_size, NULL, NULL); + int error = 0; + stb_vorbis* decoder = stb_vorbis_open_memory(file_contents, (int)file_size, &error, NULL); if (decoder == NULL) { + printf("Error %d when creating decoder from file \"%s\"!\n", error, filename); free(file_contents); break; } diff --git a/src/stb_vorbis.c b/src/stb_vorbis.c index 18f1edab..8e60b5e3 100644 --- a/src/stb_vorbis.c +++ b/src/stb_vorbis.c @@ -3646,7 +3646,8 @@ static int start_decoder(vorb *f) //user comments f->comment_list_length = get32_packet(f); f->comment_list = (char**)setup_malloc(f, sizeof(char*) * (f->comment_list_length)); - if (f->comment_list == NULL) return error(f, VORBIS_outofmem); + // David: If comment_list_length == 0 (there is no metadata) then malloc will always return NULL, but that's not an error. + if (f->comment_list_length != 0 && f->comment_list == NULL) return error(f, VORBIS_outofmem); for(i=0; i < f->comment_list_length; ++i) { len = get32_packet(f);