aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Data/MySQL/MySQLSimulationData.cs63
1 files changed, 34 insertions, 29 deletions
diff --git a/OpenSim/Data/MySQL/MySQLSimulationData.cs b/OpenSim/Data/MySQL/MySQLSimulationData.cs
index b201c51..40619de 100644
--- a/OpenSim/Data/MySQL/MySQLSimulationData.cs
+++ b/OpenSim/Data/MySQL/MySQLSimulationData.cs
@@ -561,45 +561,46 @@ namespace OpenSim.Data.MySQL
561 561
562 public virtual void StoreTerrain(double[,] ter, UUID regionID) 562 public virtual void StoreTerrain(double[,] ter, UUID regionID)
563 { 563 {
564 m_log.Info("[REGION DB]: Storing terrain"); 564 Util.FireAndForget(delegate(object x)
565
566 lock (m_dbLock)
567 { 565 {
568 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) 566 double[,] oldTerrain = LoadTerrain(regionID);
569 {
570 dbcon.Open();
571 567
572 using (MySqlCommand cmd = dbcon.CreateCommand()) 568 m_log.Info("[REGION DB]: Storing terrain");
569
570 lock (m_dbLock)
571 {
572 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
573 { 573 {
574 cmd.CommandText = "delete from terrain where RegionUUID = ?RegionUUID"; 574 dbcon.Open();
575 cmd.Parameters.AddWithValue("RegionUUID", regionID.ToString());
576 575
577 using (MySqlCommand cmd2 = dbcon.CreateCommand()) 576 using (MySqlCommand cmd = dbcon.CreateCommand())
578 { 577 {
579 try 578 cmd.CommandText = "delete from terrain where RegionUUID = ?RegionUUID";
579 cmd.Parameters.AddWithValue("RegionUUID", regionID.ToString());
580
581 using (MySqlCommand cmd2 = dbcon.CreateCommand())
580 { 582 {
581 cmd2.CommandText = "insert into terrain (RegionUUID, " + 583 try
582 "Revision, Heightfield) values (?RegionUUID, " + 584 {
583 "1, ?Heightfield)"; 585 cmd2.CommandText = "insert into terrain (RegionUUID, " +
586 "Revision, Heightfield) values (?RegionUUID, " +
587 "1, ?Heightfield)";
584 588
585 cmd2.Parameters.AddWithValue("RegionUUID", regionID.ToString()); 589 cmd2.Parameters.AddWithValue("RegionUUID", regionID.ToString());
586 cmd2.Parameters.AddWithValue("Heightfield", SerializeTerrain(ter)); 590 cmd2.Parameters.AddWithValue("Heightfield", SerializeTerrain(ter, oldTerrain));
587 591
588 ExecuteNonQuery(cmd); 592 ExecuteNonQuery(cmd);
589 ExecuteNonQuery(cmd2); 593 ExecuteNonQuery(cmd2);
590 } 594 }
591 catch 595 catch (Exception e)
592 { 596 {
593 // If we get here there is a NaN in the terrain 597 m_log.ErrorFormat(e.ToString());
594 // and the terrain can't be saved. A crash here 598 }
595 // is much better than losing all the work
596 m_log.ErrorFormat("[DATA]: Unable to save terrain. Stopping simulator to prevent data loss");
597 Environment.Exit(1);
598 } 599 }
599 } 600 }
600 } 601 }
601 } 602 }
602 } 603 });
603 } 604 }
604 605
605 public virtual double[,] LoadTerrain(UUID regionID) 606 public virtual double[,] LoadTerrain(UUID regionID)
@@ -1411,7 +1412,7 @@ namespace OpenSim.Data.MySQL
1411 /// </summary> 1412 /// </summary>
1412 /// <param name="val"></param> 1413 /// <param name="val"></param>
1413 /// <returns></returns> 1414 /// <returns></returns>
1414 private static Array SerializeTerrain(double[,] val) 1415 private static Array SerializeTerrain(double[,] val, double[,] oldTerrain)
1415 { 1416 {
1416 MemoryStream str = new MemoryStream(((int)Constants.RegionSize * (int)Constants.RegionSize) *sizeof (double)); 1417 MemoryStream str = new MemoryStream(((int)Constants.RegionSize * (int)Constants.RegionSize) *sizeof (double));
1417 BinaryWriter bw = new BinaryWriter(str); 1418 BinaryWriter bw = new BinaryWriter(str);
@@ -1420,7 +1421,11 @@ namespace OpenSim.Data.MySQL
1420 for (int x = 0; x < (int)Constants.RegionSize; x++) 1421 for (int x = 0; x < (int)Constants.RegionSize; x++)
1421 for (int y = 0; y < (int)Constants.RegionSize; y++) 1422 for (int y = 0; y < (int)Constants.RegionSize; y++)
1422 { 1423 {
1423 double height = val[x, y]; 1424 double height = 20.0;
1425 if (oldTerrain != null)
1426 height = oldTerrain[x, y];
1427 if (!double.IsNaN(val[x, y]))
1428 height = val[x, y];
1424 if (height == 0.0) 1429 if (height == 0.0)
1425 height = double.Epsilon; 1430 height = double.Epsilon;
1426 1431