ubMeshmerizer: add a few more try{} guards in file operations, etc

LSLKeyTest
UbitUmarov 2016-09-05 15:59:33 +01:00
parent 02ecff255d
commit d5dbcc8ad7
2 changed files with 50 additions and 46 deletions

View File

@ -588,37 +588,36 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
Mesh mesh = new Mesh(); Mesh mesh = new Mesh();
mesh.releaseBuildingMeshData(); mesh.releaseBuildingMeshData();
BinaryReader br = new BinaryReader(st);
bool ok = true; bool ok = true;
try using(BinaryReader br = new BinaryReader(st))
{ {
mesh.m_vertexCount = br.ReadInt32(); try
mesh.m_indexCount = br.ReadInt32(); {
mesh.m_vertexCount = br.ReadInt32();
mesh.m_indexCount = br.ReadInt32();
int n = 3 * mesh.m_vertexCount; int n = 3 * mesh.m_vertexCount;
mesh.vertices = new float[n]; mesh.vertices = new float[n];
for (int i = 0; i < n; i++) for (int i = 0; i < n; i++)
mesh.vertices[i] = br.ReadSingle(); mesh.vertices[i] = br.ReadSingle();
mesh.indexes = new int[mesh.m_indexCount]; mesh.indexes = new int[mesh.m_indexCount];
for (int i = 0; i < mesh.m_indexCount; i++) for (int i = 0; i < mesh.m_indexCount; i++)
mesh.indexes[i] = br.ReadInt32(); mesh.indexes[i] = br.ReadInt32();
mesh.m_obb.X = br.ReadSingle(); mesh.m_obb.X = br.ReadSingle();
mesh.m_obb.Y = br.ReadSingle(); mesh.m_obb.Y = br.ReadSingle();
mesh.m_obb.Z = br.ReadSingle(); mesh.m_obb.Z = br.ReadSingle();
mesh.m_obboffset.X = br.ReadSingle(); mesh.m_obboffset.X = br.ReadSingle();
mesh.m_obboffset.Y = br.ReadSingle(); mesh.m_obboffset.Y = br.ReadSingle();
mesh.m_obboffset.Z = br.ReadSingle(); mesh.m_obboffset.Z = br.ReadSingle();
}
catch
{
ok = false;
}
} }
catch
{
ok = false;
}
br.Close();
if (ok) if (ok)
{ {

View File

@ -60,7 +60,7 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
private bool m_Enabled = false; private bool m_Enabled = false;
public object diskLock = new object(); public static object diskLock = new object();
public bool doMeshFileCache = true; public bool doMeshFileCache = true;
@ -1426,13 +1426,13 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
{ {
if (File.Exists(filename)) if (File.Exists(filename))
{ {
FileStream stream = null;
try try
{ {
stream = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read); using(FileStream stream = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read))
BinaryFormatter bformatter = new BinaryFormatter(); {
// BinaryFormatter bformatter = new BinaryFormatter();
mesh = Mesh.FromStream(stream, key); mesh = Mesh.FromStream(stream,key);
}
} }
catch (Exception e) catch (Exception e)
@ -1443,13 +1443,17 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
filename, e.Message, e.StackTrace); filename, e.Message, e.StackTrace);
} }
if (stream != null) try
stream.Close(); {
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) private void StoreToFileCache(AMeshKey key, Mesh mesh)
{ {
Stream stream = null;
bool ok = false; bool ok = false;
// Make sure the target cache directory exists // Make sure the target cache directory exists
@ -1476,8 +1479,8 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
Directory.CreateDirectory(dir); Directory.CreateDirectory(dir);
} }
stream = File.Open(filename, FileMode.Create); using(Stream stream = File.Open(filename, FileMode.Create))
ok = mesh.ToStream(stream); ok = mesh.ToStream(stream);
} }
catch (IOException e) catch (IOException e)
{ {
@ -1487,15 +1490,17 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
ok = false; ok = false;
} }
if (stream != null) if (!ok && File.Exists(filename))
stream.Close();
if (File.Exists(filename))
{ {
if (ok) try
File.SetLastAccessTimeUtc(filename, DateTime.UtcNow); {
else
File.Delete(filename); File.Delete(filename);
}
catch (IOException e)
{
m_log.ErrorFormat(
"[MESH CACHE]: Failed to delete file {0}",filename);
}
} }
} }
} }