Skip to content

Commit

Permalink
fixup segfaults in replay viewer
Browse files Browse the repository at this point in the history
After this commit e4eb0a3 the
replay viewer would segfault during prestart events. However, it
turns out that nothing in the replay viewer, or in that commit,
was directly causing the segault. Instead, the display object
was holding dangling pointers for no reason, when it could have.
been simply computing the correct value (very cheaply). We clean
up the code in the display objects to fix the segfault.
  • Loading branch information
cbeck88 committed Jun 15, 2014
1 parent 74e1230 commit 926effb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/display.cpp
Expand Up @@ -143,7 +143,7 @@ display::display(const display_context * dc, CVideo& video, boost::weak_ptr<wb::
exclusive_unit_draw_requests_(),
screen_(video),
currentTeam_(0),
viewpoint_(NULL),
dont_show_all_(false),
energy_bar_rects_(),
xpos_(0),
ypos_(0),
Expand Down Expand Up @@ -357,12 +357,12 @@ void display::set_team(size_t teamindex, bool show_everything)
if (!show_everything)
{
labels().set_team(&dc_->teams()[teamindex]);
viewpoint_ = &dc_->teams()[teamindex];
dont_show_all_ = true;
}
else
{
labels().set_team(NULL);
viewpoint_ = NULL;
dont_show_all_ = false;
}
labels().recalculate_labels();
if(boost::shared_ptr<wb::manager> w = wb_.lock())
Expand Down Expand Up @@ -1848,7 +1848,7 @@ void display::draw_minimap()
}

if(minimap_ == NULL || minimap_->w > area.w || minimap_->h > area.h) {
minimap_ = image::getMinimap(area.w, area.h, get_map(), viewpoint_, (selectedHex_.valid() && !is_blindfolded()) ? &reach_map_ : NULL);
minimap_ = image::getMinimap(area.w, area.h, get_map(), &dc_->teams()[currentTeam_], (selectedHex_.valid() && !is_blindfolded()) ? &reach_map_ : NULL);
if(minimap_ == NULL) {
return;
}
Expand Down
8 changes: 4 additions & 4 deletions src/display.hpp
Expand Up @@ -73,7 +73,7 @@ class display
virtual ~display();
static display* get_singleton() { return singleton_ ;}

bool show_everything() const { return !viewpoint_ && !is_blindfolded(); }
bool show_everything() const { return !dont_show_all_ && !is_blindfolded(); }

const gamemap& get_map() const { return dc_->map(); }

Expand Down Expand Up @@ -336,11 +336,11 @@ class display

/** Returns true if location (x,y) is covered in shroud. */
bool shrouded(const map_location& loc) const {
return is_blindfolded() || (viewpoint_ && viewpoint_->shrouded(loc));
return is_blindfolded() || (dont_show_all_ && dc_->teams()[currentTeam_].shrouded(loc));
}
/** Returns true if location (x,y) is covered in fog. */
bool fogged(const map_location& loc) const {
return is_blindfolded() || (viewpoint_ && viewpoint_->fogged(loc));
return is_blindfolded() || (dont_show_all_ && dc_->teams()[currentTeam_].fogged(loc));
}

/**
Expand Down Expand Up @@ -731,7 +731,7 @@ class display

CVideo& screen_;
size_t currentTeam_;
const team *viewpoint_;
bool dont_show_all_; //const team *viewpoint_;
std::map<surface,SDL_Rect> energy_bar_rects_;
int xpos_, ypos_;
bool view_locked_;
Expand Down
6 changes: 3 additions & 3 deletions src/game_display.cpp
Expand Up @@ -165,12 +165,12 @@ void game_display::highlight_hex(map_location hex)
{
wb::future_map future; /**< Lasts for whole method. */

const unit *u = resources::gameboard->get_visible_unit(hex, dc_->teams()[viewing_team()], !viewpoint_);
const unit *u = resources::gameboard->get_visible_unit(hex, dc_->teams()[viewing_team()], !dont_show_all_);
if (u) {
displayedUnitHex_ = hex;
invalidate_unit();
} else {
u = resources::gameboard->get_visible_unit(mouseoverHex_, dc_->teams()[viewing_team()], !viewpoint_);
u = resources::gameboard->get_visible_unit(mouseoverHex_, dc_->teams()[viewing_team()], !dont_show_all_);
if (u) {
// mouse moved from unit hex to non-unit hex
if (dc_->units().count(selectedHex_)) {
Expand All @@ -192,7 +192,7 @@ void game_display::display_unit_hex(map_location hex)

wb::future_map future; /**< Lasts for whole method. */

const unit *u = resources::gameboard->get_visible_unit(hex, dc_->teams()[viewing_team()], !viewpoint_);
const unit *u = resources::gameboard->get_visible_unit(hex, dc_->teams()[viewing_team()], !dont_show_all_);
if (u) {
displayedUnitHex_ = hex;
invalidate_unit();
Expand Down

0 comments on commit 926effb

Please sign in to comment.