diff options
-rw-r--r-- | engines/sci/engine/kmovement.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/engines/sci/engine/kmovement.cpp b/engines/sci/engine/kmovement.cpp index 7f3439331e..4becc6f415 100644 --- a/engines/sci/engine/kmovement.cpp +++ b/engines/sci/engine/kmovement.cpp @@ -30,6 +30,7 @@ #include "sci/engine/selector.h" #include "sci/engine/kernel.h" #include "sci/graphics/animate.h" +#include "sci/graphics/screen.h" namespace Sci { @@ -313,8 +314,15 @@ reg_t kDoBresen(EngineState *s, int argc, reg_t *argv) { || ((y == desty) && (abs(dy) >= abs(dx))) /* Moving fast, reached? */ ))) { // Whew... in short: If we have reached or passed our target position - x = destx; - y = desty; + + // Sanity check: make sure that destx, desty are inside the screen coordinates. + // They can go off screen in some cases, e.g. in SQ5 while scrubbing the floor + if (destx < g_sci->_gfxScreen->getWidth() && desty < g_sci->_gfxScreen->getHeight()) { + x = destx; + y = desty; + } else { + warning("kDoBresen: destination x, y would be off-screen(%d, %d)", destx, desty); + } completed = 1; debugC(2, kDebugLevelBresen, "Finished mover %04x:%04x", PRINT_REG(mover)); |