Do music fade callback on main thread

Fixes music fades crashing the game sometimes
Backport from SRB2
See: 0aa763df85
Credits to Lactozilla
This commit is contained in:
alufolie91 2023-08-15 03:28:51 +02:00 committed by Alug
parent 62294dfe35
commit a7164a5d8f

View file

@ -90,6 +90,7 @@ static UINT32 fading_timer;
static UINT32 fading_duration; static UINT32 fading_duration;
static INT32 fading_id; static INT32 fading_id;
static void (*fading_callback)(void); static void (*fading_callback)(void);
static boolean fading_do_callback;
#ifdef HAVE_LIBGME #ifdef HAVE_LIBGME
static Music_Emu *gme; static Music_Emu *gme;
@ -106,6 +107,7 @@ static void var_cleanup(void)
is_fading = false; is_fading = false;
fading_callback = NULL; fading_callback = NULL;
fading_do_callback = false;
internal_volume = 100; internal_volume = 100;
} }
@ -202,6 +204,13 @@ void I_ShutdownSound(void)
void I_UpdateSound(void) void I_UpdateSound(void)
{ {
if (fading_do_callback)
{
if (fading_callback)
(*fading_callback)();
fading_callback = NULL;
fading_do_callback = false;
}
} }
/// ------------------------ /// ------------------------
@ -526,9 +535,8 @@ static UINT32 get_adjusted_position(UINT32 position)
static void do_fading_callback(void) static void do_fading_callback(void)
{ {
if (fading_callback) // TODO: Should I use a mutex here or something?
(*fading_callback)(); fading_do_callback = true;
fading_callback = NULL;
} }
/// ------------------------ /// ------------------------