LIBOMV-805: More reliable resource loading

Disable parallel reading of file to avoid files locking issues in the baker

git-svn-id: http://libopenmetaverse.googlecode.com/svn/libopenmetaverse/trunk@3270 52acb1d6-8a22-11de-b505-999d5b087335
This commit is contained in:
Latif Khalifa
2010-03-08 22:39:40 +00:00
parent 06713078af
commit cc4d76231e
2 changed files with 20 additions and 6 deletions

View File

@@ -471,7 +471,7 @@ namespace OpenMetaverse
try
{
return new System.IO.FileStream(
System.IO.Path.Combine(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), searchPath), resourceName),
System.IO.Path.Combine(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), searchPath), resourceName),
System.IO.FileMode.Open);
}
catch (Exception)

View File

@@ -264,15 +264,29 @@ namespace OpenMetaverse.Imaging
//File.WriteAllBytes(bakeType + ".tga", bakedTexture.Image.ExportTGA());
}
private static object ResourceSync = new object();
public static ManagedImage LoadResourceLayer(string fileName)
{
try
{
Stream stream = Helpers.GetResourceStream(fileName, Settings.RESOURCE_DIR);
Bitmap bitmap = LoadTGAClass.LoadTGA(stream);
stream.Close();
stream.Dispose();
return new ManagedImage(bitmap);
Bitmap bitmap = null;
lock (ResourceSync)
{
using (Stream stream = Helpers.GetResourceStream(fileName, Settings.RESOURCE_DIR))
{
bitmap = LoadTGAClass.LoadTGA(stream);
}
}
if (bitmap == null)
{
Logger.Log(String.Format("Failed loading resource file: {0}", fileName), Helpers.LogLevel.Error);
return null;
}
else
{
return new ManagedImage(bitmap);
}
}
catch (Exception e)
{