mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-10 20:38:19 +00:00
graceful error handling for invalid color ranges
(note: this means you must check stdout.txt for error message)
This commit is contained in:
parent
be0c4df7d0
commit
faf815ae72
@ -24,6 +24,7 @@
|
|||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#define LOG_NG LOG_STREAM(info, engine)
|
#define LOG_NG LOG_STREAM(info, engine)
|
||||||
|
#define ERR_NG LOG_STREAM(err, engine)
|
||||||
|
|
||||||
namespace game_config
|
namespace game_config
|
||||||
{
|
{
|
||||||
@ -225,6 +226,7 @@ namespace game_config
|
|||||||
team_rgb_colors.insert(std::make_pair(rgb_it->first,string2rgb(rgb_it->second)));
|
team_rgb_colors.insert(std::make_pair(rgb_it->first,string2rgb(rgb_it->second)));
|
||||||
} catch(bad_lexical_cast&) {
|
} catch(bad_lexical_cast&) {
|
||||||
//throw config::error(_("Invalid team color: ") + rgb_it->second);
|
//throw config::error(_("Invalid team color: ") + rgb_it->second);
|
||||||
|
ERR_NG << "Invalid team color: " << rgb_it->second;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -238,6 +240,8 @@ namespace game_config
|
|||||||
team_rgb_range.insert(std::make_pair(name,color_range(string2rgb(name))));
|
team_rgb_range.insert(std::make_pair(name,color_range(string2rgb(name))));
|
||||||
return color_info(name);
|
return color_info(name);
|
||||||
} catch(bad_lexical_cast&) {
|
} catch(bad_lexical_cast&) {
|
||||||
|
//ERR_NG << "Invalid color range: " << name;
|
||||||
|
//return color_info();
|
||||||
throw config::error(_("Invalid color range: ") + name);
|
throw config::error(_("Invalid color range: ") + name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -254,6 +258,7 @@ namespace game_config
|
|||||||
} catch(bad_lexical_cast&) {
|
} catch(bad_lexical_cast&) {
|
||||||
static std::vector<Uint32> stv;
|
static std::vector<Uint32> stv;
|
||||||
//throw config::error(_("Invalid team color: ") + name);
|
//throw config::error(_("Invalid team color: ") + name);
|
||||||
|
ERR_NG << "Invalid team color: " << name;
|
||||||
return stv;
|
return stv;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -341,9 +341,14 @@ surface locator::load_image_sub_file() const
|
|||||||
if("RC" == function){ //re-color function
|
if("RC" == function){ //re-color function
|
||||||
std::vector<std::string> recolor=utils::split(field,'>');
|
std::vector<std::string> recolor=utils::split(field,'>');
|
||||||
if(recolor.size()>1){
|
if(recolor.size()>1){
|
||||||
color_range const& new_color = game_config::color_info(recolor[1]);
|
std::map<Uint32, Uint32> tmp_map;
|
||||||
std::vector<Uint32> const& old_color = game_config::tc_info(recolor[0]);
|
try {
|
||||||
std::map<Uint32, Uint32> tmp_map = recolor_range(new_color,old_color);
|
color_range const& new_color = game_config::color_info(recolor[1]);
|
||||||
|
std::vector<Uint32> const& old_color = game_config::tc_info(recolor[0]);
|
||||||
|
tmp_map = recolor_range(new_color,old_color);
|
||||||
|
} catch (config::error& e) {
|
||||||
|
ERR_DP << "caught config::error... " << e.message << std::endl;
|
||||||
|
}
|
||||||
for(std::map<Uint32, Uint32>::const_iterator tmp = tmp_map.begin(); tmp!= tmp_map.end(); tmp++){
|
for(std::map<Uint32, Uint32>::const_iterator tmp = tmp_map.begin(); tmp!= tmp_map.end(); tmp++){
|
||||||
recolor_map[tmp->first] = tmp->second;
|
recolor_map[tmp->first] = tmp->second;
|
||||||
}
|
}
|
||||||
|
@ -389,6 +389,10 @@ LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_
|
|||||||
} catch(gamemap::incorrect_format_exception& e) {
|
} catch(gamemap::incorrect_format_exception& e) {
|
||||||
gui::show_error_message(disp, std::string(_("The game map could not be loaded: ")) + e.msg_);
|
gui::show_error_message(disp, std::string(_("The game map could not be loaded: ")) + e.msg_);
|
||||||
return QUIT;
|
return QUIT;
|
||||||
|
} catch(config::error& e) {
|
||||||
|
std::cerr << "caught config::error...\n";
|
||||||
|
gui::show_error_message(disp, _("Error while reading the WML: ") + e.message);
|
||||||
|
return QUIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
//if the scenario hasn't been set in-level, set it now.
|
//if the scenario hasn't been set in-level, set it now.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user