[ion/simulator/android] Delete JNI local references

Change-Id: Idd4d6c769786fb595a357bcc3f54e67429ed1840
This commit is contained in:
Hugo Saint-Vignes
2021-02-08 10:50:05 +01:00
parent 73172f8d0c
commit ba64458660
2 changed files with 14 additions and 1 deletions

View File

@@ -2,6 +2,7 @@
#include <SDL.h>
#include <jni.h>
#include <android/bitmap.h>
#include <assert.h>
SDL_Texture * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identifier) {
JNIEnv * env = static_cast<JNIEnv *>(SDL_AndroidGetJNIEnv());
@@ -13,6 +14,7 @@ SDL_Texture * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identi
"retrieveBitmapAsset",
"(Ljava/lang/String;)Landroid/graphics/Bitmap;"
);
assert(j_methodId != 0);
jstring j_identifier = env->NewStringUTF(identifier);
@@ -45,6 +47,10 @@ SDL_Texture * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identi
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
AndroidBitmap_unlockPixels(env, j_bitmap);
// See comment in haptics_enabled.cpp
env->DeleteLocalRef(j_bitmap);
env->DeleteLocalRef(j_identifier);
env->DeleteLocalRef(j_class);
env->DeleteLocalRef(activity);
return texture;
}

View File

@@ -1,6 +1,7 @@
#include "../../../shared/telemetry.h"
#include <jni.h>
#include <SDL.h>
#include <assert.h>
static inline JNIEnv * AndroidJNI() {
return static_cast<JNIEnv *>(SDL_AndroidGetJNIEnv());
@@ -23,8 +24,10 @@ void init() {
jclass j_class = env->FindClass("com/numworks/calculator/EpsilonActivity");
jmethodID j_methodId = env->GetMethodID(j_class,"telemetryInit", "()V");
assert(j_methodId != 0);
env->CallVoidMethod(AndroidActivity(), j_methodId);
env->DeleteLocalRef(j_class);
}
void shutdown() {
@@ -42,8 +45,10 @@ void reportScreen(const char * screenName) {
jclass j_class = env->FindClass("com/numworks/calculator/EpsilonActivity");
jmethodID j_methodId = env->GetMethodID(j_class, "telemetryScreen", "(Ljava/lang/String;)V");
assert(j_methodId != 0);
env->CallVoidMethod(AndroidActivity(), j_methodId, JS(screenName, env));
env->DeleteLocalRef(j_class);
}
void reportEvent(const char * category, const char * action, const char * label) {
@@ -51,8 +56,10 @@ void reportEvent(const char * category, const char * action, const char * label)
jclass j_class = env->FindClass("com/numworks/calculator/EpsilonActivity");
jmethodID j_methodId = env->GetMethodID(j_class, "telemetryEvent", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
assert(j_methodId != 0);
env->CallVoidMethod(AndroidActivity(), j_methodId, JS(category, env), JS(action, env), JS(label, env));
env->DeleteLocalRef(j_class);
}
}