Unable to read beyond the end of the stream
![]() 3/2/2022 3:35 AM
|
---|
Hi Wout &c,
We're having an issue where ImageExporter.CreateBitmap is throwing:
Unable to read beyond the end of the stream .
I cant work out how to reproduce it in a simple application - if I write the DxfModel out as a DWG and then read it back in it works fine.
I'm wondering if you could give me any pointers on what kinds of streams might be present in a DxfModel constructed in memory which wouldn't be in the loaded DWG?
Maybe fonts or blocks or something?
Code that simulates what we're doing (but obviously not well enough to cause the error):C# Code: void Main( |
![]() 3/2/2022 3:37 AM
|
---|
Here's the stack trace - looks like a font issue:
at System.IO.__Error.EndOfFile()
at System.IO.BinaryReader.ReadByte()
at WW.Cad.Model.Entities.ShxFile.(Byte[] )
at WW.Cad.Model.Entities.ShxFile.()
at WW.Cad.Model.Entities.ShxFile..ctor(String , Stream )
at WW.Cad.Model.Entities.ShxFile.GetShxFile(String filename, String filenameWithExtension, IFontFileLoader fontFileLoader)
at WW.Cad.Model.DxfModel.(String )
at .get_()
at ..ctor( )
at .(String , Double , Double , Double , DxfTextStyle , Color , String& )
at .(DxfText , Color , Int16 , Matrix4D , Bounds2D , Vector2D& , Vector2D& , )
at WW.Cad.Drawing.GDI.GDIGraphics3D..CreateText(DxfText , Wireframe )
at WW.Cad.Model.Entities.DxfText.DrawInternal(Wireframe context, IWireframeGraphicsFactory graphicsFactory)
at WW.Cad.Model.Entities.DxfEntity.Draw(Wireframe context, IWireframeGraphicsFactory graphicsFactory)
at WW.Cad.Model.Tables.DxfBlock.( , Boolean )
at WW.Cad.Model.Entities.DxfInsert.( , Boolean )
at WW.Cad.Model.Entities.DxfInsert.DrawInternal(Wireframe context, IWireframeGraphicsFactory graphicsFactory)
at WW.Cad.Model.Entities.DxfEntity.Draw(Wireframe context, IWireframeGraphicsFactory graphicsFactory)
at WW.Cad.Model.DxfModel.Draw(Wireframe context, IWireframeGraphicsFactory graphicsFactory)
at WW.Cad.Drawing.WireframeGraphicsFactoryUtil.CreateDrawables(IWireframeGraphicsFactory graphicsFactory, GraphicsConfig graphicsConfig, DxfModel model, Matrix4D modelTransform)
at WW.Cad.Drawing.GDI.GDIGraphics3D.CreateDrawables(DxfModel model)
at WW.Cad.IO.ImageExporter.CreateBitmap(DxfModel model, Matrix4D transform, GraphicsConfig graphicsConfig, SmoothingMode smoothingMode, Int32 width, Int32 height)
at SpatialInfo.Platform.Web.Formats.Graphic.Images.CadRenderer.Render(IVectorDrawing drawing, Double renderWidth, Double renderHeight, IEnumerable`1 imagePaths, String contentType, GraphicsMetrics stats) in C:\TFS\Product.SpatialSTORM\main.dev\DEV
|
![]() 3/2/2022 8:26 AM
|
---|
Humm - ok - I've got past that - it looks like our font resolver was not behaving properly.
But now I get this error (below). Its the same test case. There are no DxfText or DxfMTexts in the drawing but there is a Block that has some text / attributes in it. The drawing looks fine if I write it to DWG and then render but rendering it from an in-memory model causes this error.
Any clues what it might be having a key conflict with? It appears to only use "Standard" text style and txt.shx.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at WW.Cad.Model.Entities.ShxFile.GetShxFile(String filename, String filenameWithExtension, IFontFileLoader fontFileLoader)
at WW.Cad.Model.DxfModel.(String )
at WW.Cad.Model.Tables.DxfTextStyle.()
at WW.Cad.Model.Entities.DxfText.()
at WW.Cad.Model.Entities.DxfText.DrawInternal(Wireframe context, IWireframeGraphicsFactory graphicsFactory)
at WW.Cad.Model.Entities.DxfEntity.Draw(Wireframe context, IWireframeGraphicsFactory graphicsFactory)
at WW.Cad.Model.Tables.DxfBlock.( , Boolean )
at WW.Cad.Model.Entities.DxfInsert.( , Boolean )
at WW.Cad.Model.Entities.DxfInsert.DrawInternal(Wireframe context, IWireframeGraphicsFactory graphicsFactory)
at WW.Cad.Model.Entities.DxfEntity.Draw(Wireframe context, IWireframeGraphicsFactory graphicsFactory)
at WW.Cad.Model.DxfModel.Draw(Wireframe context, IWireframeGraphicsFactory graphicsFactory)
at WW.Cad.Drawing.WireframeGraphicsFactoryUtil.CreateDrawables(IWireframeGraphicsFactory graphicsFactory, GraphicsConfig graphicsConfig, DxfModel model, Matrix4D modelTransform)
at WW.Cad.Drawing.GDI.GDIGraphics3D.CreateDrawables(DxfModel model)
at WW.Cad.IO.ImageExporter.CreateBitmap(DxfModel model, Matrix4D transform, GraphicsConfig graphicsConfig, SmoothingMode smoothingMode, Int32 width, Int32 height)
at SpatialInfo.Platform.Web.Formats.Graphic.Images.CadRenderer.Render(IVectorDrawing drawing, Double renderWidth, Double renderHeight, IEnumerable`1 imagePaths, String contentType, GraphicsMetrics stats) in C:\TFS\Product.SpatialSTORM\main.dev\DEV\Platform\Web\Formats\Graphic\Images\CadRenderer.cs:line 2257
|
![]() 3/2/2022 9:36 AM
|
---|
So in the interests of trying to a) not drive myself crazy, b) help out, I had a look at what ILSpy could tell me 🙂 and I'd say this is a bug?
The method:
C# Code: public static ShxFile GetShxFile( C# Code: public static ShxFile GetShxFile( |
![]() 3/2/2022 10:46 AM
|
---|
Hi Chris,
There was indeed a missing lock in that area, I was able to get an exception by running 4 threads simultaneously running your code. I've added extra locks, can you try the latest version?
I did not get a beyond end of stream problem though.
- Wout
|
![]() 3/2/2022 10:48 AM
|
---|
Awesome! thank you! Will give it a test
Yes end of stream thing was our fault - for some reason all our shx files were full of zeros and we were returning null streams in some cases.
|
![]() 3/2/2022 11:14 AM
|
---|
And again big thank you! I can confirm this has fixed it!
|