Fix crash when removing scenery groups

This commit is contained in:
Michael Steenbeek 2017-11-11 15:03:59 +01:00
parent 3fbdf117cd
commit 263b7537d7
4 changed files with 45 additions and 5 deletions

View File

@ -209,6 +209,7 @@
C666EE181F33E3800061AA04 /* EditorMain.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C666ED851F33E3520061AA04 /* EditorMain.cpp */; };
C666EE1A1F33E3800061AA04 /* EditorObjectSelection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C666ED871F33E3520061AA04 /* EditorObjectSelection.cpp */; };
C666EE1F1F33E3800061AA04 /* GameBottomToolbar.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C666ED8C1F33E3520061AA04 /* GameBottomToolbar.cpp */; };
C666EE391F33E3800061AA04 /* RideConstruction.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C666EDA61F33E3520061AA04 /* RideConstruction.cpp */; };
C666EE3C1F33E3800061AA04 /* Scenery.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C666EDA91F33E3520061AA04 /* Scenery.cpp */; };
C666EE451F33E3800061AA04 /* TileInspector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C666EDB21F33E3520061AA04 /* TileInspector.cpp */; };
C666EE4D1F33E3800061AA04 /* Tooltip.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C666EDBA1F33E3520061AA04 /* Tooltip.cpp */; };
@ -611,6 +612,7 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
4C31B2E61FB7352900F6A38A /* Scenery.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Scenery.h; sourceTree = "<group>"; };
4C4C1E971F58226500560300 /* TrackDesign.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TrackDesign.cpp; sourceTree = "<group>"; };
4C4C1E991F5832AA00560300 /* TrackDesign.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TrackDesign.h; sourceTree = "<group>"; };
4C5DFF401FAC69D200CB093A /* Date.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Date.cpp; sourceTree = "<group>"; };
@ -822,6 +824,7 @@
C666ED851F33E3520061AA04 /* EditorMain.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EditorMain.cpp; sourceTree = "<group>"; };
C666ED871F33E3520061AA04 /* EditorObjectSelection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EditorObjectSelection.cpp; sourceTree = "<group>"; };
C666ED8C1F33E3520061AA04 /* GameBottomToolbar.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GameBottomToolbar.cpp; sourceTree = "<group>"; };
C666EDA61F33E3520061AA04 /* RideConstruction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RideConstruction.cpp; sourceTree = "<group>"; };
C666EDA91F33E3520061AA04 /* Scenery.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Scenery.cpp; sourceTree = "<group>"; };
C666EDB21F33E3520061AA04 /* TileInspector.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TileInspector.cpp; sourceTree = "<group>"; };
C666EDBA1F33E3520061AA04 /* Tooltip.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Tooltip.cpp; sourceTree = "<group>"; };
@ -2525,7 +2528,9 @@
C666ED8C1F33E3520061AA04 /* GameBottomToolbar.cpp */,
C654DF3E1F69C18C0040F43D /* Intent.cpp */,
C654DF3F1F69C18C0040F43D /* Intent.h */,
C666EDA61F33E3520061AA04 /* RideConstruction.cpp */,
C666EDA91F33E3520061AA04 /* Scenery.cpp */,
4C31B2E61FB7352900F6A38A /* Scenery.h */,
F76C854A1EC4E7CD00FA49E2 /* tile_inspector.h */,
C666EDB21F33E3520061AA04 /* TileInspector.cpp */,
C666EDBA1F33E3520061AA04 /* Tooltip.cpp */,

View File

@ -31,11 +31,12 @@
#include "../object_list.h"
#include "../rct1.h"
#include "../ride/ride_data.h"
#include "../sprites.h"
#include "../util/util.h"
#include "../windows/Intent.h"
#include "dropdown.h"
#include "../sprites.h"
#include "_legacy.h"
#include "dropdown.h"
#include "Scenery.h"
enum {
FILTER_RCT2 = (1 << 0),
@ -735,6 +736,8 @@ static void window_editor_object_selection_close(rct_window *w)
context_broadcast_intent(&intent);
visible_list_dispose();
window_scenery_reset_selected_scenery_items();
}
/**
@ -1920,5 +1923,7 @@ sint32 editor_remove_unused_objects()
editor_object_flags_free();
}
window_scenery_reset_selected_scenery_items();
return numUnselectedObjects;
}

View File

@ -23,17 +23,17 @@
#include "../interface/viewport.h"
#include "../interface/widget.h"
#include "../localisation/localisation.h"
#include "../object_list.h"
#include "../sprites.h"
#include "../world/scenery.h"
#include "dropdown.h"
#include "error.h"
#include "../sprites.h"
#include "../object_list.h"
#include "Scenery.h"
#define WINDOW_SCENERY_WIDTH 634
#define WINDOW_SCENERY_HEIGHT 180
#define SCENERY_BUTTON_WIDTH 66
#define SCENERY_BUTTON_HEIGHT 80
#define SCENERY_WINDOW_TABS MAX_SCENERY_GROUP_OBJECTS + 1 // The + 1 is for the 'Miscellaneous' tab
enum {
WINDOW_SCENERY_TAB_1,
@ -1262,3 +1262,12 @@ bool window_scenery_set_selected_item(sint32 sceneryId)
}
return result;
}
// Used after removing objects, in order to avoid crashes.
void window_scenery_reset_selected_scenery_items()
{
for (size_t i = 0; i < SCENERY_WINDOW_TABS; i++)
{
gWindowSceneryTabSelections[i] = -1;
}
}

View File

@ -0,0 +1,21 @@
#pragma region Copyright (c) 2017-2017 OpenRCT2 Developers
/*****************************************************************************
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
*
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* A full copy of the GNU General Public License can be found in licence.txt
*****************************************************************************/
#pragma endregion
#pragma once
#define SCENERY_WINDOW_TABS MAX_SCENERY_GROUP_OBJECTS + 1 // The + 1 is for the 'Miscellaneous' tab
void window_scenery_reset_selected_scenery_items();