From 0b4363679cb210c791bbd5a9a9fe9c17af72badb Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Wed, 27 Jan 2021 01:01:07 +1000 Subject: [PATCH] Android: Block for window changes/surface destruction --- android/app/src/cpp/android_host_interface.cpp | 4 +++- android/app/src/cpp/android_host_interface.h | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/android/app/src/cpp/android_host_interface.cpp b/android/app/src/cpp/android_host_interface.cpp index 7713c6917..22e0868aa 100644 --- a/android/app/src/cpp/android_host_interface.cpp +++ b/android/app/src/cpp/android_host_interface.cpp @@ -1001,10 +1001,12 @@ DEFINE_JNI_ARGS_METHOD(void, AndroidHostInterface_surfaceChanged, jobject obj, j if (surface && !native_surface) Log_ErrorPrint("ANativeWindow_fromSurface() returned null"); + // We should wait for the emu to finish if the surface is being destroyed or changed. AndroidHostInterface* hi = AndroidHelpers::GetNativeClass(env, obj); + const bool block = (!native_surface || native_surface != hi->GetSurface()); hi->RunOnEmulationThread( [hi, native_surface, format, width, height]() { hi->SurfaceChanged(native_surface, format, width, height); }, - false); + block); } DEFINE_JNI_ARGS_METHOD(void, AndroidHostInterface_setControllerType, jobject obj, jint index, jstring controller_type) diff --git a/android/app/src/cpp/android_host_interface.h b/android/app/src/cpp/android_host_interface.h index 20c32979c..045b999b0 100644 --- a/android/app/src/cpp/android_host_interface.h +++ b/android/app/src/cpp/android_host_interface.h @@ -24,6 +24,8 @@ public: AndroidHostInterface(jobject java_object, jobject context_object, std::string user_directory); ~AndroidHostInterface() override; + ALWAYS_INLINE ANativeWindow* GetSurface() const { return m_surface; } + bool Initialize() override; void Shutdown() override;