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

Fix crash in export and freeze in infill generation #1518

Merged
merged 4 commits into from
Oct 29, 2021

Conversation

Ghostkeeper
Copy link
Collaborator

@Ghostkeeper Ghostkeeper commented Oct 28, 2021

This fixes one suspected issue and one actual issue.

Commit 3a9307c fixes a suspected issue where the g-code export was writing uninitialised memory. I still don't know exactly why it was causing an issue since to me, the g-code coordinates looked like they were still in proper memory. However apparently not. Before fixing this, I was getting an assertion failure about coordinates being out of reasonable range (>1m from the origin). After fixing this, that error disappeared.
Aside from that, the change is also neater. We should not use references for objects that are the size of a pointer or smaller, and coord_t is 64 bits for all of our releases, which is the size of a pointer too on those platforms. And we should use coord_t, not int, for coordinates.

Commit 618a8ab is an actual fix of a serious bug in the simplify function, or perhaps more generally. The simplify function can choose to omit a line segment by introducing a new vertex in the intersection point of the two line segments around it. So rather than printing 3 line segments where the middle one is tiny, it chooses to continue in the direction of the first line segment until they intersect and can continue in a straight line to the last line segment, saving 1 vertex. The intersection point is checked to see if it's not too far away. However it was encountering an intersection point that was so far away (~300km) that calculating the distance to it ended up a negative number due to integer overflow. The distance check thought it was then actually really close by, accepting the far vertex into the resulting polygon. This caused the infill area in this model to become 300km wide, resulting in CuraEngine freezing trying to optimize millions of infill lines that filled that area.
The fix regards lines as not-intersecting if the intersection point is really far away. It'll mean that these lines are almost parallel. Pretending that they are parallel then works practically, and also prevents overflow errors like this.

Fixes Ultimaker/Cura#10505 .
Fixes CURA-8622.

This would theoretically increase memory usage, but in practice leads to compiler optimisations since it won't need to cast to smaller ints. Let's hope it's not a noticeable impact.
This also seems to fix a rare bug where the references to these coordinates were invalidated when exporting g-code. Ints and coord_t shouldn't be passed by reference anyway.

Contributes to issue CURA-8622.
This can lead to overflow errors. If we start using points with those really far coordinates, we may end up with coordinates where we will get integer overflows if we calculate distances between them.
The coordinate check performed here checks if the points are within 2.1km of the origin. I think that's pretty safe for most printers. When we get printers to print cities we'll be in trouble, but we'll see about that when we get there...

Such integer overflows were causing the simplify function to accept intersection points that were extremely far away, since the calculated distance to them ended up negative. These far intersection points were then included in the resulting polygon, resulting in attempts to fill polygons of literally 300km length. Not nice.

Contributes to issue CURA-8622.
src/utils/linearAlg2D.h Outdated Show resolved Hide resolved
@rburema rburema merged commit fa4fa12 into 4.12 Oct 29, 2021
@rburema rburema deleted the CURA-8622_crash_exporting branch October 29, 2021 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants