@@ -31,6 +31,8 @@ THE SOFTWARE.
3131#include " platform/CCFileUtils.h"
3232#include " platform/CCStdC.h"
3333
34+ #include < thread>
35+
3436NS_CC_BEGIN
3537
3638int Device::getDPI ()
@@ -171,16 +173,18 @@ class BitmapDC
171173 if (fontPath.size () > 0 )
172174 {
173175 _curFontPath = fontPath;
174- wchar_t * pwszBuffer = utf8ToUtf16 (_curFontPath);
175- if (pwszBuffer)
176- {
177- if (AddFontResource (pwszBuffer))
176+ std::thread ([fontPath, wnd = _wnd, this ]() {
177+ wchar_t * pwszBuffer = utf8ToUtf16 (fontPath);
178+ if (pwszBuffer)
178179 {
179- SendMessage (_wnd, WM_FONTCHANGE, 0 , 0 );
180+ if (AddFontResource (pwszBuffer))
181+ {
182+ PostMessage (wnd, WM_FONTCHANGE, 0 , 0 );
183+ }
184+ delete[] pwszBuffer;
185+ pwszBuffer = nullptr ;
180186 }
181- delete[] pwszBuffer;
182- pwszBuffer = nullptr ;
183- }
187+ }).detach ();
184188 }
185189
186190 _font = nullptr ;
@@ -428,14 +432,16 @@ class BitmapDC
428432 // release temp font resource
429433 if (_curFontPath.size () > 0 )
430434 {
431- wchar_t * pwszBuffer = utf8ToUtf16 (_curFontPath);
432- if (pwszBuffer)
433- {
434- RemoveFontResource (pwszBuffer);
435- SendMessage (_wnd, WM_FONTCHANGE, 0 , 0 );
436- delete[] pwszBuffer;
437- pwszBuffer = nullptr ;
438- }
435+ std::thread ([curFontPath = _curFontPath, wnd = _wnd, this ]() {
436+ wchar_t * pwszBuffer = utf8ToUtf16 (curFontPath);
437+ if (pwszBuffer)
438+ {
439+ RemoveFontResource (pwszBuffer);
440+ PostMessage (wnd, WM_FONTCHANGE, 0 , 0 );
441+ delete[] pwszBuffer;
442+ pwszBuffer = nullptr ;
443+ }
444+ }).detach ();
439445 _curFontPath.clear ();
440446 }
441447 }
0 commit comments