petergolde / PurplePen

Purple Pen course setting program for orienteering
62 stars 20 forks source link

Null pointer exception when opening map #5

Closed danielwidmann closed 2 years ago

danielwidmann commented 4 years ago

Creating a new event with the attached Open Orienteering Mapper file will cause a NullReferenceException and no map will be displayed.

After debugging the code, it seems that the issue is caused by the following symbol:

<symbol type="4" id="34" code="526.1" name="Building inside (not passable)"><area_symbol inner_color="8" min_area="0" patterns="1"><pattern type="1" angle="0" rotatable="true" line_spacing="0" line_offset="0" offset_along_line="0" color="-1" line_width="0"/></area_symbol></symbol>

Purple Pen seems to have trouble with color="-1" in the pattern.

Map: BCIT-Georeferenced_no_template.zip

Stacktrace: at PurplePen.MapModel.AreaSymDef.CreatePensAndBrushes(IGraphicsTarget g) in C:\Users\peter\Documents\Programs\MapModel\src\MapModel-Shared\SymDef.cs:line 2073 at PurplePen.MapModel.AreaSymDef.Draw(IGraphicsTarget g, SymPathWithHoles path, SymColor color, Single angle, PointF rotationCenter, RenderOptions renderOpts) in C:\Users\peter\Documents\Programs\MapModel\src\MapModel-Shared\SymDef.cs:line 2148 at PurplePen.MapModel.AreaSymbol.Draw(IGraphicsTarget g, SymColor color, RenderOptions renderOpts) in C:\Users\peter\Documents\Programs\MapModel\src\MapModel-Shared\Symbol.cs:line 587 at PurplePen.MapModel.Map.DrawColor(IGraphicsTarget g, SymColor curColor, RectangleF rect, RenderOptions renderOpts, Operation throwOnCancel) in C:\Users\peter\Documents\Programs\MapModel\src\MapModel-Shared\Map.cs:line 2146 at PurplePen.MapModel.Map.Draw(IGraphicsTarget g, RectangleF rect, RenderOptions renderOpts, Operation throwOnCancel, Int32 templateRecursionCount) in C:\Users\peter\Documents\Programs\MapModel\src\MapModel-Shared\Map.cs:line 2088 at PurplePen.MapModel.Map.Draw(IGraphicsTarget g, RectangleF rect, RenderOptions renderOpts, Operation throwOnCancel) in C:\Users\peter\Documents\Programs\MapModel\src\MapModel-Shared\Map.cs:line 2061 at PurplePen.MapDisplay.DrawOcadMap(IGraphicsTarget grTarget, RectangleF visRect, RenderOptions renderOptions) in D:\2020\PurplePen\src\PurplePen\MapDisplay.cs:line 521 at PurplePen.MapDisplay.DrawHelper(IGraphicsTarget grTargetOcadMap, IGraphicsTarget grTargetBitmapMap, IGraphicsTarget grTargetCourses, RectangleF visRect, Single minResolution) in D:\2020\PurplePen\src\PurplePen\MapDisplay.cs:line 623 at PurplePen.MapDisplay.Draw(Bitmap bitmap, Matrix transform, Region clipRegion) in D:\2020\PurplePen\src\PurplePen\MapDisplay.cs:line 582 at PurplePen.MapView.ViewCache.UpdateCache(Size sizeView, RectangleF mapAreaToView, Matrix transform) in D:\2020\PurplePen\src\PurplePen\MapView\ViewCache.cs:line 156 at PurplePen.MapView.ViewCache.GetCacheBitmap(Size sizeView, RectangleF mapAreaToView, Matrix transform, Int64& changeNumber) in D:\2020\PurplePen\src\PurplePen\MapView\ViewCache.cs:line 126 at PurplePen.MapView.MapViewer.CompositeBitmap(Boolean highlightsHaveChanged) in D:\2020\PurplePen\src\PurplePen\MapView\MapViewer.cs:line 932 at PurplePen.MapView.MapViewer.Draw(Graphics g, Rectangle clip) in D:\2020\PurplePen\src\PurplePen\MapView\MapViewer.cs:line 962 at PurplePen.MapView.MapViewer.MapViewer_Paint(Object sender, PaintEventArgs e) in D:\2020\PurplePen\src\PurplePen\MapView\MapViewer.cs:line 1052 at System.Windows.Forms.Control.OnPaint(PaintEventArgs e) at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer) at System.Windows.Forms.Control.WmPaint(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

danielwidmann commented 4 years ago

Suggestion for a fix:

In OpenMapperImport in the method ReadAreaSymbol the hatching could be ignored if the color is -1. For me this prevented the exception and buildings we still drawn correctly in Purple Pen.

I would create a pull request but this part of the code doesn't seem to be on github.

petergolde commented 2 years ago

Fixed in 3.4.1