Skip to content

Commit 25d222b

Browse files
committed
Minimally fix the known unsoundness in bevy_mikktspace (#5299)
# Objective - 0.8 is coming soon, and our mikktspace implementation is unsound - see gltf-rs/mikktspace#26 - Best not to ship that ## Solution - Fix the unsoundness in a minimal way - Obviously there might be others, but it seems unlikely we have any way to know about those
1 parent a63d761 commit 25d222b

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

crates/bevy_mikktspace/src/generated.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -1060,8 +1060,8 @@ unsafe fn InitTriInfo<I: Geometry>(
10601060
let mut bChooseOrientFirstTri: bool = false;
10611061
if (*pTriInfos.offset((t + 1) as isize)).iFlag & 4i32 != 0i32 {
10621062
bChooseOrientFirstTri = true
1063-
} else if CalcTexArea(geometry, &*piTriListIn.offset((t * 3 + 0) as isize))
1064-
>= CalcTexArea(geometry, &*piTriListIn.offset(((t + 1) * 3 + 0) as isize))
1063+
} else if CalcTexArea(geometry, piTriListIn.offset((t * 3 + 0) as isize))
1064+
>= CalcTexArea(geometry, piTriListIn.offset(((t + 1) * 3 + 0) as isize))
10651065
{
10661066
bChooseOrientFirstTri = true
10671067
}
@@ -1503,9 +1503,7 @@ unsafe fn GenerateSharedVerticesIndexList<I: Geometry>(
15031503
vP_1.z
15041504
};
15051505
let iCell_0 = FindGridCell(fMin, fMax, fVal_0);
1506-
let mut pTable: *mut i32 = 0 as *mut i32;
1507-
pTable = &mut piHashTable[piHashOffsets[iCell_0] as usize] as *mut i32;
1508-
*pTable.offset(piHashCount2[iCell_0] as isize) = i as i32;
1506+
piHashTable[(piHashOffsets[iCell_0] + piHashCount2[iCell_0]) as usize] = i as i32;
15091507
piHashCount2[iCell_0] += 1;
15101508
i += 1
15111509
}
@@ -1525,7 +1523,7 @@ unsafe fn GenerateSharedVerticesIndexList<I: Geometry>(
15251523
k = 0;
15261524
while k < g_iCells {
15271525
// extract table of cell k and amount of entries in it
1528-
let mut pTable_0 = &mut piHashTable[piHashOffsets[k] as usize] as *mut i32;
1526+
let pTable_0 = piHashTable.as_mut_ptr().offset(piHashOffsets[k] as isize);
15291527
let iEntries = piHashCount[k] as usize;
15301528
if !(iEntries < 2) {
15311529
e = 0;

0 commit comments

Comments
 (0)