From 662725090bd5ba753b51ad5bac4ad5c002c0f830 Mon Sep 17 00:00:00 2001 From: MaxED <j.maxed@gmail.com> Date: Wed, 13 Jul 2016 23:28:06 +0000 Subject: [PATCH] Fixed a crash when using "Open map in current WAD" action in Visual mode. --- Source/Core/General/MapManager.cs | 29 +++++++++++++++++++-------- Source/Core/VisualModes/VisualMode.cs | 24 +++++++++++++--------- 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/Source/Core/General/MapManager.cs b/Source/Core/General/MapManager.cs index b5ccadf9a..25ffdcc08 100644 --- a/Source/Core/General/MapManager.cs +++ b/Source/Core/General/MapManager.cs @@ -538,16 +538,29 @@ namespace CodeImp.DoomBuilder // Restore selection groups options.ReadSelectionGroups(); - // Center map in screen or on stored coordinates - ClassicMode mode = General.Editing.Mode as ClassicMode; - if(mode != null) + if(General.Editing.Mode != null) { - mode.OnRedoEnd(); + if(General.Editing.Mode is ClassicMode) + { + ClassicMode mode = (ClassicMode)General.Editing.Mode; + mode.OnRedoEnd(); - if(options.ViewPosition.IsFinite() && !float.IsNaN(options.ViewScale)) - mode.CenterOnCoordinates(options.ViewPosition, options.ViewScale); - else - mode.CenterInScreen(); + // Center map in screen or on stored coordinates + if(options.ViewPosition.IsFinite() && !float.IsNaN(options.ViewScale)) + mode.CenterOnCoordinates(options.ViewPosition, options.ViewScale); + else + mode.CenterInScreen(); + } + else if(General.Editing.Mode is VisualMode) + { + VisualMode mode = (VisualMode)General.Editing.Mode; + + // This will rebuild blockmap, among the other things + General.Editing.Mode.OnReloadResources(); + + // Update camera position + if(options.ViewPosition.IsFinite()) mode.CenterOnCoordinates(options.ViewPosition); + } } // Success diff --git a/Source/Core/VisualModes/VisualMode.cs b/Source/Core/VisualModes/VisualMode.cs index 489bf6356..d4423e078 100644 --- a/Source/Core/VisualModes/VisualMode.cs +++ b/Source/Core/VisualModes/VisualMode.cs @@ -1143,18 +1143,22 @@ namespace CodeImp.DoomBuilder.VisualModes [BeginAction("centeroncoordinates", BaseAction = true)] protected virtual void CenterOnCoordinates() { - //show form... + // Show form... CenterOnCoordinatesForm form = new CenterOnCoordinatesForm(); - if(form.ShowDialog() == DialogResult.OK) - { - Sector s = General.Map.Map.GetSectorByCoordinates(form.Coordinates, blockmap); + if(form.ShowDialog() == DialogResult.OK) CenterOnCoordinates(form.Coordinates); + } - if(s == null) - General.Map.VisualCamera.Position = form.Coordinates; - else - General.Map.VisualCamera.Position = new Vector3D(form.Coordinates.x, form.Coordinates.y, s.FloorHeight + 54); - General.Map.VisualCamera.Sector = s; - } + //mxd + public void CenterOnCoordinates(Vector2D coords) + { + Sector s = General.Map.Map.GetSectorByCoordinates(coords, blockmap); + + if(s == null) + General.Map.VisualCamera.Position = coords; + else + General.Map.VisualCamera.Position = new Vector3D(coords.x, coords.y, s.FloorHeight + 54); + + General.Map.VisualCamera.Sector = s; } //mxd -- GitLab