From d5dbcc8ad706e6ec69790e3936abca60be1a5b71 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Mon, 5 Sep 2016 15:59:33 +0100 Subject: ubMeshmerizer: add a few more try{} guards in file operations, etc --- .../PhysicsModules/ubOdeMeshing/Meshmerizer.cs | 49 ++++++++++++---------- 1 file changed, 27 insertions(+), 22 deletions(-) (limited to 'OpenSim/Region/PhysicsModules/ubOdeMeshing/Meshmerizer.cs') diff --git a/OpenSim/Region/PhysicsModules/ubOdeMeshing/Meshmerizer.cs b/OpenSim/Region/PhysicsModules/ubOdeMeshing/Meshmerizer.cs index d9544db..ff10e7f 100644 --- a/OpenSim/Region/PhysicsModules/ubOdeMeshing/Meshmerizer.cs +++ b/OpenSim/Region/PhysicsModules/ubOdeMeshing/Meshmerizer.cs @@ -60,7 +60,7 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing private bool m_Enabled = false; - public object diskLock = new object(); + public static object diskLock = new object(); public bool doMeshFileCache = true; @@ -1426,13 +1426,13 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing { if (File.Exists(filename)) { - FileStream stream = null; try { - stream = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read); - BinaryFormatter bformatter = new BinaryFormatter(); - - mesh = Mesh.FromStream(stream, key); + using(FileStream stream = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read)) + { +// BinaryFormatter bformatter = new BinaryFormatter(); + mesh = Mesh.FromStream(stream,key); + } } catch (Exception e) @@ -1443,13 +1443,17 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing filename, e.Message, e.StackTrace); } - if (stream != null) - stream.Close(); + try + { + if (mesh == null || !ok) + File.Delete(filename); + else + File.SetLastAccessTimeUtc(filename, DateTime.UtcNow); + } + catch + { + } - if (mesh == null || !ok) - File.Delete(filename); - else - File.SetLastAccessTimeUtc(filename, DateTime.UtcNow); } } @@ -1458,7 +1462,6 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing private void StoreToFileCache(AMeshKey key, Mesh mesh) { - Stream stream = null; bool ok = false; // Make sure the target cache directory exists @@ -1476,8 +1479,8 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing Directory.CreateDirectory(dir); } - stream = File.Open(filename, FileMode.Create); - ok = mesh.ToStream(stream); + using(Stream stream = File.Open(filename, FileMode.Create)) + ok = mesh.ToStream(stream); } catch (IOException e) { @@ -1487,15 +1490,17 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing ok = false; } - if (stream != null) - stream.Close(); - - if (File.Exists(filename)) + if (!ok && File.Exists(filename)) { - if (ok) - File.SetLastAccessTimeUtc(filename, DateTime.UtcNow); - else + try + { File.Delete(filename); + } + catch (IOException e) + { + m_log.ErrorFormat( + "[MESH CACHE]: Failed to delete file {0}",filename); + } } } } -- cgit v1.1