From 09336bd4512aa2d12c7b433fde181834cb740597 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=91=A3=E6=AD=A3=E4=B8=9C?= <1796342412@qq.com> Date: Mon, 18 Mar 2024 10:16:25 +0800 Subject: [PATCH 1/2] test --- src/core/ohos/SDL_ohos.cpp | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/core/ohos/SDL_ohos.cpp b/src/core/ohos/SDL_ohos.cpp index 4aa5e8fb9..65dee21ab 100644 --- a/src/core/ohos/SDL_ohos.cpp +++ b/src/core/ohos/SDL_ohos.cpp @@ -51,6 +51,7 @@ SDL_DisplayOrientation displayOrientation; SDL_atomic_t bPermissionRequestPending; SDL_bool bPermissionRequestResult; +static SDL_atomic_t bQuit; /* Lock / Unlock Mutex */ void @@ -254,6 +255,9 @@ SDL_bool OHOS_SetCustomCursor(int cursorID) { cJSON *root = cJSON_CreateObject(); + if (SDL_AtomicGet(&bQuit) == SDL_TRUE) { + return SDL_TRUE; + } if (root == NULL) { SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Error creating JSON object."); return SDL_FALSE; @@ -267,6 +271,9 @@ SDL_bool OHOS_SetSystemCursor(int cursorID) { cJSON *root = cJSON_CreateObject(); + if (SDL_AtomicGet(&bQuit) == SDL_TRUE) { + return SDL_TRUE; + } if (root == NULL) { SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Error creating JSON object."); return SDL_FALSE; @@ -281,26 +288,12 @@ OHOS_SetSystemCursor(int cursorID) SDL_bool OHOS_SupportsRelativeMouse(void) { - cJSON *root = cJSON_CreateObject(); - if (root == NULL) { - SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Error creating JSON object."); - return SDL_FALSE; - } - - napi_call_threadsafe_function(napiCallback->tsfn, root, napi_tsfn_nonblocking); return SDL_TRUE; } SDL_bool OHOS_SetRelativeMouseEnabled(SDL_bool enabled) { - cJSON *root = cJSON_CreateObject(); - if (root == NULL) { - SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Error creating JSON object."); - return SDL_FALSE; - } - cJSON_AddBoolToObject(root, "enabled", enabled); - napi_call_threadsafe_function(napiCallback->tsfn, root, napi_tsfn_nonblocking); return SDL_TRUE; } @@ -465,6 +458,7 @@ OHOS_NativeQuit(void) { napi_value SDLNapi::OHOS_NativeSendQuit(napi_env env, napi_callback_info info) { + SDL_AtomicSet(&bQuit, SDL_TRUE); SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT); napi_value sum = 0; SDL_SendQuit(); @@ -545,6 +539,7 @@ OHOS_NAPI_NativeSetup(void) SDL_setenv("SDL_VIDEO_EGL_DRIVER", "libEGL.so", 1); SDL_setenv("SDL_ASSERT", "ignore", 1); SDL_AtomicSet(&bPermissionRequestPending, SDL_FALSE); + SDL_AtomicSet(&bQuit, SDL_FALSE); return; } @@ -626,7 +621,8 @@ SDLAppEntry(napi_env env, napi_callback_info info) break; } napi_get_value_string_utf8(env, argv[i], nullptr, 0, &buffer_size); - arg = new char[buffer_size]; + arg = new char[buffer_size + 1]; + SDL_memset(arg, 0, buffer_size + 1); napi_get_value_string_utf8(env, argv[i], arg, buffer_size + 1, &buffer_size); if (!arg) { delete[] arg; -- Gitee From c77f875b8d0a8a150904219dbfdbf5fda120b0db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=91=A3=E6=AD=A3=E4=B8=9C?= <1796342412@qq.com> Date: Mon, 18 Mar 2024 10:50:15 +0800 Subject: [PATCH 2/2] test --- src/core/ohos/SDL_ohos.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/ohos/SDL_ohos.cpp b/src/core/ohos/SDL_ohos.cpp index 65dee21ab..3770aafda 100644 --- a/src/core/ohos/SDL_ohos.cpp +++ b/src/core/ohos/SDL_ohos.cpp @@ -254,10 +254,10 @@ OHOS_CreateCustomCursor(SDL_Surface *surface, int hot_x, int hot_y) SDL_bool OHOS_SetCustomCursor(int cursorID) { - cJSON *root = cJSON_CreateObject(); if (SDL_AtomicGet(&bQuit) == SDL_TRUE) { return SDL_TRUE; } + cJSON *root = cJSON_CreateObject(); if (root == NULL) { SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Error creating JSON object."); return SDL_FALSE; @@ -270,10 +270,10 @@ OHOS_SetCustomCursor(int cursorID) SDL_bool OHOS_SetSystemCursor(int cursorID) { - cJSON *root = cJSON_CreateObject(); if (SDL_AtomicGet(&bQuit) == SDL_TRUE) { return SDL_TRUE; } + cJSON *root = cJSON_CreateObject(); if (root == NULL) { SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Error creating JSON object."); return SDL_FALSE; -- Gitee