Author: mordante
Date: Sun Mar 6 15:14:09 2011
New Revision: 48785
URL: http://svn.gna.org/viewcvs/wesnoth?rev=48785&view=rev
Log:
Avoid deferring NULL pointers.
Several pointers are NULL when running from the unit tests, these were
deferred without testing.
Modified:
trunk/src/gui/dialogs/gamestate_inspector.cpp
Modified: trunk/src/gui/dialogs/gamestate_inspector.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/dialogs/gamestate_inspector.cpp?rev=48785&r1=48784&r2=48785&view=diff
==============================================================================
--- trunk/src/gui/dialogs/gamestate_inspector.cpp (original)
+++ trunk/src/gui/dialogs/gamestate_inspector.cpp Sun Mar 6 15:14:09 2011
@@ -178,7 +178,10 @@
{
model_.clear_stuff_list();
- const config &vars = resources::state_of_game->get_variables();
+ const config &vars = resources::state_of_game
+ ? resources::state_of_game->get_variables()
+ : config();
+
foreach( const config::attribute &a, vars.attribute_range()) {
model_.add_row_to_stuff_list(a.first,a.first);
}
@@ -200,7 +203,9 @@
}
int i = 0;///@todo replace with precached data
- const config &vars = resources::state_of_game->get_variables();
+ const config &vars = resources::state_of_game
+ ? resources::state_of_game->get_variables()
+ : config();
foreach( const config::attribute &a, vars.attribute_range()) {
if (selected==i) {
@@ -239,25 +244,30 @@
{
model_.clear_stuff_list();
- for(unit_map::iterator i = resources::units->begin(); i !=
resources::units->end(); ++i) {
- std::stringstream s;
- s << '(' << i->get_location();
- s << ") side=" << i->side() << ' ';
- if (i->can_recruit()) {
- s << "LEADER ";
+ if(resources::units) {
+ for(unit_map::iterator i = resources::units->begin()
+ ; i != resources::units->end()
+ ; ++i) {
+
+ std::stringstream s;
+ s << '(' << i->get_location();
+ s << ") side=" << i->side() << ' ';
+ if (i->can_recruit()) {
+ s << "LEADER ";
+ }
+
+ s << "id=[" << i->id() << "] " << i->type_id()
+ << "; L" << i->level()<< "; " <<
i->experience()
+ << '/' << i->max_experience() << " xp; "
+ << i->hitpoints() << '/' <<
i->max_hitpoints()
+ << " hp; ";
+ foreach (const std::string &str,
i->get_traits_list()) {
+ s << str <<" ";
+ }
+
+ std::string key = s.str();
+ model_.add_row_to_stuff_list(key,key);
}
-
- s << "id=[" << i->id() << "] " << i->type_id()
- << "; L" << i->level()<< "; " << i->experience()
- << '/' << i->max_experience() << " xp; "
- << i->hitpoints() << '/' << i->max_hitpoints()
- << " hp; ";
- foreach (const std::string &str, i->get_traits_list()) {
- s << str <<" ";
- }
-
- std::string key = s.str();
- model_.add_row_to_stuff_list(key,key);
}
model_.set_inspect_window_text("");
@@ -273,14 +283,18 @@
}
int i = 0;///@todo replace with precached data
- for(unit_map::iterator u = resources::units->begin(); u !=
resources::units->end(); ++u) {
- if (selected==i) {
- config c_unit;
- u->write(c_unit);
- model_.set_inspect_window_text(c_unit.debug());
- return;
+ if(resources::units) {
+ for(unit_map::iterator u = resources::units->begin()
+ ; u != resources::units->end()
+ ; ++u) {
+ if (selected==i) {
+ config c_unit;
+ u->write(c_unit);
+
model_.set_inspect_window_text(c_unit.debug());
+ return;
+ }
+ i++;
}
- i++;
}
model_.set_inspect_window_text("");
@@ -325,7 +339,9 @@
}
if (selected==0) {
- config c = resources::teams->at(side_-1).to_config();
+ config c = resources::teams
+ ?
resources::teams->at(side_-1).to_config()
+ : config();
c.clear_children("ai");
c.clear_children("village");
c.remove_attribute("shroud_data");
@@ -344,7 +360,10 @@
}
if (selected==3) {
- const std::vector<unit> recall_list =
resources::teams->at(side_-1).recall_list();
+ const std::vector<unit> recall_list = resources::teams
+ ?
resources::teams->at(side_-1).recall_list()
+ : std::vector<unit>();
+
std::stringstream s;
foreach (const unit &u, recall_list) {
s << "id=["<<u.id() << "] "<<u.type_id() << ";
L"<<u.level()<<"; " << u.experience() <<"/" << u.max_experience()<< " xp "<<
std::endl;
@@ -358,7 +377,10 @@
}
if (selected==4) {
- const std::vector<unit> recall_list =
resources::teams->at(side_-1).recall_list();
+ const std::vector<unit> recall_list = resources::teams
+ ?
resources::teams->at(side_-1).recall_list()
+ : std::vector<unit>();
+
config c;
foreach (const unit &u, recall_list) {
config c_unit;
@@ -377,25 +399,29 @@
if (selected==6) {
std::stringstream s;
- for(unit_map::iterator i = resources::units->begin(); i
!= resources::units->end(); ++i) {
- if (i->side()!=side_) {
- continue;
+ if(resources::units) {
+ for(unit_map::iterator i =
resources::units->begin()
+ ; i != resources::units->end()
+ ; ++i) {
+ if (i->side()!=side_) {
+ continue;
+ }
+ s << i->get_location();
+ if (i->can_recruit()) {
+ s << " LEADER ";
+ }
+
+ s << "id=[" << i->id() << "] " <<
i->type_id()
+ << "; L" << i->level()<< "; "
+ << i->experience() << '/'
+ << i->max_experience() << " xp;
"
+ << i->hitpoints() << '/'
+ << i->max_hitpoints()<<" hp.\n";
+ foreach (const std::string &str,
i->get_traits_list() ) {
+ s << "\t" << str<< std::endl;
+ }
+ s << std::endl << std::endl;
}
- s << i->get_location();
- if (i->can_recruit()) {
- s << " LEADER ";
- }
-
- s << "id=[" << i->id() << "] " << i->type_id()
- << "; L" << i->level()<< "; "
- << i->experience() << '/'
- << i->max_experience() << " xp; "
- << i->hitpoints() << '/'
- << i->max_hitpoints()<<" hp.\n";
- foreach (const std::string &str,
i->get_traits_list() ) {
- s << "\t" << str<< std::endl;
- }
- s << std::endl << std::endl;
}
model_.set_inspect_window_text(s.str());
return;
@@ -426,7 +452,9 @@
sm_controllers_.push_back(
boost::shared_ptr<single_mode_controller>(new
unit_mode_controller("units",model_)));
//foreach team
- int sides = static_cast<int>((*resources::teams).size());
+ int sides = resources::teams
+ ? static_cast<int>((*resources::teams).size())
+ : 0;
for( int side = 1; side<=sides; ++side) {
std::string side_str = str_cast(side);
sm_controllers_.push_back(boost::shared_ptr<single_mode_controller>(
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits