Odin icon indicating copy to clipboard operation
Odin copied to clipboard

linalg.transpose from column to row matrix causes segfault

Open tgolsson opened this issue 3 months ago • 2 comments

Context

Starting from #3686 and potentially related to #2641, I've found another segfault when converting to row_major matrices:

package transpose_crash_repro

import "core:fmt"
import "core:math/linalg"


main :: proc() {
        a := (# row_major matrix[4, 4]f32)(1)
        b1: # column_major matrix[4, 4]f32 = linalg.transpose(a)
        b2: # row_major matrix[4, 4]f32 = linalg.transpose(a)
        fmt.println("row -> {row, column} ok")

        c := (# column_major matrix[4, 4]f32)(1)
        d1: # column_major matrix[4, 4]f32 = linalg.transpose(c)
        fmt.println("column -> column ok")

        d2: # row_major matrix[4, 4]f32 = linalg.transpose(c)
        fmt.println("column -> row broken")
}

Fails on the last transpose but none before it.

$ odin run test.odin -file
row -> {row, column} ok
column -> column ok
Segmentation fault (core dumped)

Failure Information (for bugs)

odin version dev-2025-08-nightly

tgolsson avatar Aug 27 '25 21:08 tgolsson

Still get hit by this in dev 2025 11.

SlashScreen avatar Nov 29 '25 11:11 SlashScreen

I reverted my fix because it was an immediate fix, but wasn't doing the right thing. To be clear this should behave as a cast, so these lines should do the same thing:

a := cast(#row_major matrix[4, 4]f32)src
b: #row_major matrix[4, 4]f32 = linalg.transpose(src)

I did add a panic, so it's a compile time error instead of a runtime error now.

laytan avatar Nov 29 '25 19:11 laytan