From ddffce1dc547563a88388ee1bf681f2a748fb46b Mon Sep 17 00:00:00 2001 From: Thanasis Antoniou Date: Tue, 5 Mar 2019 11:19:55 +0200 Subject: BLADERUNNER: Prevent assert fault when loading actor with bad frame value Commented out assert fault in SliceAnimations::getFramePtr and sanitized the frame value instead Some actors (currently happened only with hawkers_barkeep) can have invalid frame value set when loading a save file which would cause and assert fault in the getFramePtr() assert check. This seems to be a combination of factors responsible: 1) The updateAnimation (called for an actor before drawing him into the world) has a switch clause based on animationState (not animationId) and 2) the ai_script vars for an actor are not re-initialized upon a LOAD (eg for hawkers_barkeep the _var2 value is problematic in this context because a non-zero value won't allow for sanitization of the existing / loaded frame value) --- engines/bladerunner/slice_animations.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/engines/bladerunner/slice_animations.cpp b/engines/bladerunner/slice_animations.cpp index b180e84ac0..078d51953a 100644 --- a/engines/bladerunner/slice_animations.cpp +++ b/engines/bladerunner/slice_animations.cpp @@ -168,7 +168,28 @@ void *SliceAnimations::PageFile::loadPage(uint32 pageNumber) { } void *SliceAnimations::getFramePtr(uint32 animation, uint32 frame) { - assert(frame < _animations[animation].frameCount); +#if BLADERUNNER_ORIGINAL_BUGS +#else + // FIXME: Maybe there's a better way? + // Sanitize bad frame value + // For some actors (currently only happened with hawkers_barkeep) it is possible + // to SAVE a frame value (while saving a game) + // that in conjunction with other actor script vars not being re-initialized + // upon LOADING that game (for hawkers_barkeep this variable is "_var2") + // will lead to an invalid frame here and an assertion fault (now commented out). + // Example of faulty case: + // hawkers_barkeep was SAVED as: + // (animationState, animationFrame, animationStateNext, nextAnimation) = (0, 19, 0, 0) + // while his animationID was 705 + // if _var1, _var2, _var3 == (0, 6, 1) when LOADING that save file, + // then animationFrame will remain 19, which is invalid for his 705 animation + // and the assert will produce a fault when trying to call drawInWorld for him. + if (frame >= _animations[animation].frameCount) { + debug("Bad frame: %u max: %u animation: %u", frame, _animations[animation].frameCount, animation); + frame = 0; + } +// assert(frame < _animations[animation].frameCount); +#endif // BLADERUNNER_ORIGINAL_BUGS uint32 frameOffset = _animations[animation].offset + frame * _animations[animation].frameSize; uint32 page = frameOffset / _pageSize; -- cgit v1.2.3