From b7c9eb4bf78b831c920f6a6f1aed4df903b9e4f4 Mon Sep 17 00:00:00 2001 From: Melanie Date: Mon, 5 Dec 2011 15:46:57 +0100 Subject: Don't allow deletion of a terrain from the database unless we have one to replace it with --- OpenSim/Data/MySQL/MySQLSimulationData.cs | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'OpenSim/Data/MySQL/MySQLSimulationData.cs') diff --git a/OpenSim/Data/MySQL/MySQLSimulationData.cs b/OpenSim/Data/MySQL/MySQLSimulationData.cs index 3437250..b201c51 100644 --- a/OpenSim/Data/MySQL/MySQLSimulationData.cs +++ b/OpenSim/Data/MySQL/MySQLSimulationData.cs @@ -574,15 +574,29 @@ namespace OpenSim.Data.MySQL cmd.CommandText = "delete from terrain where RegionUUID = ?RegionUUID"; cmd.Parameters.AddWithValue("RegionUUID", regionID.ToString()); - ExecuteNonQuery(cmd); - - cmd.CommandText = "insert into terrain (RegionUUID, " + - "Revision, Heightfield) values (?RegionUUID, " + - "1, ?Heightfield)"; + using (MySqlCommand cmd2 = dbcon.CreateCommand()) + { + try + { + cmd2.CommandText = "insert into terrain (RegionUUID, " + + "Revision, Heightfield) values (?RegionUUID, " + + "1, ?Heightfield)"; - cmd.Parameters.AddWithValue("Heightfield", SerializeTerrain(ter)); + cmd2.Parameters.AddWithValue("RegionUUID", regionID.ToString()); + cmd2.Parameters.AddWithValue("Heightfield", SerializeTerrain(ter)); - ExecuteNonQuery(cmd); + ExecuteNonQuery(cmd); + ExecuteNonQuery(cmd2); + } + catch + { + // If we get here there is a NaN in the terrain + // and the terrain can't be saved. A crash here + // is much better than losing all the work + m_log.ErrorFormat("[DATA]: Unable to save terrain. Stopping simulator to prevent data loss"); + Environment.Exit(1); + } + } } } } -- cgit v1.1