Android: fix call of glFinish without context. Message in the log, when going to background: "call to OpenGL ES API with no current context (logged once per thread)" Because of SDL_WINDOWEVENT_MINIMIZED is sent from the Java Activity thread. It calls SDL_RendererEventWatch(), _WindowEvent() and glFinish() without context. Solution is to move sending of SDL_WINDOWEVENT_MINIMIZED to the SDL thread.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c
index 4d6d9f9..1081b58 100644
--- a/src/core/android/SDL_android.c
+++ b/src/core/android/SDL_android.c
@@ -1162,23 +1162,11 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeQuit)(
JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativePause)(
JNIEnv *env, jclass cls)
{
- SDL_LockMutex(Android_ActivityMutex);
-
__android_log_print(ANDROID_LOG_VERBOSE, "SDL", "nativePause()");
- if (Android_Window) {
- SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
- SDL_SendAppEvent(SDL_APP_WILLENTERBACKGROUND);
- SDL_SendAppEvent(SDL_APP_DIDENTERBACKGROUND);
- }
-
- /* *After* sending the relevant events, signal the pause semaphore
- * so the event loop knows to pause and (optionally) block itself.
- * Sometimes 2 pauses can be queued (eg pause/resume/pause), so it's
- * always increased. */
+ /* Signal the pause semaphore so the event loop knows to pause and (optionally) block itself.
+ * Sometimes 2 pauses can be queued (eg pause/resume/pause), so it's always increased. */
SDL_SemPost(Android_PauseSem);
-
- SDL_UnlockMutex(Android_ActivityMutex);
}
/* Resume */
diff --git a/src/video/android/SDL_androidevents.c b/src/video/android/SDL_androidevents.c
index 87ad12f..139eb38 100644
--- a/src/video/android/SDL_androidevents.c
+++ b/src/video/android/SDL_androidevents.c
@@ -27,6 +27,7 @@
#include "SDL_androidkeyboard.h"
#include "SDL_androidwindow.h"
#include "../SDL_sysvideo.h"
+#include "../../events/SDL_events_c.h"
/* Can't include sysaudio "../../audio/android/SDL_androidaudio.h"
* because of THIS redefinition */
@@ -129,6 +130,14 @@ Android_PumpEvents_Blocking(_THIS)
}
} else {
if (videodata->isPausing || SDL_SemTryWait(Android_PauseSem) == 0) {
+
+ /* Android_PauseSem was signaled */
+ if (videodata->isPausing == 0) {
+ SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
+ SDL_SendAppEvent(SDL_APP_WILLENTERBACKGROUND);
+ SDL_SendAppEvent(SDL_APP_DIDENTERBACKGROUND);
+ }
+
/* We've been signaled to pause (potentially several times), but before we block ourselves,
* we need to make sure that the very last event (of the first pause sequence, if several)
* has reached the app */
@@ -187,6 +196,14 @@ Android_PumpEvents_NonBlocking(_THIS)
}
} else {
if (videodata->isPausing || SDL_SemTryWait(Android_PauseSem) == 0) {
+
+ /* Android_PauseSem was signaled */
+ if (videodata->isPausing == 0) {
+ SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
+ SDL_SendAppEvent(SDL_APP_WILLENTERBACKGROUND);
+ SDL_SendAppEvent(SDL_APP_DIDENTERBACKGROUND);
+ }
+
/* We've been signaled to pause (potentially several times), but before we block ourselves,
* we need to make sure that the very last event (of the first pause sequence, if several)
* has reached the app */