From a4a8b07d31dbeb9780352e332a5a4451866550c5 Mon Sep 17 00:00:00 2001 From: Mike Pavone Date: Sun, 24 Mar 2019 13:31:22 -0700 Subject: Make sure there are no races between main thread and audio thread around mix_buf. Fix lack of proper termination in shader loading code --- render_sdl.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'render_sdl.c') diff --git a/render_sdl.c b/render_sdl.c index 7f24b0d..8b92310 100755 --- a/render_sdl.c +++ b/render_sdl.c @@ -165,10 +165,6 @@ static conv_func convert; static void audio_callback(void * userdata, uint8_t *byte_stream, int len) { uint8_t num_populated; - float *mix_dest = mix_buf ? mix_buf : (float *)byte_stream; - - int samples = len / sample_size; - memset(mix_dest, 0, samples * sizeof(float)); SDL_LockMutex(audio_mutex); do { num_populated = 0; @@ -183,6 +179,9 @@ static void audio_callback(void * userdata, uint8_t *byte_stream, int len) SDL_CondWait(audio_ready, audio_mutex); } } while(!quitting && num_populated < num_audio_sources); + int samples = len / sample_size; + float *mix_dest = mix_buf ? mix_buf : (float *)byte_stream; + memset(mix_dest, 0, samples * sizeof(float)); if (!quitting) { for (uint8_t i = 0; i < num_audio_sources; i++) { @@ -191,8 +190,8 @@ static void audio_callback(void * userdata, uint8_t *byte_stream, int len) SDL_CondSignal(audio_sources[i]->cond); } } + convert(mix_dest, byte_stream, samples); SDL_UnlockMutex(audio_mutex); - convert(mix_dest, byte_stream, samples); } #define NO_LAST_BUFFERED -2000000000 @@ -248,12 +247,12 @@ static void render_close_audio() SDL_LockMutex(audio_mutex); quitting = 1; SDL_CondSignal(audio_ready); - if (mix_buf) { - free(mix_buf); - mix_buf = NULL; - } SDL_UnlockMutex(audio_mutex); SDL_CloseAudio(); + if (mix_buf) { + free(mix_buf); + mix_buf = NULL; + } } #define BUFFER_INC_RES 0x40000000UL @@ -522,6 +521,7 @@ static GLuint load_shader(char * fname, GLenum shader_type) } fsize = fsize32; } + text[fsize] = 0; if (strncmp(text, "#version", strlen("#version"))) { GLchar *tmp = text; -- cgit v1.2.3