Remove limit in size of widget_table
It is difficult, but possible, to exceed 1024 widgets. One way is to set a very large Unicode symbol set, and then use #wizcustom. As there is no limit to how many objects can occupy a square, this limit is a possible hazard even to a normal game.
This commit is contained in:
+10
-7
@@ -610,9 +610,9 @@ typedef struct WidgetBucket {
|
|||||||
WidgetData *data;
|
WidgetData *data;
|
||||||
} WidgetBucket;
|
} WidgetBucket;
|
||||||
|
|
||||||
#define MAX_WIDGETS 1024
|
static WidgetBucket *widget_table = NULL;
|
||||||
static WidgetBucket widget_table[MAX_WIDGETS];
|
static unsigned num_widgets = 0;
|
||||||
static unsigned num_widgets;
|
static unsigned max_widgets = 0;
|
||||||
|
|
||||||
/* bsearch compare function to search widget-table */
|
/* bsearch compare function to search widget-table */
|
||||||
static int
|
static int
|
||||||
@@ -653,9 +653,12 @@ get_widget_data(Widget w)
|
|||||||
static WidgetData *
|
static WidgetData *
|
||||||
add_widget(Widget w)
|
add_widget(Widget w)
|
||||||
{
|
{
|
||||||
/* Panic rather than overflow the array */
|
/* If the array is full (or unallocated), add some new space to it */
|
||||||
if (num_widgets >= MAX_WIDGETS) {
|
if (num_widgets >= max_widgets) {
|
||||||
panic("Widget table is full\n");
|
max_widgets = num_widgets + 1024;
|
||||||
|
widget_table = (WidgetBucket *) re_alloc(
|
||||||
|
(long *) widget_table,
|
||||||
|
max_widgets * sizeof(widget_table[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Insert the widget into the table, maintaining its order */
|
/* Insert the widget into the table, maintaining its order */
|
||||||
@@ -688,7 +691,7 @@ delete_widget(Widget w)
|
|||||||
|
|
||||||
/* Remove the widget from the table */
|
/* Remove the widget from the table */
|
||||||
for (unsigned i = (unsigned)(bucket - widget_table);
|
for (unsigned i = (unsigned)(bucket - widget_table);
|
||||||
i + 1 < MAX_WIDGETS;
|
i + 1 < num_widgets;
|
||||||
++i) {
|
++i) {
|
||||||
widget_table[i] = widget_table[i+1];
|
widget_table[i] = widget_table[i+1];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user