From 26e2d35ec75e80c63de0251844181469529d6808 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 15 Jul 2007 04:08:44 +0000 Subject: [PATCH] Fixed bug #385 Removed C runtime dependency for file I/O - fixes opening Ogg Vorbis files on Windows with different versions of the C runtime. --- CHANGES | 2 ++ music_ogg.c | 36 ++++++------------------------------ 2 files changed, 8 insertions(+), 30 deletions(-) diff --git a/CHANGES b/CHANGES index 33f78e3a..f5513c68 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,6 @@ 1.2.8: +Sam Lantinga - Sat Jul 14 21:05:09 PDT 2007 + * Fixed opening Ogg Vorbis files using different C runtimes on Windows Philippe Simons - Sat Jul 14 20:33:17 PDT 2007 * Added support for Ogg Vorbis playback with Tremor (an integer decoder) Sam Lantinga - Sat Jul 14 07:02:09 PDT 2007 diff --git a/music_ogg.c b/music_ogg.c index 71cb26bf..51a2fef6 100644 --- a/music_ogg.c +++ b/music_ogg.c @@ -55,38 +55,14 @@ void OGG_setvolume(OGG_music *music, int volume) /* Load an OGG stream from the given file */ OGG_music *OGG_new(const char *file) { - OGG_music *music; - FILE *fp; - - music = (OGG_music *)malloc(sizeof *music); - if ( music ) { - /* Initialize the music structure */ - memset(music, 0, (sizeof *music)); - OGG_stop(music); - OGG_setvolume(music, MIX_MAX_VOLUME); - music->section = -1; + SDL_RWops *rw; - if ( Mix_InitOgg() < 0 ) { - return(NULL); - } - fp = fopen(file, "rb"); - if ( fp == NULL ) { - free(music); - Mix_QuitOgg(); - SDL_SetError("Couldn't open %s", file); - return(NULL); - } - if ( vorbis.ov_open(fp, &music->vf, NULL, 0) < 0 ) { - fclose(fp); - free(music); - Mix_QuitOgg(); - SDL_SetError("Not an Ogg Vorbis audio stream"); - return(NULL); - } - } else { - SDL_OutOfMemory(); + rw = SDL_RWFromFile(file, "rb"); + if ( rw == NULL ) { + SDL_SetError("Couldn't open %s", file); + return NULL; } - return(music); + return OGG_new_RW(rw); }