diff --git a/src/core/ohos/SDL_ohos.cpp b/src/core/ohos/SDL_ohos.cpp index 4aa5e8fb952ffbcbe88c462d59b63fd3120f4a25..3770aafda22cdd580bff5d9926915001bf0d5998 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 @@ -253,6 +254,9 @@ OHOS_CreateCustomCursor(SDL_Surface *surface, int hot_x, int hot_y) SDL_bool OHOS_SetCustomCursor(int cursorID) { + 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."); @@ -266,6 +270,9 @@ OHOS_SetCustomCursor(int cursorID) SDL_bool OHOS_SetSystemCursor(int cursorID) { + 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."); @@ -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;