mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-18 18:30:59 +00:00
SAGA2: Add fallback for invalid sector access
This commit is contained in:
parent
91882aca4e
commit
12535d74bc
@ -794,6 +794,12 @@ public:
|
||||
void cleanup(void);
|
||||
|
||||
Sector *getSector(int16 u, int16 v) {
|
||||
if (v * sectorArraySize + u >= sectorArraySize * sectorArraySize ||
|
||||
v * sectorArraySize + u < 0) {
|
||||
warning("Sector::getSector: Invalid sector: (%d, %d)", u, v);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return &(sectorArray)[v * sectorArraySize + u];
|
||||
}
|
||||
|
||||
|
@ -969,18 +969,27 @@ uint8 ProtoObj::getDamageSound(const ObjectSoundFXs &) {
|
||||
void ProtoObj::doBackgroundUpdate(GameObject *obj) {
|
||||
TilePoint location = obj->getLocation();
|
||||
GameWorld *w = obj->world();
|
||||
int u = location.u >> kSectorShift;
|
||||
int v = location.v >> kSectorShift;
|
||||
|
||||
// XXX: Temporary crash prevention
|
||||
// We should properly solve the problem
|
||||
debug(3, "XXX: doBackgroundUpdate");
|
||||
if (location.u == -1 && location.v == -1)
|
||||
|
||||
if (w == nullptr) {
|
||||
obj->deactivate();
|
||||
return;
|
||||
}
|
||||
|
||||
Sector *sect = w->getSector(u, v);
|
||||
|
||||
if (sect == nullptr)
|
||||
return;
|
||||
|
||||
if (w == NULL
|
||||
|| !w->getSector(
|
||||
location.u >> kSectorShift,
|
||||
location.v >> kSectorShift)->isActivated())
|
||||
if (!sect->isActivated()) {
|
||||
obj->deactivate();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user