From b53f6473156902c0528f4eb5c5d9df38af8ded81 Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Sun, 14 Apr 2013 20:11:14 +0300 Subject: [PATCH] Fix race condition causing possible crash on startup --- src/platform/wxwidgets/mainwindow.cpp | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/platform/wxwidgets/mainwindow.cpp b/src/platform/wxwidgets/mainwindow.cpp index 6b1ea2b9..e730e372 100644 --- a/src/platform/wxwidgets/mainwindow.cpp +++ b/src/platform/wxwidgets/mainwindow.cpp @@ -782,34 +782,42 @@ void wxwin_mainwindow::notify_exit() throw() Destroy(); } +std::string read_variable_map(const std::map& vars, const std::string& key) +{ + if(!vars.count(key)) + return ""; + return vars.find(key)->second; +} + void wxwin_mainwindow::update_statusbar(const std::map& vars) { if(vars.empty()) return; try { std::ostringstream s; - bool recording = (vars.find("!mode")->second == "R"); + bool recording = (read_variable_map(vars, "!mode") == "R"); if(recording) - s << "Frame: " << vars.find("!frame")->second; + s << "Frame: " << read_variable_map(vars, "!frame"); else - s << "Frame: " << vars.find("!frame")->second << "/" << vars.find("!length")->second; - s << " Lag: " << vars.find("!lag")->second; - s << " Subframe: " << vars.find("!subframe")->second; + s << "Frame: " << read_variable_map(vars, "!frame") << "/" << + read_variable_map(vars, "!length"); + s << " Lag: " << read_variable_map(vars, "!lag"); + s << " Subframe: " << read_variable_map(vars, "!subframe"); if(vars.count("!saveslot")) - s << " Slot: " << vars.find("!saveslot")->second; + s << " Slot: " << read_variable_map(vars, "!saveslot"); if(vars.count("!saveslotinfo")) - s << " [" << vars.find("!saveslotinfo")->second << "]"; - s << " Speed: " << vars.find("!speed")->second << "%"; + s << " [" << read_variable_map(vars, "!saveslotinfo") << "]"; + s << " Speed: " << read_variable_map(vars, "!speed") << "%"; s << " "; - if(vars.find("!dumping")->second != "") + if(read_variable_map(vars, "!dumping") != "") s << " Dumping"; - if(vars.find("!mode")->second == "C") + if(read_variable_map(vars, "!mode") == "C") s << " Corrupt"; - else if(vars.find("!mode")->second == "R") + else if(read_variable_map(vars, "!mode") == "R") s << " Recording"; - else if(vars.find("!mode")->second == "P") + else if(read_variable_map(vars, "!mode") == "P") s << " Playback"; - else if(vars.find("!mode")->second == "F") + else if(read_variable_map(vars, "!mode") == "F") s << " Finished"; else s << " Unknown"; -- 2.11.4.GIT