cart: empty [ Login ]

Exception on WW.Cad.IO.DwgReader.Read

1 
Davide
2/8/2019 2:08 PM
Hello, I am using WW.Cad.IO.DwgReader to read cad files and create a simple png preview for a project. With one file (uploaded as confidential attachment) from an import of 15+ year old customer archive, when reading, the memory grows but never ends. In a vm with reduced resources, this exception is generated:
11:04:34 - Exception of type 'System.OutOfMemoryException' was thrown. - at System.Collections.Generic.List`1.set_Capacity(Int32 value) at System.Collections.Generic.List`1.EnsureCapacity(Int32 min) at System.Collections.Generic.List`1.Add(T item) at .() at ..( ) at ..() at ..(& ,  , IList`1 ) at WW.Cad.IO.DwgReader.() at WW.Cad.IO.DwgReader.Read(DxfModel model) at WW.Cad.IO.DwgReader.Read() at WW.Cad.IO.DwgReader.Read(String filename, ProgressEventHandler progressEventHandler) at WW.Cad.IO.DwgReader.Read(String filename) at DXApplication13....
Wout
2/8/2019 3:05 PM
Hi, The problem has been fixed, please download the latest CadLib version from "Your resources" in your profile. Thank you for the report! - Wout
Davide
2/11/2019 10:07 AM
Thanks for the quick response. I also report out this exception with same code (dwg in attachment):
System.ArgumentException HResult=0x80070057 Messaggio=Parametro non valido. Origine=System.Drawing Analisi dello stack: in System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format) in System.Drawing.Bitmap..ctor(Int32 width, Int32 height) in WW.Cad.IO.ImageExporter.CreateBitmap(GDIGraphics3D cadGraphics, SmoothingMode smoothingMode, Matrix4D transform, Color backColor, Int32 width, Int32 height) in WW.Cad.IO.ImageExporter.CreateAutoSizedBitmap(DxfModel model, GDIGraphics3D cadGraphics, SmoothingMode smoothingMode, Matrix4D transform, Color backColor, Size maxSize) in WW.Cad.IO.ImageExporter.CreateAutoSizedBitmap(DxfModel model, GDIGraphics3D cadGraphics, Matrix4D transform, Color backColor, Size maxSize)
Wout
2/12/2019 11:48 AM
Can you please post the code to reproduce the issue? - Wout
Davide
2/13/2019 9:53 AM
In https://www.woutware.com/Resources/WW.Cad.4.0 last release is not downlodable. I resolved this problem (but i don't understand very well why this behavior). I am doing images for 1000 dwg consecutively, the exception was launched after 400 files, resolved adding a simple Application.DoEvents() after each file (it is a simple windows form application).
C# Code:
... public static long? CreateAttachmentPreview(Attachment a){ ... case ".dwg": model = DwgReader.Read(a.Path); ExportToPng(model, ap.FilePath); ... public static void ExportToPng(DxfModel model, String filename) { GraphicsConfig config =(GraphicsConfig) GraphicsConfig.BlackBackgroundCorrectForBackColor.Clone(); config.NoOfArcLineSegments = 70; GDIGraphics3D graphics = new GDIGraphics3D(config); Size maxSize = new Size(1600, 1600); Bitmap bitmap = ImageExporter.CreateAutoSizedBitmap( model, graphics, Matrix4D.Identity, System.Drawing.Color.White, maxSize ); using (Stream stream = File.Create(filename)) { ImageExporter.EncodeImageToPng(bitmap, stream); } }
Wout
2/17/2019 1:45 PM
The download problem is fixed by the way. Also please call Dispose() on the Bitmap after you don't need it anymore. It's safest to just use the C# using statement. - Wout
1