From 8f7dcbe4ac77da2d5c6a0d4658ee813a17369944 Mon Sep 17 00:00:00 2001 From: Thierry Crozat Date: Sun, 5 Nov 2017 15:47:33 +0000 Subject: SUPERNOVA: Fix crash when displaying strings larger than the screen --- engines/supernova/supernova.cpp | 23 +++++++++++++++++++---- engines/supernova/supernova.h | 4 +--- 2 files changed, 20 insertions(+), 7 deletions(-) (limited to 'engines/supernova') diff --git a/engines/supernova/supernova.cpp b/engines/supernova/supernova.cpp index 291e18d964..5bc87872c5 100644 --- a/engines/supernova/supernova.cpp +++ b/engines/supernova/supernova.cpp @@ -967,16 +967,32 @@ ScreenBufferStack::ScreenBufferStack() : _last(_buffer) { } -void ScreenBufferStack::push(int x, int y, int width, int height, int pitch) { +void ScreenBufferStack::push(int x, int y, int width, int height) { if (_last == ARRAYEND(_buffer)) return; + Graphics::Surface* screenSurface = g_system->lockScreen(); + + if (x < 0) { + width += x; + x = 0; + } + if (x + width > screenSurface->w) + width = screenSurface->w - x; + + if (y < 0) { + height += y; + y = 0; + } + if (y + height > screenSurface->h) + height = screenSurface->h - y; + _last->_pixels = new byte[width * height]; byte *pixels = _last->_pixels; - const byte *screen = static_cast(g_system->lockScreen()->getBasePtr(x, y)); + const byte *screen = static_cast(screenSurface->getBasePtr(x, y)); for (int i = 0; i < height; ++i) { Common::copy(screen, screen + width, pixels); - screen += pitch; + screen += screenSurface->pitch; pixels += width; } g_system->unlockScreen(); @@ -985,7 +1001,6 @@ void ScreenBufferStack::push(int x, int y, int width, int height, int pitch) { _last->_y = y; _last->_width = width; _last->_height = height; - _last->_pitch = pitch; ++_last; } diff --git a/engines/supernova/supernova.h b/engines/supernova/supernova.h index 16c98887b0..b3ab3f45bf 100644 --- a/engines/supernova/supernova.h +++ b/engines/supernova/supernova.h @@ -55,7 +55,6 @@ struct ScreenBuffer { , _y(0) , _width(0) , _height(0) - , _pitch(0) , _pixels(NULL) {} @@ -64,13 +63,12 @@ struct ScreenBuffer { int _y; int _width; int _height; - int _pitch; }; class ScreenBufferStack { public: ScreenBufferStack(); - void push(int x, int y, int width, int height, int pitch = 320); + void push(int x, int y, int width, int height); void restore(); private: -- cgit v1.2.3