libsdl-org / SDL_mixer

An audio mixer that supports various file formats for Simple Directmedia Layer.
zlib License
431 stars 147 forks source link

[1.2 master] Crash after closing and reopening Mix_OpenAudio #580

Open SupSuper opened 11 months ago

SupSuper commented 11 months ago

(yes yes I know it's deprecated)

Simple test case:

int main()
{
    SDL_Init(SDL_INIT_EVERYTHING);
    Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 2048);
    Mix_CloseAudio();
    Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 2048);
}

This will crash on the second Mix_OpenAudio call with an access violation on the following line: image

This issue only occurs on the "master" version of SDL_mixer 1.2 (https://github.com/libsdl-org/SDL_mixer/commit/b762825ebf631618abd69463cbbf4fbb0bbc8f76), not the last official release 1.2.12. Normally I would close it there, but we've had sporadic reports of Linux users running into this crash, so I can only assume they're building it from source or some distros are patching it.

(if reopening Mixer isn't supported, I'd also accept a workaround)

sezero commented 11 months ago

I can't reproduce this on linux at the moment.

I added this debug print:

diff --git a/dynamic_mod.c b/dynamic_mod.c
index e184ee7..a5a4388 100644
--- a/dynamic_mod.c
+++ b/dynamic_mod.c
@@ -219,6 +219,7 @@ int Mix_InitMOD(void)
            SDL_UnloadObject(mikmod.handle);
            return -1;
        }
+/**/       fprintf(stderr,"MUSIC_MOD: loaded\n");
    }
    ++mikmod.loaded;

.. and upon running your test case, MUSIC_MOD: loaded printed on my terminal only once, meaning libmikmod is never unlodaded. valgrind doesn't any errors or warnings either...