Fix concurrent access to 'g_vAllPlaylists' and 'g_vAllMaps'

This commit is contained in:
Kawe Mazidjatari 2022-08-29 11:55:58 +02:00
parent 73ff0bd0c1
commit ab8fc757c8
5 changed files with 19 additions and 2 deletions

View File

@ -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;

View File

@ -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();
}

View File

@ -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;

View File

@ -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.

View File

@ -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
//---------------------------------------------------------------------------------