]> git.xonotic.org Git - xonotic/netradiant.git/commitdiff
Do not crash in Winding_Clip when using -D_GLIBCXX_ASSERTIONS 194/head
authorWalter Doekes <walter+github@wjd.nu>
Sun, 17 Jul 2022 20:16:36 +0000 (22:16 +0200)
committerWalter Doekes <walter+github@wjd.nu>
Sun, 17 Jul 2022 20:16:39 +0000 (22:16 +0200)
When setting -D_GLIBCXX_ASSERTIONS, invalid vector accesses are found,
like empty_vector.back(). In this case, the result was not used so the
bug wasn't found without the assertion.

This changeset fixes so dragging a brush to 0 size does not crash/abort
netradiant.

Closes #156.

radiant/winding.cpp

index 9651af2c2c027dc665fbda6d9f91dfa7ddb721ec..8865db52aff206f4a0050d90eac9608c90b64f7d 100644 (file)
@@ -194,6 +194,10 @@ const double DEBUG_EPSILON_SQUARED = DEBUG_EPSILON * DEBUG_EPSILON;
 /// If \p winding is completely in back of the plane, \p clipped will be empty.
 /// If \p winding intersects the plane, the edge of \p clipped which lies on \p clipPlane will store the value of \p adjacent.
 void Winding_Clip( const FixedWinding& winding, const Plane3& plane, const Plane3& clipPlane, std::size_t adjacent, FixedWinding& clipped ){
 /// If \p winding is completely in back of the plane, \p clipped will be empty.
 /// If \p winding intersects the plane, the edge of \p clipped which lies on \p clipPlane will store the value of \p adjacent.
 void Winding_Clip( const FixedWinding& winding, const Plane3& plane, const Plane3& clipPlane, std::size_t adjacent, FixedWinding& clipped ){
+       // if there are no points, we're done
+       if ( winding.size() == 0 ) {
+               return;
+       }
        PlaneClassification classification = Winding_ClassifyDistance( plane3_distance_to_point( clipPlane, winding.back().vertex ), ON_EPSILON );
        PlaneClassification nextClassification;
        // for each edge
        PlaneClassification classification = Winding_ClassifyDistance( plane3_distance_to_point( clipPlane, winding.back().vertex ), ON_EPSILON );
        PlaneClassification nextClassification;
        // for each edge