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 --- OpenSim/Region/PhysicsModules/ubOdeMeshing/Mesh.cs | 47 ++++++++++----------- .../PhysicsModules/ubOdeMeshing/Meshmerizer.cs | 49 ++++++++++++---------- 2 files changed, 50 insertions(+), 46 deletions(-) (limited to 'OpenSim/Region/PhysicsModules') diff --git a/OpenSim/Region/PhysicsModules/ubOdeMeshing/Mesh.cs b/OpenSim/Region/PhysicsModules/ubOdeMeshing/Mesh.cs index 5b1510f..d9ea4a4 100644 --- a/OpenSim/Region/PhysicsModules/ubOdeMeshing/Mesh.cs +++ b/OpenSim/Region/PhysicsModules/ubOdeMeshing/Mesh.cs @@ -588,38 +588,37 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing Mesh mesh = new Mesh(); mesh.releaseBuildingMeshData(); - BinaryReader br = new BinaryReader(st); - bool ok = true; - try + using(BinaryReader br = new BinaryReader(st)) { - mesh.m_vertexCount = br.ReadInt32(); - mesh.m_indexCount = br.ReadInt32(); + try + { + mesh.m_vertexCount = br.ReadInt32(); + mesh.m_indexCount = br.ReadInt32(); - int n = 3 * mesh.m_vertexCount; - mesh.vertices = new float[n]; - for (int i = 0; i < n; i++) - mesh.vertices[i] = br.ReadSingle(); + int n = 3 * mesh.m_vertexCount; + mesh.vertices = new float[n]; + for (int i = 0; i < n; i++) + mesh.vertices[i] = br.ReadSingle(); - mesh.indexes = new int[mesh.m_indexCount]; - for (int i = 0; i < mesh.m_indexCount; i++) - mesh.indexes[i] = br.ReadInt32(); + mesh.indexes = new int[mesh.m_indexCount]; + for (int i = 0; i < mesh.m_indexCount; i++) + mesh.indexes[i] = br.ReadInt32(); - mesh.m_obb.X = br.ReadSingle(); - mesh.m_obb.Y = br.ReadSingle(); - mesh.m_obb.Z = br.ReadSingle(); + mesh.m_obb.X = br.ReadSingle(); + mesh.m_obb.Y = br.ReadSingle(); + mesh.m_obb.Z = br.ReadSingle(); - mesh.m_obboffset.X = br.ReadSingle(); - mesh.m_obboffset.Y = br.ReadSingle(); - mesh.m_obboffset.Z = br.ReadSingle(); - } - catch - { - ok = false; + mesh.m_obboffset.X = br.ReadSingle(); + mesh.m_obboffset.Y = br.ReadSingle(); + mesh.m_obboffset.Z = br.ReadSingle(); + } + catch + { + ok = false; + } } - br.Close(); - if (ok) { mesh.pinMemory(); 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 From 34dce801b27e0935c4b3392d1de02a86afada5b3 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Mon, 12 Sep 2016 18:10:11 +0100 Subject: put a lock back in ubOde character :( --- .../Region/PhysicsModules/ubOde/ODECharacter.cs | 51 ++++++++++------------ 1 file changed, 22 insertions(+), 29 deletions(-) (limited to 'OpenSim/Region/PhysicsModules') diff --git a/OpenSim/Region/PhysicsModules/ubOde/ODECharacter.cs b/OpenSim/Region/PhysicsModules/ubOde/ODECharacter.cs index 3a5a936..9640e91 100644 --- a/OpenSim/Region/PhysicsModules/ubOde/ODECharacter.cs +++ b/OpenSim/Region/PhysicsModules/ubOde/ODECharacter.cs @@ -112,7 +112,6 @@ namespace OpenSim.Region.PhysicsModule.ubOde private bool _zeroFlag = false; private bool m_haveLastFallVel = false; - private uint m_localID = 0; public bool m_returnCollisions = false; // taints and their non-tainted counterparts @@ -149,7 +148,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde public int m_eventsubscription = 0; private int m_cureventsubscription = 0; - private CollisionEventUpdate CollisionEventsThisFrame = null; + private CollisionEventUpdate CollisionEventsThisFrame = new CollisionEventUpdate(); private bool SentEmptyCollisionsEvent; // unique UUID of this character object @@ -1556,32 +1555,26 @@ namespace OpenSim.Region.PhysicsModule.ubOde public override float APIDDamping { set { return; } } - public override void SubscribeEvents(int ms) { m_eventsubscription = ms; m_cureventsubscription = 0; - if (CollisionEventsThisFrame == null) - CollisionEventsThisFrame = new CollisionEventUpdate(); + CollisionEventsThisFrame.Clear(); SentEmptyCollisionsEvent = false; } public override void UnSubscribeEvents() { - if (CollisionEventsThisFrame != null) - { - CollisionEventsThisFrame.Clear(); - CollisionEventsThisFrame = null; - } m_eventsubscription = 0; _parent_scene.RemoveCollisionEventReporting(this); + lock(CollisionEventsThisFrame) + CollisionEventsThisFrame.Clear(); } public override void AddCollisionEvent(uint CollidedWith, ContactPoint contact) { - if (CollisionEventsThisFrame == null) - CollisionEventsThisFrame = new CollisionEventUpdate(); - CollisionEventsThisFrame.AddCollider(CollidedWith, contact); + lock(CollisionEventsThisFrame) + CollisionEventsThisFrame.AddCollider(CollidedWith, contact); _parent_scene.AddCollisionEventReporting(this); } @@ -1590,28 +1583,28 @@ namespace OpenSim.Region.PhysicsModule.ubOde if (m_cureventsubscription < 50000) m_cureventsubscription += timestep; - if (CollisionEventsThisFrame == null) - return; - if (m_cureventsubscription < m_eventsubscription) return; - int ncolisions = CollisionEventsThisFrame.m_objCollisionList.Count; - - if (!SentEmptyCollisionsEvent || ncolisions > 0) + lock(CollisionEventsThisFrame) { - base.SendCollisionUpdate(CollisionEventsThisFrame); - m_cureventsubscription = 0; + int ncolisions = CollisionEventsThisFrame.m_objCollisionList.Count; - if (ncolisions == 0) + if (!SentEmptyCollisionsEvent || ncolisions > 0) { - SentEmptyCollisionsEvent = true; -// _parent_scene.RemoveCollisionEventReporting(this); - } - else - { - SentEmptyCollisionsEvent = false; - CollisionEventsThisFrame.Clear(); + base.SendCollisionUpdate(CollisionEventsThisFrame); + m_cureventsubscription = 0; + + if (ncolisions == 0) + { + SentEmptyCollisionsEvent = true; + // _parent_scene.RemoveCollisionEventReporting(this); + } + else + { + SentEmptyCollisionsEvent = false; + CollisionEventsThisFrame.Clear(); + } } } } -- cgit v1.1