Skip to content

Commit 36a1f1e

Browse files
Workaround a Squeak3D crash
After proper instrumentation, it appears that a reproducible crash case provided by Stephane Rollandin is due to attempt of removing a face which is not in the fillList. This happens in the special case when `leftEdge == lastIntersection`, and the code attempts to remove `leftEdge->rightFace` which seem to not always be on the fillList. It's not obvious to understand if this is really an invariant of the loop, or a wrong expectation. Thus, as a workaround, protect the removal by a preliminary inclusion test. Note that removing or adding a face should change its `B3D_FACE_ACTIVE` flags. Normally, we remove then add, so do not have to toggle the flag. But if we do not remove, then we must toggle, otherwise another invariant will break and cause crash in `b3dToggleTopFills`.
1 parent 3a0e796 commit 36a1f1e

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

platforms/Cross/plugins/Squeak3D/b3dMain.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,9 +1374,12 @@ int b3dMainLoop(B3DRasterizerState *state, int stopReason)
13741374

13751375
/*-- Toggle the faces of the top edge (the left edge is always on top) --*/
13761376
if(leftEdge == lastIntersection) {
1377-
/* Special case if this is a intersection edge */
1377+
/* Special case if this is an intersection edge */
13781378
assert(fillList->firstFace == leftEdge->leftFace);
1379-
b3dRemoveFill(fillList, leftEdge->rightFace);
1379+
if(b3dIsInFillList(fillList,leftEdge->rightFace))
1380+
b3dRemoveFill(fillList, leftEdge->rightFace);
1381+
else
1382+
leftEdge->rightFace->flags ^= B3D_FACE_ACTIVE;
13801383
b3dAddFrontFill(fillList, leftEdge->rightFace);
13811384
} else {
13821385
b3dToggleTopFills(fillList, leftEdge, yValue);

0 commit comments

Comments
 (0)