Simd error after updating to Catalina - Swift

167 Views Asked by At

Previously working code now gets an error:

var row1 = simd_double3(x:CV1.x, y: CV1.y, z:CV1.z)
var row2 = simd_double3(x:CV2.x, y: CV2.y, z:CV2.z)
var row3 = simd_double3(x:self.n.x, y: self.n.y, z:self.n.z)
var m:simd_double3x3 = simd_double3x3(rows: [row1, row2, row3])
self.majorInvMatrix = m.inverse

The allocation of m.inverse gets

EXC_BAD_ACCESS(code=EXC_1386GPFLT)

Changing it to

let zz = m.inverse

still gives the error, but if I interrupt the code before the allocation and look at m.inverse in the console there isn't a problem.

If I add in the line var a = 2 there is no problem (it doesn't work with let a = 2)

var row1 = simd_double3(x:CV1.x, y: CV1.y, z:CV1.z)
var row2 = simd_double3(x:CV2.x, y: CV2.y, z:CV2.z)
var row3 = simd_double3(x:self.n.x, y: self.n.y, z:self.n.z)
var m:simd_double3x3 = simd_double3x3(rows: [row1, row2, row3])
var a = 2
self.majorInvMatrix = m.inverse
1

There are 1 best solutions below

0
JeremyP On

This is an operating system bug, or rather an OS library bug. In simple terms, the compiler and the SIMD library disagree about how the simd_double3x3 should be aligned in memory.

Your var a = 2 changes the alignment of things on the stack which is why it works (in your case - not mine, unfortunately).

The problem will be fixed in 10.15.4.

Full details on this thread:

https://forums.developer.apple.com/thread/127976