소스 검색

[macOS] text input handling must be done on main thread

Xcode's Main Thread Checker warns about that
Andrey Filipenkov 3 년 전
부모
커밋
7150ee565a
1개의 변경된 파일20개의 추가작업 그리고 0개의 파일을 삭제
  1. 20 0
      client/gui/SDL_Extensions.cpp

+ 20 - 0
client/gui/SDL_Extensions.cpp

@@ -16,6 +16,10 @@
 #include "../Graphics.h"
 #include "../CMT.h"
 
+#ifdef VCMI_APPLE
+#include <dispatch/dispatch.h>
+#endif
+
 const SDL_Color Colors::YELLOW = { 229, 215, 123, 0 };
 const SDL_Color Colors::WHITE = { 255, 243, 222, 0 };
 const SDL_Color Colors::METALLIC_GOLD = { 173, 142, 66, 0 };
@@ -786,19 +790,35 @@ SDL_Color CSDL_Ext::makeColor(ui8 r, ui8 g, ui8 b, ui8 a)
 
 void CSDL_Ext::startTextInput(SDL_Rect * where)
 {
+#ifdef VCMI_APPLE
+	dispatch_async(dispatch_get_main_queue(), ^{
+#endif
+
 	if (SDL_IsTextInputActive() == SDL_FALSE)
 	{
 		SDL_StartTextInput();
 	}
 	SDL_SetTextInputRect(where);
+
+#ifdef VCMI_APPLE
+	});
+#endif
 }
 
 void CSDL_Ext::stopTextInput()
 {
+#ifdef VCMI_APPLE
+	dispatch_async(dispatch_get_main_queue(), ^{
+#endif
+
 	if (SDL_IsTextInputActive() == SDL_TRUE)
 	{
 		SDL_StopTextInput();
 	}
+
+#ifdef VCMI_APPLE
+	});
+#endif
 }
 
 STRONG_INLINE static uint32_t mapColor(SDL_Surface * surface, SDL_Color color)