Hi BoltBait, even with the render function being called hundreds of times, wouldn't each selection be unique?
My plugin code below still gives me the same error when run even thought the file names should be unique each time I would have thought:
void SaveSelectionToFile(Rectangle rect)
{
String str = String.Format("C:\\Sprites\\{0},{0},{0},{0}",
rect.Left.ToString(),
rect.Top.ToString(),
rect.Right.ToString(),
rect.Bottom.ToString());
String filename = str + ".txt";
if (System.IO.File.Exists(filename) == true) return;
System.IO.StreamWriter SW;
SW = System.IO.File.CreateText(filename);
SW.WriteLine(str);
SW.Close();
}
void Render(Surface dst, Surface src, Rectangle rect)
{
Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
SaveSelectionToFile(selection);
}
Full Error:
File: C:\Program Files\Paint.NET\Effects\SaveSelection.dll
Name: SaveSelectionEffect.SaveSelectionEffectPlugin
Version: 1.0.3303.23127
Author:
Copyright: Copyright ©
Website: http://www.getpaint.net/redirect/plugins.html
Full error message: PaintDotNet.WorkerThreadException: Worker thread threw an exception ---> System.IO.IOException: The process cannot access the file 'C:\Sprites\228,228,228,228.txt' because it is being used by another process.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
at System.IO.StreamWriter.CreateFile(String path, Boolean append)
at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize)
at System.IO.StreamWriter..ctor(String path, Boolean append)
at System.IO.File.CreateText(String path)
at SaveSelectionEffect.SaveSelectionEffectPlugin.SaveSelectionToFile(Rectangle rect)
at SaveSelectionEffect.SaveSelectionEffectPlugin.Render(Surface dst, Surface src, Rectangle rect)
at SaveSelectionEffect.SaveSelectionEffectPlugin.OnRender(Rectangle[] rois, Int32 startIndex, Int32 length)
at PaintDotNet.Effects.Effect`1.Render(Rectangle[] renderRects, Int32 startIndex, Int32 length)
at PaintDotNet.Effects.Effect`1.Render(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs, Rectangle[] rois, Int32 startIndex, Int32 length)
at PaintDotNet.Effects.BackgroundEffectRenderer.RendererContext.RenderImpl()
--- End of inner exception stack trace ---
at PaintDotNet.Effects.BackgroundEffectRenderer.Join()
at PaintDotNet.Menus.EffectMenuBase.DoEffect(Effect effect, EffectConfigToken token, PdnRegion selectedRegion, PdnRegion regionToRender, Surface originalSurface, Exception& exception)
cheers,
Paul