summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/teleport.cc
diff options
context:
space:
mode:
authorMatthew Cline <zelgadis@sourceforge.net>2009-11-14 22:21:58 -0800
committerMatthew Cline <zelgadis@sourceforge.net>2009-11-15 01:20:33 -0800
commit6cda5fe31dffd0c018008e0e5d8921f9c0cc8a43 (patch)
tree85890733977b6f8e4f103045693c468d49a56261 /crawl-ref/source/teleport.cc
parenta04238cb7b08fd82298442f2eb14fbc9c922a98b (diff)
downloadcrawl-ref-6cda5fe31dffd0c018008e0e5d8921f9c0cc8a43.tar.gz
crawl-ref-6cda5fe31dffd0c018008e0e5d8921f9c0cc8a43.zip
teleport.cc: hack to deal with memory bug
random_space_weighted() sometimes gets this weird memory bug which causes the return value to be random (and usually out-of-bounds). "Fixed" by testing the result against in_bounds()
Diffstat (limited to 'crawl-ref/source/teleport.cc')
-rw-r--r--crawl-ref/source/teleport.cc18
1 files changed, 14 insertions, 4 deletions
diff --git a/crawl-ref/source/teleport.cc b/crawl-ref/source/teleport.cc
index 8b96ed6b35..aafc685583 100644
--- a/crawl-ref/source/teleport.cc
+++ b/crawl-ref/source/teleport.cc
@@ -68,6 +68,9 @@ typedef std::pair<coord_def, int> coord_weight;
// Try to find a "safe" place for moved close or far from the target.
// keep_los indicates that the destination should be in view of the target.
+//
+// XXX: Check the result against in_bounds(), not coord_def::origin(),
+// beceause of a memory problem described below.
static coord_def random_space_weighted(actor* moved, actor* target,
bool close, bool keep_los = true,
bool allow_sanct = true)
@@ -95,6 +98,13 @@ static coord_def random_space_weighted(actor* moved, actor* target,
weight = 0;
dests.push_back(coord_weight(*ri, weight));
}
+
+ // XXX: Sometimes this results in a memory problem, where it seems as
+ // if the dests vector is free'd before copying the result. When
+ // this happens, an out-of-bounds coordinate is usually returned.
+ //
+ // This is with GCC 4.4.1, -O2, 32 bit Linux, -march-native on a
+ // Family 10 AMD chip.
coord_def* choice = random_choose_weighted(dests);
return (choice ? *choice : coord_def(0, 0));
}
@@ -108,7 +118,7 @@ void blink_other_close(actor* victim, const coord_def &target)
if (is_sanctuary(you.pos()))
return;
coord_def dest = random_space_weighted(victim, caster, true);
- if (dest.origin())
+ if (!in_bounds(dest))
return;
bool success = victim->blink_to(dest);
ASSERT(success);
@@ -121,7 +131,7 @@ void blink_away(monsters* mon)
if (!foe || !mon->can_see(foe))
return;
coord_def dest = random_space_weighted(mon, foe, false, false);
- if (dest.origin())
+ if (!in_bounds(dest))
return;
bool success = mon->blink_to(dest);
ASSERT(success);
@@ -134,7 +144,7 @@ void blink_range(monsters* mon)
if (!foe || !mon->can_see(foe))
return;
coord_def dest = random_space_weighted(mon, foe, false, true);
- if (dest.origin())
+ if (!in_bounds(dest))
return;
bool success = mon->blink_to(dest);
ASSERT(success);
@@ -147,7 +157,7 @@ void blink_close(monsters* mon)
if (!foe || !mon->can_see(foe))
return;
coord_def dest = random_space_weighted(mon, foe, true);
- if (dest.origin())
+ if (!in_bounds(dest))
return;
bool success = mon->blink_to(dest);
ASSERT(success);