diff --git a/src/core/ohos/SDL_ohos_xcomponent.cpp b/src/core/ohos/SDL_ohos_xcomponent.cpp index 5ff5902e2dfa541f5bdcbc3391e4718d7e4a88ff..8c2533568fefbf82f63bd7c9d47b28fd4652da09 100644 --- a/src/core/ohos/SDL_ohos_xcomponent.cpp +++ b/src/core/ohos/SDL_ohos_xcomponent.cpp @@ -64,12 +64,12 @@ static void OnSurfaceCreatedCB(OH_NativeXComponent *component, void *window) { OHOS_SetScreenSize((int)width, (int)height); if (OHOS_Window) { SDL_WindowData *data = (SDL_WindowData *)OHOS_Window->driverdata; - data->native_window = (OHNativeWindow *)(window); if (data->native_window == NULL) { SDL_SetError("Could not fetch native window from UI thread"); } } + SDL_AtomicSet(&bWindowCreateFlag, SDL_TRUE); } static void OnSurfaceChangedCB(OH_NativeXComponent *component, void *window) { diff --git a/src/video/ohos/SDL_ohoswindow.c b/src/video/ohos/SDL_ohoswindow.c index 3f59ea120efa12d8c165d7affdbed93b49853876..b84fc300af7682f6fafb856b059b27cd801c22a6 100644 --- a/src/video/ohos/SDL_ohoswindow.c +++ b/src/video/ohos/SDL_ohoswindow.c @@ -35,6 +35,7 @@ /* Currently only one window */ SDL_Window *OHOS_Window = NULL; +SDL_atomic_t bWindowCreateFlag; int OHOS_CreateWindow(_THIS, SDL_Window * window) { @@ -42,7 +43,9 @@ int OHOS_CreateWindow(_THIS, SDL_Window * window) int retval = 0; unsigned int delaytime = 0; - OHOS_PageMutex_Lock_Running(); + while (SDL_AtomicGet(&bWindowCreateFlag) == SDL_FALSE) { + SDL_Delay(2); + } if (OHOS_Window) { retval = SDL_SetError("OHOS only supports one window"); @@ -63,10 +66,7 @@ int OHOS_CreateWindow(_THIS, SDL_Window * window) retval = SDL_OutOfMemory(); goto endfunction; } - while (gNative_window == NULL && delaytime < 3000) { - delaytime += 2; - SDL_Delay(2); - } + data->native_window = gNative_window; if (!data->native_window) { diff --git a/src/video/ohos/SDL_ohoswindow.h b/src/video/ohos/SDL_ohoswindow.h index 79a819ab1f992da400fd67a97ab73bc6b7dd879e..52a808af7cef19d290d0495c77ccdc3004e4e74b 100644 --- a/src/video/ohos/SDL_ohoswindow.h +++ b/src/video/ohos/SDL_ohoswindow.h @@ -36,7 +36,7 @@ extern void OHOS_MinimizeWindow(_THIS, SDL_Window *window); extern void OHOS_DestroyWindow(_THIS, SDL_Window *window); extern SDL_bool OHOS_GetWindowWMInfo(_THIS, SDL_Window *window, struct SDL_SysWMinfo *info); extern SDL_Window *OHOS_Window; - +extern SDL_atomic_t bWindowCreateFlag; typedef struct { EGLSurface egl_surface;