diff --git a/RenderSystems/Vulkan/include/Windowing/Android/OgreVulkanAndroidWindow.h b/RenderSystems/Vulkan/include/Windowing/Android/OgreVulkanAndroidWindow.h index 5f0de8eb768..87f314c62da 100644 --- a/RenderSystems/Vulkan/include/Windowing/Android/OgreVulkanAndroidWindow.h +++ b/RenderSystems/Vulkan/include/Windowing/Android/OgreVulkanAndroidWindow.h @@ -51,11 +51,18 @@ namespace Ogre public: /** User must override this function. @param env [out] - The JNI class that is assumed to be from AttachCurrentThread. + The JNI class that is assumed to be from AttachCurrentThread(). @param activity [out] NativeActivity object handle, used for JNI. */ - virtual void get( JNIEnv **env, jobject *activity ) = 0; + virtual void acquire( JNIEnv **env, jobject *activity ) = 0; + + /** Notifies the implementation that we're done using the env object. + In case the implementation wants to call DetachCurrentThread(). + @param env + The JNI class that was retrieved via acquire(). + */ + virtual void release( JNIEnv *env ) = 0; }; class _OgreVulkanExport VulkanAndroidWindow final : public VulkanWindowSwapChainBased diff --git a/RenderSystems/Vulkan/src/Windowing/Android/OgreVulkanAndroidWindow.cpp b/RenderSystems/Vulkan/src/Windowing/Android/OgreVulkanAndroidWindow.cpp index e7d0e1179c1..cf05fcfec06 100644 --- a/RenderSystems/Vulkan/src/Windowing/Android/OgreVulkanAndroidWindow.cpp +++ b/RenderSystems/Vulkan/src/Windowing/Android/OgreVulkanAndroidWindow.cpp @@ -395,11 +395,14 @@ namespace Ogre "VulkanAndroidWindow::createSwapchain" ); } - JNIEnv *jni = 0; - jobject nativeActivityClass = 0; - mJniProvider->get( &jni, &nativeActivityClass ); - SwappyVk_initAndGetRefreshCycleDuration( jni, nativeActivityClass, mDevice->mPhysicalDevice, - mDevice->mDevice, mSwapchain, &mRefreshDuration ); + { + JNIEnv *jni = 0; + jobject nativeActivityClass = 0; + mJniProvider->acquire( &jni, &nativeActivityClass ); + SwappyVk_initAndGetRefreshCycleDuration( jni, nativeActivityClass, mDevice->mPhysicalDevice, + mDevice->mDevice, mSwapchain, &mRefreshDuration ); + mJniProvider->release( jni ); + } // Swappy wants to know the mNativeWindow every time the Swapchain changes. // If we try to set mNativeWindow without a valid mSwapchain yet, it won't work correctly.