mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-11 08:36:38 -04:00
Fix rare game freeze when trying to stop playing music, only been triggered on android so far that I know of
This commit is contained in:
parent
0fe269dff5
commit
2b10ae408c
11
src/Audio.c
11
src/Audio.c
@ -12,10 +12,13 @@
|
|||||||
#include "Stream.h"
|
#include "Stream.h"
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
#include "Options.h"
|
#include "Options.h"
|
||||||
|
#ifdef CC_BUILD_ANDROID
|
||||||
|
/* TODO: Refactor maybe to not rely on checking WinInfo.Handle != NULL */
|
||||||
|
#include "Window.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
int Audio_SoundsVolume, Audio_MusicVolume;
|
int Audio_SoundsVolume, Audio_MusicVolume;
|
||||||
|
|
||||||
/* TODO: Fix for android */
|
|
||||||
#if defined CC_BUILD_NOAUDIO
|
#if defined CC_BUILD_NOAUDIO
|
||||||
/* Can't use mojang's sounds or music assets, so just stub everything out */
|
/* Can't use mojang's sounds or music assets, so just stub everything out */
|
||||||
static void OnInit(void) { }
|
static void OnInit(void) { }
|
||||||
@ -960,6 +963,10 @@ static cc_result Music_PlayOgg(struct Stream* source) {
|
|||||||
if (res) goto cleanup;
|
if (res) goto cleanup;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
#if 0
|
||||||
|
/* Don't play music while in the background on Android */
|
||||||
|
if (!WindowInfo.Handle && !music_pendingStop) { Thread_Sleep(10); continue; }
|
||||||
|
#endif
|
||||||
next = -1;
|
next = -1;
|
||||||
|
|
||||||
for (i = 0; i < AUDIO_MAX_BUFFERS; i++) {
|
for (i = 0; i < AUDIO_MAX_BUFFERS; i++) {
|
||||||
@ -968,8 +975,8 @@ static cc_result Music_PlayOgg(struct Stream* source) {
|
|||||||
if (available) { next = i; break; }
|
if (available) { next = i; break; }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (next == -1) { Thread_Sleep(10); continue; }
|
|
||||||
if (music_pendingStop) break;
|
if (music_pendingStop) break;
|
||||||
|
if (next == -1) { Thread_Sleep(10); continue; }
|
||||||
|
|
||||||
res = Music_Buffer(next, &data[chunkSize * next], samplesPerSecond, &vorbis);
|
res = Music_Buffer(next, &data[chunkSize * next], samplesPerSecond, &vorbis);
|
||||||
/* need to specially handle last bit of audio */
|
/* need to specially handle last bit of audio */
|
||||||
|
@ -3760,6 +3760,7 @@ static void JNICALL java_processMouseMove(JNIEnv* env, jobject o, jint id, jint
|
|||||||
static void JNICALL java_processSurfaceCreated(JNIEnv* env, jobject o, jobject surface) {
|
static void JNICALL java_processSurfaceCreated(JNIEnv* env, jobject o, jobject surface) {
|
||||||
Platform_LogConst("WIN - CREATED");
|
Platform_LogConst("WIN - CREATED");
|
||||||
win_handle = ANativeWindow_fromSurface(env, surface);
|
win_handle = ANativeWindow_fromSurface(env, surface);
|
||||||
|
WindowInfo.Handle = win_handle;
|
||||||
RefreshWindowBounds();
|
RefreshWindowBounds();
|
||||||
/* TODO: Restore context */
|
/* TODO: Restore context */
|
||||||
Event_RaiseVoid(&WindowEvents.Created);
|
Event_RaiseVoid(&WindowEvents.Created);
|
||||||
@ -3771,6 +3772,7 @@ static void JNICALL java_processSurfaceDestroyed(JNIEnv* env, jobject o) {
|
|||||||
if (win_handle) ANativeWindow_release(win_handle);
|
if (win_handle) ANativeWindow_release(win_handle);
|
||||||
|
|
||||||
win_handle = NULL;
|
win_handle = NULL;
|
||||||
|
WindowInfo.Handle = NULL;
|
||||||
/* eglSwapBuffers might return EGL_BAD_SURFACE, EGL_BAD_ALLOC, or some other error */
|
/* eglSwapBuffers might return EGL_BAD_SURFACE, EGL_BAD_ALLOC, or some other error */
|
||||||
/* Instead the context is lost here in a consistent manner */
|
/* Instead the context is lost here in a consistent manner */
|
||||||
if (Gfx.Created) Gfx_LoseContext("surface lost");
|
if (Gfx.Created) Gfx_LoseContext("surface lost");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user