Fix asserts due to main window not existing yet

Partial revert of https://github.com/OpenTTD/OpenTTD/pull/10327
This commit is contained in:
Jonathan G Rennison
2023-01-27 17:56:17 +00:00
parent 32fe84cfdd
commit 4761750eae
4 changed files with 15 additions and 9 deletions

View File

@@ -4185,8 +4185,8 @@ bool VehicleClicked(const GUIVehicleGroup &vehgroup)
void StopGlobalFollowVehicle(const Vehicle *v)
{
Window *w = GetMainWindow();
if (w->viewport->follow_vehicle == v->index) {
Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
if (w != nullptr && w->viewport->follow_vehicle == v->index) {
ScrollMainWindowTo(v->x_pos, v->y_pos, v->z_pos, true); // lock the main view on the vehicle's last position
w->viewport->follow_vehicle = INVALID_VEHICLE;
}