Fixed bug #5118 - [Android] PointerIcon leak in Cursor API

This commit is contained in:
Sylvain 2021-12-21 22:07:17 +01:00
parent 5ca0926d8d
commit a1e992b110
No known key found for this signature in database
GPG Key ID: 5F87E02E5BC0939E
4 changed files with 27 additions and 0 deletions

View File

@ -1479,6 +1479,19 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
return mLastCursorID; return mLastCursorID;
} }
/**
* This method is called by SDL using JNI.
*/
public static void destroyCustomCursor(int cursorID) {
if (Build.VERSION.SDK_INT >= 24) {
try {
mCursors.remove(cursorID);
} catch (Exception e) {
}
}
return;
}
/** /**
* This method is called by SDL using JNI. * This method is called by SDL using JNI.
*/ */

View File

@ -303,6 +303,7 @@ static jmethodID midClipboardGetText;
static jmethodID midClipboardHasText; static jmethodID midClipboardHasText;
static jmethodID midClipboardSetText; static jmethodID midClipboardSetText;
static jmethodID midCreateCustomCursor; static jmethodID midCreateCustomCursor;
static jmethodID midDestroyCustomCursor;
static jmethodID midGetContext; static jmethodID midGetContext;
static jmethodID midGetDisplayDPI; static jmethodID midGetDisplayDPI;
static jmethodID midGetManifestEnvironmentVariables; static jmethodID midGetManifestEnvironmentVariables;
@ -582,6 +583,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(JNIEnv *env, jclass cl
midClipboardHasText = (*env)->GetStaticMethodID(env, mActivityClass, "clipboardHasText", "()Z"); midClipboardHasText = (*env)->GetStaticMethodID(env, mActivityClass, "clipboardHasText", "()Z");
midClipboardSetText = (*env)->GetStaticMethodID(env, mActivityClass, "clipboardSetText", "(Ljava/lang/String;)V"); midClipboardSetText = (*env)->GetStaticMethodID(env, mActivityClass, "clipboardSetText", "(Ljava/lang/String;)V");
midCreateCustomCursor = (*env)->GetStaticMethodID(env, mActivityClass, "createCustomCursor", "([IIIII)I"); midCreateCustomCursor = (*env)->GetStaticMethodID(env, mActivityClass, "createCustomCursor", "([IIIII)I");
midDestroyCustomCursor = (*env)->GetStaticMethodID(env, mActivityClass, "destroyCustomCursor", "(I)V");
midGetContext = (*env)->GetStaticMethodID(env, mActivityClass, "getContext","()Landroid/content/Context;"); midGetContext = (*env)->GetStaticMethodID(env, mActivityClass, "getContext","()Landroid/content/Context;");
midGetDisplayDPI = (*env)->GetStaticMethodID(env, mActivityClass, "getDisplayDPI", "()Landroid/util/DisplayMetrics;"); midGetDisplayDPI = (*env)->GetStaticMethodID(env, mActivityClass, "getDisplayDPI", "()Landroid/util/DisplayMetrics;");
midGetManifestEnvironmentVariables = (*env)->GetStaticMethodID(env, mActivityClass, "getManifestEnvironmentVariables", "()Z"); midGetManifestEnvironmentVariables = (*env)->GetStaticMethodID(env, mActivityClass, "getManifestEnvironmentVariables", "()Z");
@ -612,6 +614,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(JNIEnv *env, jclass cl
!midClipboardHasText || !midClipboardHasText ||
!midClipboardSetText || !midClipboardSetText ||
!midCreateCustomCursor || !midCreateCustomCursor ||
!midDestroyCustomCursor ||
!midGetContext || !midGetContext ||
!midGetDisplayDPI || !midGetDisplayDPI ||
!midGetManifestEnvironmentVariables || !midGetManifestEnvironmentVariables ||
@ -2503,6 +2506,12 @@ int Android_JNI_CreateCustomCursor(SDL_Surface *surface, int hot_x, int hot_y)
return custom_cursor; return custom_cursor;
} }
void Android_JNI_DestroyCustomCursor(int cursorID)
{
JNIEnv *env = Android_JNI_GetEnv();
(*env)->CallStaticVoidMethod(env, mActivityClass, midDestroyCustomCursor, cursorID);
return;
}
SDL_bool Android_JNI_SetCustomCursor(int cursorID) SDL_bool Android_JNI_SetCustomCursor(int cursorID)
{ {

View File

@ -118,6 +118,7 @@ int Android_JNI_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *bu
/* Cursor support */ /* Cursor support */
int Android_JNI_CreateCustomCursor(SDL_Surface *surface, int hot_x, int hot_y); int Android_JNI_CreateCustomCursor(SDL_Surface *surface, int hot_x, int hot_y);
void Android_JNI_DestroyCustomCursor(int cursorID);
SDL_bool Android_JNI_SetCustomCursor(int cursorID); SDL_bool Android_JNI_SetCustomCursor(int cursorID);
SDL_bool Android_JNI_SetSystemCursor(int cursorID); SDL_bool Android_JNI_SetSystemCursor(int cursorID);

View File

@ -113,6 +113,10 @@ Android_CreateSystemCursor(SDL_SystemCursor id)
static void static void
Android_FreeCursor(SDL_Cursor * cursor) Android_FreeCursor(SDL_Cursor * cursor)
{ {
SDL_AndroidCursorData *data = (SDL_AndroidCursorData*) cursor->driverdata;
if (data->custom_cursor != 0) {
Android_JNI_DestroyCustomCursor(data->custom_cursor);
}
SDL_free(cursor->driverdata); SDL_free(cursor->driverdata);
SDL_free(cursor); SDL_free(cursor);
} }