summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-12-21 18:12:25 +0000
committerrubidium <rubidium@openttd.org>2009-12-21 18:12:25 +0000
commit64ac99a6c19ca82c5ca2bb78b6ed97ddc9f9b5a9 (patch)
tree7533b4e81b74fceb6145d1a4ff7cf9dc4bd94126
parent7c4e8421be406069662417a9c49dde77f679e0b5 (diff)
downloadopenttd-64ac99a6c19ca82c5ca2bb78b6ed97ddc9f9b5a9.tar.xz
(svn r18591) -Fix [FS#3399]: FindScrollbar could trigger an assert if the next widget (in the widget array) was a container-ish (e.g. selection) widget
-rw-r--r--src/widget.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/widget.cpp b/src/widget.cpp
index 3202959a7..ab540927b 100644
--- a/src/widget.cpp
+++ b/src/widget.cpp
@@ -1601,7 +1601,11 @@ NWidgetCore *NWidgetBackground::GetWidgetFromPos(int x, int y)
Scrollbar *NWidgetBackground::FindScrollbar(Window *w, bool allow_next) const
{
if (this->index >= 0 && allow_next && this->child == NULL && (uint)(this->index) + 1 < w->nested_array_size) {
- const NWidgetCore *next_wid = w->GetWidget<NWidgetCore>(this->index + 1);
+ /* GetWidget ensures that the widget is of the given type.
+ * As we might have cases where the next widget in the array
+ * is a non-Core widget (e.g. NWID_SELECTION) we first get
+ * the base class and then dynamic_cast that. */
+ const NWidgetCore *next_wid = dynamic_cast<NWidgetCore>(w->GetWidget<NWidgetBase>(this->index + 1));
if (next_wid != NULL) return next_wid->FindScrollbar(w, false);
}
return NULL;