mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Fix concurrent access to 'g_vAllPlaylists' and 'g_vAllMaps'
This commit is contained in:
parent
73ff0bd0c1
commit
ab8fc757c8
@ -35,6 +35,8 @@ bool MOD_LevelHasChanged(const string& svLevelName)
|
||||
//-----------------------------------------------------------------------------
|
||||
void MOD_GetAllInstalledMaps()
|
||||
{
|
||||
std::lock_guard<std::mutex> l(g_MapVecMutex);
|
||||
|
||||
if (!g_vAllMaps.empty())
|
||||
return;
|
||||
|
||||
|
@ -393,25 +393,31 @@ void CBrowser::HostPanel(void)
|
||||
|
||||
if (ImGui::BeginCombo("Playlist", g_pServerListManager->m_Server.m_svPlaylist.c_str()))
|
||||
{
|
||||
for (auto& item : g_vAllPlaylists)
|
||||
g_PlaylistsVecMutex.lock();
|
||||
for (const string& item : g_vAllPlaylists)
|
||||
{
|
||||
if (ImGui::Selectable(item.c_str(), item == g_pServerListManager->m_Server.m_svPlaylist))
|
||||
{
|
||||
g_pServerListManager->m_Server.m_svPlaylist = item;
|
||||
}
|
||||
}
|
||||
|
||||
g_PlaylistsVecMutex.unlock();
|
||||
ImGui::EndCombo();
|
||||
}
|
||||
|
||||
if (ImGui::BeginCombo("Map##ServerHost_MapListBox", g_pServerListManager->m_Server.m_svHostMap.c_str()))
|
||||
{
|
||||
for (auto& item : g_vAllMaps)
|
||||
g_MapVecMutex.lock();
|
||||
for (const string& item : g_vAllMaps)
|
||||
{
|
||||
if (ImGui::Selectable(item.c_str(), item == g_pServerListManager->m_Server.m_svHostMap))
|
||||
{
|
||||
g_pServerListManager->m_Server.m_svHostMap = item;
|
||||
}
|
||||
}
|
||||
|
||||
g_MapVecMutex.unlock();
|
||||
ImGui::EndCombo();
|
||||
}
|
||||
|
||||
|
@ -53,6 +53,8 @@ namespace VSquirrel
|
||||
//-----------------------------------------------------------------------------
|
||||
SQRESULT GetAvailableMaps(HSQUIRRELVM v)
|
||||
{
|
||||
std::lock_guard<std::mutex> l(g_MapVecMutex);
|
||||
|
||||
if (g_vAllMaps.empty())
|
||||
return SQ_OK;
|
||||
|
||||
@ -71,6 +73,8 @@ namespace VSquirrel
|
||||
//-----------------------------------------------------------------------------
|
||||
SQRESULT GetAvailablePlaylists(HSQUIRRELVM v)
|
||||
{
|
||||
std::lock_guard<std::mutex> l(g_PlaylistsVecMutex);
|
||||
|
||||
if (g_vAllPlaylists.empty())
|
||||
return SQ_OK;
|
||||
|
||||
|
@ -1222,7 +1222,9 @@ void KeyValues::InitPlaylists(void)
|
||||
KeyValues* pPlaylists = (*g_pPlaylistKeyValues)->FindKey("Playlists", false);
|
||||
if (pPlaylists)
|
||||
{
|
||||
std::lock_guard<std::mutex> l(g_PlaylistsVecMutex);
|
||||
g_vAllPlaylists.clear();
|
||||
|
||||
for (KeyValues* pSubKey = pPlaylists->GetFirstTrueSubKey(); pSubKey != nullptr; pSubKey = pSubKey->GetNextTrueSubKey())
|
||||
{
|
||||
g_vAllPlaylists.push_back(pSubKey->GetName()); // Get all playlists.
|
||||
|
@ -7,6 +7,9 @@
|
||||
extern vector<string> g_vAllPlaylists;
|
||||
extern vector<string> g_vGameInfoPaths;
|
||||
|
||||
inline std::mutex g_MapVecMutex;
|
||||
inline std::mutex g_PlaylistsVecMutex;
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
// Purpose: Forward declarations
|
||||
//---------------------------------------------------------------------------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user