Skip to content

Commit

Permalink
Fixed the loading of OGG files which have no metadata.
Browse files Browse the repository at this point in the history
  • Loading branch information
NagyD committed Oct 9, 2022
1 parent d605517 commit f26c53e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/seg009.c
Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion src/stb_vorbis.c
Expand Up @@ -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);
Expand Down

2 comments on commit f26c53e

@dstarosta
Copy link
Contributor

@dstarosta dstarosta commented on f26c53e Oct 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vorbis 1.22 has a better fix for this problem that avoids an allocation.

@NagyD
Copy link
Owner Author

@NagyD NagyD commented on f26c53e Oct 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the tip!
Somehow I forgot to check if this was already fixed upstream.

I have updated stb_vorbis to the latest version: 04d0818

Please sign in to comment.