diff -r c99ba0d75ce8 -r 1046eeaf4f0a src/settings_gui.cpp --- a/src/settings_gui.cpp Sun Sep 28 11:57:00 2008 +0200 +++ b/src/settings_gui.cpp Sun Sep 28 14:06:35 2008 +0200 @@ -614,6 +614,7 @@ "gui.default_rail_type", "gui.always_build_infrastructure", "gui.show_track_reservation", + NULL }; static const char *_patches_construction[] = { @@ -629,6 +630,7 @@ "gui.semaphore_build_before", "gui.default_signal_type", "gui.cycle_signal_types", + NULL }; static const char *_patches_stations[] = { @@ -644,6 +646,7 @@ "construction.road_stop_on_town_road", "station.adjacent_stations", "economy.station_noise_level", + NULL }; static const char *_patches_economy[] = { @@ -663,6 +666,7 @@ "economy.town_growth_rate", "economy.larger_towns", "economy.initial_city_size", + NULL }; static const char *_patches_ai[] = { @@ -672,6 +676,7 @@ "ai.ai_disable_veh_roadveh", "ai.ai_disable_veh_aircraft", "ai.ai_disable_veh_ship", + NULL }; static const char *_patches_vehicles[] = { @@ -706,6 +711,7 @@ "vehicle.plane_speed", "order.timetabling", "vehicle.dynamic_engines", + NULL }; /** Data structure describing a single patch at a tab */ @@ -717,24 +723,24 @@ /** * Data structure describing one page of patches in the patch settings window. * - * The names of the patches to display are statically defined, and from this - * information, a dynamic array (with length \a num_entries) of PatchEntry entries is + * The names of the patches to display are statically defined and terminated with a \c NULL. + * From this information, a dynamic array (with length \a num_entries) of PatchEntry entries is * constructed. */ struct PatchPage { const char **names; ///< Static list of strings with patch names that are settable at the tab PatchEntry *entries; ///< Array of patch entries of the page. Initially \c NULL, filled in at run time - byte num_entries; ///< Number of entries at the page (statically filled). + byte num_entries; ///< Number of entries at the page. Initially \c 0, computed at run time }; /** Array of pages (tabs), where each page holds a number of advanced settings. */ static PatchPage _patches_page[] = { - {_patches_ui, NULL, lengthof(_patches_ui)}, - {_patches_construction, NULL, lengthof(_patches_construction)}, - {_patches_vehicles, NULL, lengthof(_patches_vehicles)}, - {_patches_stations, NULL, lengthof(_patches_stations)}, - {_patches_economy, NULL, lengthof(_patches_economy)}, - {_patches_ai, NULL, lengthof(_patches_ai)}, + {_patches_ui, NULL, 0}, + {_patches_construction, NULL, 0}, + {_patches_vehicles, NULL, 0}, + {_patches_stations, NULL, 0}, + {_patches_economy, NULL, 0}, + {_patches_ai, NULL, 0}, }; /** Widget numbers of config patches window */ @@ -770,6 +776,12 @@ if (first_time) { PatchPage *page; for (page = &_patches_page[0]; page != endof(_patches_page); page++) { + /* Count number of entries at each page, and fill page->num_entries */ + byte count = 0; + for (const char **patchname = page->names; *patchname != NULL; ++patchname) + count++; + + page->num_entries = count; if (patches_max < page->num_entries) patches_max = page->num_entries; page->entries = MallocT(page->num_entries);