workaround potencial memory leaks

LSLKeyTest
UbitUmarov 2016-08-22 03:55:01 +01:00
parent 426e8a798f
commit c8a1d7e5a7
7 changed files with 32 additions and 50 deletions

View File

@ -47,8 +47,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
/// <param name="map">The terrain channel being saved</param> /// <param name="map">The terrain channel being saved</param>
public override void SaveFile(string filename, ITerrainChannel map) public override void SaveFile(string filename, ITerrainChannel map)
{ {
Bitmap colours = CreateGrayscaleBitmapFromMap(map); using(Bitmap colours = CreateGrayscaleBitmapFromMap(map))
colours.Save(filename,ImageFormat.Bmp); colours.Save(filename,ImageFormat.Bmp);
} }
@ -59,8 +58,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
/// <param name="map">The terrain channel being saved</param> /// <param name="map">The terrain channel being saved</param>
public override void SaveStream(Stream stream, ITerrainChannel map) public override void SaveStream(Stream stream, ITerrainChannel map)
{ {
Bitmap colours = CreateGrayscaleBitmapFromMap(map); using(Bitmap colours = CreateGrayscaleBitmapFromMap(map))
colours.Save(stream,ImageFormat.Bmp); colours.Save(stream,ImageFormat.Bmp);
} }

View File

@ -36,8 +36,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
{ {
public override void SaveFile(string filename, ITerrainChannel map) public override void SaveFile(string filename, ITerrainChannel map)
{ {
Bitmap colours = CreateGrayscaleBitmapFromMap(map); using(Bitmap colours = CreateGrayscaleBitmapFromMap(map))
colours.Save(filename,ImageFormat.Gif); colours.Save(filename,ImageFormat.Gif);
} }
@ -48,8 +47,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
/// <param name="map">The terrain channel being saved</param> /// <param name="map">The terrain channel being saved</param>
public override void SaveStream(Stream stream, ITerrainChannel map) public override void SaveStream(Stream stream, ITerrainChannel map)
{ {
Bitmap colours = CreateGrayscaleBitmapFromMap(map); using(Bitmap colours = CreateGrayscaleBitmapFromMap(map))
colours.Save(stream,ImageFormat.Gif); colours.Save(stream,ImageFormat.Gif);
} }

View File

@ -111,8 +111,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
/// <param name="map">The terrain channel being saved</param> /// <param name="map">The terrain channel being saved</param>
public virtual void SaveFile(string filename, ITerrainChannel map) public virtual void SaveFile(string filename, ITerrainChannel map)
{ {
Bitmap colours = CreateGrayscaleBitmapFromMap(map); using(Bitmap colours = CreateGrayscaleBitmapFromMap(map))
colours.Save(filename,ImageFormat.Png); colours.Save(filename,ImageFormat.Png);
} }
@ -123,8 +122,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
/// <param name="map">The terrain channel being saved</param> /// <param name="map">The terrain channel being saved</param>
public virtual void SaveStream(Stream stream, ITerrainChannel map) public virtual void SaveStream(Stream stream, ITerrainChannel map)
{ {
Bitmap colours = CreateGrayscaleBitmapFromMap(map); using(Bitmap colours = CreateGrayscaleBitmapFromMap(map))
colours.Save(stream,ImageFormat.Png); colours.Save(stream,ImageFormat.Png);
} }

View File

@ -59,8 +59,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
public void SaveFile(string filename, ITerrainChannel map) public void SaveFile(string filename, ITerrainChannel map)
{ {
Bitmap colours = CreateBitmapFromMap(map); using(Bitmap colours = CreateBitmapFromMap(map))
colours.Save(filename,ImageFormat.Jpeg); colours.Save(filename,ImageFormat.Jpeg);
} }
@ -71,8 +70,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
/// <param name="map">The terrain channel being saved</param> /// <param name="map">The terrain channel being saved</param>
public void SaveStream(Stream stream, ITerrainChannel map) public void SaveStream(Stream stream, ITerrainChannel map)
{ {
Bitmap colours = CreateBitmapFromMap(map); using(Bitmap colours = CreateBitmapFromMap(map))
colours.Save(stream,ImageFormat.Jpeg); colours.Save(stream,ImageFormat.Jpeg);
} }

View File

@ -36,8 +36,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
{ {
public override void SaveFile(string filename, ITerrainChannel map) public override void SaveFile(string filename, ITerrainChannel map)
{ {
Bitmap colours = CreateGrayscaleBitmapFromMap(map); using(Bitmap colours = CreateGrayscaleBitmapFromMap(map))
colours.Save(filename,ImageFormat.Png); colours.Save(filename,ImageFormat.Png);
} }
@ -48,8 +47,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
/// <param name="map">The terrain channel being saved</param> /// <param name="map">The terrain channel being saved</param>
public override void SaveStream(Stream stream, ITerrainChannel map) public override void SaveStream(Stream stream, ITerrainChannel map)
{ {
Bitmap colours = CreateGrayscaleBitmapFromMap(map); using(Bitmap colours = CreateGrayscaleBitmapFromMap(map))
colours.Save(stream,ImageFormat.Png); colours.Save(stream,ImageFormat.Png);
} }

View File

@ -36,8 +36,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
{ {
public override void SaveFile(string filename, ITerrainChannel map) public override void SaveFile(string filename, ITerrainChannel map)
{ {
Bitmap colours = CreateGrayscaleBitmapFromMap(map); using(Bitmap colours = CreateGrayscaleBitmapFromMap(map))
colours.Save(filename,ImageFormat.Tiff); colours.Save(filename,ImageFormat.Tiff);
} }
@ -48,8 +47,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
/// <param name="map">The terrain channel being saved</param> /// <param name="map">The terrain channel being saved</param>
public override void SaveStream(Stream stream, ITerrainChannel map) public override void SaveStream(Stream stream, ITerrainChannel map)
{ {
Bitmap colours = CreateGrayscaleBitmapFromMap(map); using(Bitmap colours = CreateGrayscaleBitmapFromMap(map))
colours.Save(stream,ImageFormat.Tiff); colours.Save(stream,ImageFormat.Tiff);
} }

View File

@ -69,16 +69,8 @@ namespace PrimMesher
needsScaling = true; needsScaling = true;
} }
try
{
if (needsScaling) if (needsScaling)
bm = ScaleImage(bm, width, height); bm = ScaleImage(bm, width, height);
}
catch (Exception e)
{
throw new Exception("Exception in ScaleImage(): e: " + e.ToString());
}
if (width * height > numLodPixels) if (width * height > numLodPixels)
{ {
@ -129,11 +121,15 @@ namespace PrimMesher
} }
catch (Exception e) catch (Exception e)
{ {
if (needsScaling)
bm.Dispose();
throw new Exception("Caught exception processing byte arrays in SculptMap(): e: " + e.ToString()); throw new Exception("Caught exception processing byte arrays in SculptMap(): e: " + e.ToString());
} }
width++; width++;
height++; height++;
if(needsScaling)
bm.Dispose();
} }
public List<List<Coord>> ToRows(bool mirror) public List<List<Coord>> ToRows(bool mirror)
@ -168,12 +164,10 @@ namespace PrimMesher
private Bitmap ScaleImage(Bitmap srcImage, int destWidth, int destHeight) private Bitmap ScaleImage(Bitmap srcImage, int destWidth, int destHeight)
{ {
Bitmap scaledImage = new Bitmap(destWidth, destHeight, PixelFormat.Format24bppRgb); Bitmap scaledImage = new Bitmap(destWidth, destHeight, PixelFormat.Format24bppRgb);
Color c; Color c;
// will let last step to be eventually diferent, as seems to be in sl // will let last step to be eventually diferent, as seems to be in sl
float xscale = (float)srcImage.Width / (float)destWidth; float xscale = (float)srcImage.Width / (float)destWidth;