Skip to content

Commit e49a267

Browse files
committed
Fixed minor threading issues
1 parent 2101563 commit e49a267

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

MTA10/core/CWebCore.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ void CWebCore::AddEventToEventQueue ( std::function<void(void)> event, CWebView*
142142
#ifndef MTA_DEBUG
143143
UNREFERENCED_PARAMETER(name);
144144
#endif
145-
if ( pWebView->IsBeingDestroyed () )
145+
if ( pWebView && pWebView->IsBeingDestroyed () )
146146
return;
147147

148148
std::lock_guard<std::mutex> lock ( m_EventQueueMutex );
@@ -206,12 +206,12 @@ eURLState CWebCore::GetURLState ( const SString& strURL, bool bOutputDebug )
206206
return eURLState::WEBPAGE_ALLOWED;
207207
else
208208
{
209-
if ( m_bTestmodeEnabled && bOutputDebug ) g_pCore->DebugPrintfColor ( "[BROWSER] Blocked page: %s", 255, 0, 0, strURL.c_str() );
209+
if ( m_bTestmodeEnabled && bOutputDebug ) DebugOutputThreadsafe ( SString ( "[BROWSER] Blocked page: %s", strURL.c_str () ), 255, 0, 0 );
210210
return eURLState::WEBPAGE_DISALLOWED;
211211
}
212212
}
213213

214-
if ( m_bTestmodeEnabled && bOutputDebug ) g_pCore->DebugPrintfColor ( "[BROWSER] Blocked page: %s", 255, 0, 0, strURL.c_str() );
214+
if ( m_bTestmodeEnabled && bOutputDebug ) DebugOutputThreadsafe ( SString ( "[BROWSER] Blocked page: %s", strURL.c_str () ), 255, 0, 0 );
215215
return eURLState::WEBPAGE_NOT_LISTED;
216216
}
217217

@@ -372,6 +372,13 @@ bool CWebCore::IsRequestsGUIVisible ()
372372
return m_pRequestsGUI && m_pRequestsGUI->IsVisible ();
373373
}
374374

375+
void CWebCore::DebugOutputThreadsafe ( const SString& message, unsigned char R, unsigned char G, unsigned char B )
376+
{
377+
AddEventToEventQueue( [message, R, G, B]() {
378+
g_pCore->DebugEchoColor ( message, R, G, B );
379+
}, nullptr, "DebugOutputThreadsafe" );
380+
}
381+
375382
bool CWebCore::GetRemotePagesEnabled ()
376383
{
377384
bool bCanLoadRemotePages;

MTA10/core/CWebCore.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class CWebCore : public CWebCoreInterface
7272

7373
inline bool IsTestModeEnabled () { return m_bTestmodeEnabled; };
7474
inline void SetTestModeEnabled ( bool bEnabled ) { m_bTestmodeEnabled = bEnabled; };
75+
void DebugOutputThreadsafe ( const SString& message, unsigned char R, unsigned char G, unsigned char B );
7576

7677
inline CWebViewInterface* GetFocusedWebView () { return (CWebViewInterface*) m_pFocusedWebView; };
7778
inline void SetFocusedWebView ( CWebView* pWebView ) { m_pFocusedWebView = pWebView; };

0 commit comments

Comments
 (0)