Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AV in TPolygonRenderer32VPR2X.AddLineSegment #67

Closed
andersmelander opened this issue Apr 12, 2019 · 4 comments
Closed

AV in TPolygonRenderer32VPR2X.AddLineSegment #67

andersmelander opened this issue Apr 12, 2019 · 4 comments
Labels

Comments

@andersmelander
Copy link
Member

TPolygonRenderer32VPR2X fails to render the following ellipse:
Ellipse(691, 10, 3, 161)
on a bitmap with the dimensions 694, 333

Call stack:

GR32_VPR2.AddSegment(45089147,-60543,45089185,-125752)
GR32_VPR2.TPolygonRenderer32VPR2X.AddLineSegment(45088768,589822,45089148,-62259)
GR32_VPR2.TPolygonRenderer32VPR2X.PolyPolygonFS((((694, 10), (693,994079589844, 20,1092739105225), (693,976318359375, 30,1786499023438), (693,946838378906, 40,1683921813965), (693,90576171875, 50,0390739440918), (693,853149414062, 59,7517356872559), (693,789306640625, 69,2680587768555), (693,714477539062, 78,5504684448242), (693,62890625, 87,5623474121094), (693,532958984375, 96,2681274414062), (693,427062988281, 104,633430480957), (693,3115234375, 112,625274658203), (693,186889648438, 120,212097167969), (693,053649902344, 127,363967895508), (692,912292480469, 134,052642822266), (692,763366699219, 140,251754760742), (692,607482910156, 145,936813354492), (692,445251464844, 151,085388183594), (692,27734375, 155,677169799805), (692,104370117188, 159,694030761719), (691,927062988281, 163,1201171875), (691,74609375, 165,94189453125), (691,562133789062, 168,148254394531), (691,3759765625, 169,73046875), (691,188354492188, 170,68229675293), (691, 171), (690,811645507812, 170,68229675293), (690,6240234375, 169,73046875), (690,437866210938, 168,148254394531), (690,25390625, 165,94189453125), (690,072937011719, 163,120101928711), (689,895629882812, 159,69401550293), (689,72265625, 155,677154541016), (689,554748535156, 151,085372924805), (689,392517089844, 145,936782836914), (689,236633300781, 140,251724243164), (689,087707519531, 134,052627563477), (688,946350097656, 127,36393737793), (688,813110351562, 120,212066650391), (688,6884765625, 112,625244140625), (688,572937011719, 104,633407592773), (688,467041015625, 96,2680969238281), (688,37109375, 87,5623245239258), (688,285522460938, 78,5504455566406), (688,210693359375, 69,2680358886719), (688,146850585938, 59,7517127990723), (688,09423828125, 50,0390472412109), (688,053161621094, 40,1683654785156), (688,023681640625, 30,1786270141602), (688,005920410156, 20,1092491149902), (688, 9,99997711181641), (688,005920410156, -0,109296590089798), (688,023681640625, -10,1786727905273), (688,053161621094, -20,1684131622314), (688,09423828125, -30,0390911102295), (688,1468505859...
GR32_Polygons.TCustomPolygonRenderer.PolyPolygonFS((((694, 10), (693,994079589844, 20,1092739105225), (693,976318359375, 30,1786499023438), (693,946838378906, 40,1683921813965), (693,90576171875, 50,0390739440918), (693,853149414062, 59,7517356872559), (693,789306640625, 69,2680587768555), (693,714477539062, 78,5504684448242), (693,62890625, 87,5623474121094), (693,532958984375, 96,2681274414062), (693,427062988281, 104,633430480957), (693,3115234375, 112,625274658203), (693,186889648438, 120,212097167969), (693,053649902344, 127,363967895508), (692,912292480469, 134,052642822266), (692,763366699219, 140,251754760742), (692,607482910156, 145,936813354492), (692,445251464844, 151,085388183594), (692,27734375, 155,677169799805), (692,104370117188, 159,694030761719), (691,927062988281, 163,1201171875), (691,74609375, 165,94189453125), (691,562133789062, 168,148254394531), (691,3759765625, 169,73046875), (691,188354492188, 170,68229675293), (691, 171), (690,811645507812, 170,68229675293), (690,6240234375, 169,73046875), (690,437866210938, 168,148254394531), (690,25390625, 165,94189453125), (690,072937011719, 163,120101928711), (689,895629882812, 159,69401550293), (689,72265625, 155,677154541016), (689,554748535156, 151,085372924805), (689,392517089844, 145,936782836914), (689,236633300781, 140,251724243164), (689,087707519531, 134,052627563477), (688,946350097656, 127,36393737793), (688,813110351562, 120,212066650391), (688,6884765625, 112,625244140625), (688,572937011719, 104,633407592773), (688,467041015625, 96,2680969238281), (688,37109375, 87,5623245239258), (688,285522460938, 78,5504455566406), (688,210693359375, 69,2680358886719), (688,146850585938, 59,7517127990723), (688,09423828125, 50,0390472412109), (688,053161621094, 40,1683654785156), (688,023681640625, 30,1786270141602), (688,005920410156, 20,1092491149902), (688, 9,99997711181641), (688,005920410156, -0,109296590089798), (688,023681640625, -10,1786727905273), (688,053161621094, -20,1684131622314), (688,09423828125, -30,0390911102295), (688,1468505...
GR32_Brushes.TCustomBrush.PolyPolygonFS($2101A80,(((694, 10), (693,994079589844, 20,1092739105225), (693,976318359375, 30,1786499023438), (693,946838378906, 40,1683921813965), (693,90576171875, 50,0390739440918), (693,853149414062, 59,7517356872559), (693,789306640625, 69,2680587768555), (693,714477539062, 78,5504684448242), (693,62890625, 87,5623474121094), (693,532958984375, 96,2681274414062), (693,427062988281, 104,633430480957), (693,3115234375, 112,625274658203), (693,186889648438, 120,212097167969), (693,053649902344, 127,363967895508), (692,912292480469, 134,052642822266), (692,763366699219, 140,251754760742), (692,607482910156, 145,936813354492), (692,445251464844, 151,085388183594), (692,27734375, 155,677169799805), (692,104370117188, 159,694030761719), (691,927062988281, 163,1201171875), (691,74609375, 165,94189453125), (691,562133789062, 168,148254394531), (691,3759765625, 169,73046875), (691,188354492188, 170,68229675293), (691, 171), (690,811645507812, 170,68229675293), (690,6240234375, 169,73046875), (690,437866210938, 168,148254394531), (690,25390625, 165,94189453125), (690,072937011719, 163,120101928711), (689,895629882812, 159,69401550293), (689,72265625, 155,677154541016), (689,554748535156, 151,085372924805), (689,392517089844, 145,936782836914), (689,236633300781, 140,251724243164), (689,087707519531, 134,052627563477), (688,946350097656, 127,36393737793), (688,813110351562, 120,212066650391), (688,6884765625, 112,625244140625), (688,572937011719, 104,633407592773), (688,467041015625, 96,2680969238281), (688,37109375, 87,5623245239258), (688,285522460938, 78,5504455566406), (688,210693359375, 69,2680358886719), (688,146850585938, 59,7517127990723), (688,09423828125, 50,0390472412109), (688,053161621094, 40,1683654785156), (688,023681640625, 30,1786270141602), (688,005920410156, 20,1092491149902), (688, 9,99997711181641), (688,005920410156, -0,109296590089798), (688,023681640625, -10,1786727905273), (688,053161621094, -20,1684131622314), (688,09423828125, -30,0390911102295), (688,146850585...
GR32_Paths.TCanvas32.DrawPath($2059A30)
GR32_Paths.TCustomCanvas.DoChanged
GR32_Paths.TCustomPath.EndUpdate
GR32_Paths.TFlattenedPath.Polygon(((694, 10), (693,994079589844, 20,1092739105225), (693,976318359375, 30,1786499023438), (693,946838378906, 40,1683921813965), (693,90576171875, 50,0390739440918), (693,853149414062, 59,7517356872559), (693,789306640625, 69,2680587768555), (693,714477539062, 78,5504684448242), (693,62890625, 87,5623474121094), (693,532958984375, 96,2681274414062), (693,427062988281, 104,633430480957), (693,3115234375, 112,625274658203), (693,186889648438, 120,212097167969), (693,053649902344, 127,363967895508), (692,912292480469, 134,052642822266), (692,763366699219, 140,251754760742), (692,607482910156, 145,936813354492), (692,445251464844, 151,085388183594), (692,27734375, 155,677169799805), (692,104370117188, 159,694030761719), (691,927062988281, 163,1201171875), (691,74609375, 165,94189453125), (691,562133789062, 168,148254394531), (691,3759765625, 169,73046875), (691,188354492188, 170,68229675293), (691, 171), (690,811645507812, 170,68229675293), (690,6240234375, 169,73046875), (690,437866210938, 168,148254394531), (690,25390625, 165,94189453125), (690,072937011719, 163,120101928711), (689,895629882812, 159,69401550293), (689,72265625, 155,677154541016), (689,554748535156, 151,085372924805), (689,392517089844, 145,936782836914), (689,236633300781, 140,251724243164), (689,087707519531, 134,052627563477), (688,946350097656, 127,36393737793), (688,813110351562, 120,212066650391), (688,6884765625, 112,625244140625), (688,572937011719, 104,633407592773), (688,467041015625, 96,2680969238281), (688,37109375, 87,5623245239258), (688,285522460938, 78,5504455566406), (688,210693359375, 69,2680358886719), (688,146850585938, 59,7517127990723), (688,09423828125, 50,0390472412109), (688,053161621094, 40,1683654785156), (688,023681640625, 30,1786270141602), (688,005920410156, 20,1092491149902), (688, 9,99997711181641), (688,005920410156, -0,109296590089798), (688,023681640625, -10,1786727905273), (688,053161621094, -20,1684131622314), (688,09423828125, -30,0390911102295), (688,146850585938, -39,7517547...
GR32_Paths.TCustomPath.Ellipse(691,10,3,161,100)

The parameter values to AddLineSegment are in fixed format, but the floating point values are:

688; 9,99997711181641; 688,005798339844; 0,0500000007450581

At the point of failure the X and Y values in AddLineSegment are 688, -2. Since these values are used as indices into a TIntegerMap the pointer value returned is outside the map and this pointer value is used in AddSegment causing the AV.

The problem can be reproduced with the Benchmark example.

@andersmelander
Copy link
Member Author

Same problem drawing a line: MoveTo(467, 0), LineTo(466, 280)
Same symptoms. Also reproduced with the Benchmark example.

@andersmelander
Copy link
Member Author

Source of problem appears to be an integer overflow in FixedDiv.

@PatmanSan
Copy link

FOpacityMap (TFloatMap in VPR2 and TIntegerMap in VPR2X) is created and set to size, but not initialized with data. Both AddLineSegment and DrawBitmap are reading from the uninitialized map, causing rounding and overflow errors further down the line. Adding FOpacityMap.Clear after FOpacityMap.SetSize eliminates the errors, which indicates that the map needs to be initialized with proper data for the renderer to do its magic.

@andersmelander
Copy link
Member Author

TPolygonRenderer32VPR2X was deprecated in 3aa6cb8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants