summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-03-03 20:33:57 +0000
committerrubidium <rubidium@openttd.org>2009-03-03 20:33:57 +0000
commit2972ad372b790e4fe66270d97b223905aa5ffe42 (patch)
treeb17b45f0114f34b3a8c0a57eac16aecbf77681d6
parent08cf37ccc220a37165a118863d4d2ecac80927c2 (diff)
downloadopenttd-2972ad372b790e4fe66270d97b223905aa5ffe42.tar.xz
(svn r15603) -Fix [FS#2696]: crash when using an extraordinarily large sprite as cursor.
-rw-r--r--src/core/alloc_type.hpp9
-rw-r--r--src/gfx.cpp8
2 files changed, 13 insertions, 4 deletions
diff --git a/src/core/alloc_type.hpp b/src/core/alloc_type.hpp
index 887ba7237..b95fc79ee 100644
--- a/src/core/alloc_type.hpp
+++ b/src/core/alloc_type.hpp
@@ -123,6 +123,15 @@ public:
}
return this->buffer;
}
+
+ /**
+ * Get the currently allocated buffer.
+ * @return the buffer
+ */
+ FORCEINLINE const T *GetBuffer() const
+ {
+ return this->buffer;
+ }
};
/**
diff --git a/src/gfx.cpp b/src/gfx.cpp
index 07cb70bac..a69654ca1 100644
--- a/src/gfx.cpp
+++ b/src/gfx.cpp
@@ -52,7 +52,7 @@ static int ReallyDoDrawString(const char *string, int x, int y, TextColour colou
FontSize _cur_fontsize;
static FontSize _last_fontsize;
-static uint8 _cursor_backup[64 * 64 * 4];
+static ReusableBuffer<uint8> _cursor_backup;
/**
* The rect for repaint.
@@ -1288,7 +1288,7 @@ void UndrawMouseCursor()
if (_cursor.visible) {
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
_cursor.visible = false;
- blitter->CopyFromBuffer(blitter->MoveTo(_screen.dst_ptr, _cursor.draw_pos.x, _cursor.draw_pos.y), _cursor_backup, _cursor.draw_size.x, _cursor.draw_size.y);
+ blitter->CopyFromBuffer(blitter->MoveTo(_screen.dst_ptr, _cursor.draw_pos.x, _cursor.draw_pos.y), _cursor_backup.GetBuffer(), _cursor.draw_size.x, _cursor.draw_size.y);
_video_driver->MakeDirty(_cursor.draw_pos.x, _cursor.draw_pos.y, _cursor.draw_size.x, _cursor.draw_size.y);
}
}
@@ -1337,10 +1337,10 @@ void DrawMouseCursor()
_cursor.draw_pos.y = y;
_cursor.draw_size.y = h;
- assert(blitter->BufferSize(w, h) < (int)sizeof(_cursor_backup));
+ uint8 *buffer = _cursor_backup.Allocate(blitter->BufferSize(w, h));
/* Make backup of stuff below cursor */
- blitter->CopyToBuffer(blitter->MoveTo(_screen.dst_ptr, _cursor.draw_pos.x, _cursor.draw_pos.y), _cursor_backup, _cursor.draw_size.x, _cursor.draw_size.y);
+ blitter->CopyToBuffer(blitter->MoveTo(_screen.dst_ptr, _cursor.draw_pos.x, _cursor.draw_pos.y), buffer, _cursor.draw_size.x, _cursor.draw_size.y);
/* Draw cursor on screen */
_cur_dpi = &_screen;