From 9a6b364f70ba77c3f9b64717b62bfd69f3085612 Mon Sep 17 00:00:00 2001 From: bofeng-song Date: Fri, 13 May 2022 10:16:01 +0800 Subject: [PATCH] Fix the problem that Surface size may get wrong after Android backend cut to frontend (#255) --- .../include/game-activity/GameActivity.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/sources/android-gamesdk/GameActivity/game-activity/include/game-activity/GameActivity.cpp b/sources/android-gamesdk/GameActivity/game-activity/include/game-activity/GameActivity.cpp index d20cd6be..4e6d63ee 100644 --- a/sources/android-gamesdk/GameActivity/game-activity/include/game-activity/GameActivity.cpp +++ b/sources/android-gamesdk/GameActivity/game-activity/include/game-activity/GameActivity.cpp @@ -767,10 +767,15 @@ static void onSurfaceChanged_native(JNIEnv *env, jobject javaGameActivity, code->nativeWindow); } - code->lastWindowWidth = - ANativeWindow_getWidth(code->nativeWindow); - code->lastWindowHeight = - ANativeWindow_getHeight(code->nativeWindow); + if (width != code->lastWindowWidth || + height != code->lastWindowHeight) { + code->lastWindowWidth = width; + code->lastWindowHeight = height; + if (code->callbacks.onNativeWindowResized != NULL) { + code->callbacks.onNativeWindowResized( + code, code->nativeWindow, width, height); + } + } } } else { // Maybe it was resized? @@ -778,6 +783,8 @@ static void onSurfaceChanged_native(JNIEnv *env, jobject javaGameActivity, int32_t newHeight = ANativeWindow_getHeight(code->nativeWindow); if (newWidth != code->lastWindowWidth || newHeight != code->lastWindowHeight) { + code->lastWindowWidth = newWidth; + code->lastWindowHeight = newHeight; if (code->callbacks.onNativeWindowResized != NULL) { code->callbacks.onNativeWindowResized( code, code->nativeWindow, newWidth, newHeight);