9 Replies
      Latest reply on Jan 16, 2020 3:17 AM by Fritzt
      Fritzt Level 1 Level 1 (10 points)

        I'm struggling to get an app working on Catalina 10.15.2 using Xcode 11.3.1, Swift 5. I could manage to boil down an example of the crash for Xcode Playgrounds:

         

        import Cocoa
        import simd
        
        var viewMatrix = double4x4(1)
        var modelMatrix = double4x4(1)
        
        let modelViewMatrix = viewMatrix * modelMatrix
        
        var m = modelViewMatrix.transpose.inverse
        
        print(m)

         

        I get an

         

        error: Execution was interrupted, reason: EXC_BAD_ACCESS (code=EXC_I386_GPFLT).

         

        like in the full app. Any idea what's wrong and why the code it crashing? App code works fine running natively on macOS 10.14.6 and iOS 13.

         

        Thanks!

        • Re: crash with simple simd code in Swift
          Claude31 Level 8 Level 8 (7,845 points)

          Yes, surprising bug:

           

          In OSX 10.14, playground OSX, this works

          import simd
           
          var viewMatrix = double4x4(1)
          var modelMatrix = double4x4(1)
          let modelViewMatrix = viewMatrix * modelMatrix
          var m = modelViewMatrix.transpose.inverse
          
          print(m)

           

          simd_double4x4([[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]])

           

          The same crashes on Catalina.

           

          But this works:

           

          import simd
           
          var viewMatrix = double4x4(1)
          var modelMatrix = double4x4(1)
          let modelViewMatrix = viewMatrix * modelMatrix
          var m = modelViewMatrix.transpose.inverse
           
          print(viewMatrix)
          print(modelViewMatrix)
          print(m)

           

          simd_double4x4([[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]])

          simd_double4x4([[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]])

          simd_double4x4([[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]])

           

           

          Removing any of line 8 or 9 causes crash

           

          This code crashes in an OSX App with EXC_BAD_ACCESS (code= EXC_i386_GPFLT) error.

          Same error without transpose, just inverse (logic).the following causes crash in app but not in playground:

           

          import simd
          
          var viewMatrix = double4x4(1)
          var m = viewMatrix.inverse
          
          print(m)

           

          I replaced double4x4 by float4x4, it works in code and in playground, even without additional print.

           

          Tested with 3x3, same problem.

           

          There is definitely a bug here. Should file a bug report (I'll do it).

           

          EDITED: bug filed. FB7534934

          • Re: crash with simple simd code in Swift
            Claude31 Level 8 Level 8 (7,845 points)

            Exact, works in iOS13 simulator on macOS 10.14.6.

            Works also in simulator on Catalina.

            Note: you don't import Cocoa in an iOS App.

            • Re: crash with simple simd code in Swift
              Claude31 Level 8 Level 8 (7,845 points)

              Any idea what's wrong and why the code it crashing?

               

              I do suspect a bug in the library that handles double operations (the problem is visibly there since a long time, but not problem with float).

                • Re: crash with simple simd code in Swift
                  eskimo Apple Staff Apple Staff (12,705 points)

                  Any idea what's wrong and why the code it crashing?

                  The crash seems to be caused by an alignment issue.  There is disagreement between the compiler and the system as to how these values should be aligned, and alignment is critical for the SIMD instructions that actually back all of this stuff.

                  Share and Enjoy

                  Quinn “The Eskimo!”
                  Apple Developer Relations, Developer Technical Support, Core OS/Hardware
                  let myEmail = "eskimo" + "1" + "@apple.com"

                    • Re: crash with simple simd code in Swift
                      Claude31 Level 8 Level 8 (7,845 points)

                      So, that's a bug in library ? Compiler ?

                       

                      What is really suprising is that adding print statement eliminates the crash in some cases (I detailed in bug report FB7534934).

                        • Re: crash with simple simd code in Swift
                          eskimo Apple Staff Apple Staff (12,705 points)

                          So, that's a bug in library ? Compiler ?

                          The jury is still out on that one (-:

                          What is really suprising is that adding print statement eliminates the crash in some cases

                          This is probably because adding a print statement causes the compiler to lay out the stack differently, which changes the alignment of the value passed to the system.

                          Share and Enjoy

                          Quinn “The Eskimo!”
                          Apple Developer Relations, Developer Technical Support, Core OS/Hardware
                          let myEmail = "eskimo" + "1" + "@apple.com"

                        • Re: crash with simple simd code in Swift
                          Fritzt Level 1 Level 1 (10 points)

                          I was afraid of such an answer. Since I only experience these crashes when trying to invert matrices, I might write my own function and hope for the best. But a timely fix in the OS or compiler would of course be much more welcome. If one could only get an estimate for the time frame ... Thanks for the help!