raddebugger icon indicating copy to clipboard operation
raddebugger copied to clipboard

Watch expressions don't understand Jai static arrays when they are global

Open charlesastaylor opened this issue 7 months ago • 0 comments

Hey Ryan, I've bumped into a few issues when trying to use type views from jai that haven't seemed worth reporting but this one is concrete enough I think it might be. You can find some discussion in the jai beta discord about this here, I'll try summarise the issue below.

Actually, in the process of writing this report I realise the issue is only to do with globals, I have updated the title to reflect that but left the above comment for original context! Globals in jai have reference types, which appears to be what is causing the issue.

Jai dynamic arrays ([..] T) and array views ([] T) have .data and .count members so when doing watch expressions with them this issue isn't apparent. For static arrays ([N] T), in jai code you can use the same data/count members but in the output executable the type is just a straight, c style, array.

My example program with some raddbg_pins showing the issues:

My_Struct :: struct {
    a, b, c: int;
}

data:  [10] My_Struct;
data2: [10] My_Struct;

main :: () {
    for * data {
        it.a = it_index * 3 + 0;
        it.b = it_index * 3 + 1;
        it.c = it_index * 3 + 2;
    }

    for * data2 {
        it.a = data[it_index].a * 10;
        it.b = data[it_index].b * 10;
        it.c = data[it_index].c * 10;
    }

    p1 := data.data;
    p2 := data2.data;

    what_about_a_local_array: [5] My_Struct;
    what_about_a_local_array[0].a = 123;
    for * what_about_a_local_array  it.* = data[it_index];

    // This doesn't work        raddbg_pin(data[3])
    // This does                raddbg_pin(p1[3])
    // Local arrays work ok     raddbg_pin(what_about_a_local_array[3])

    // Some more examples from what I was originally trying to do, before realise the issue was actually
    // to do with being a global:
    //
    // NO GOOD  raddbg_pin(columns(sequence(10), data[$].a, data2[$].a))
    //    GOOD  raddbg_pin(columns(sequence(10), p1[$].a, p2[$].a))
    //    GOOD  raddbg_pin(columns(sequence(5), what_about_a_local_array[$].a, what_about_a_local_array[$].a))
    //
    // NO GOOD  raddbg_pin(columns(array(data, 10), rows($, a), omit($, a)))
    //    GOOD  raddbg_pin(columns(array(p1, 10), rows($, a), omit($, a)))
    //    GOOD  raddbg_pin(columns(array((My_Struct*)data, 10), rows($, a), omit($, a)))
 
    debug_break();
}

charlesastaylor avatar Aug 25 '25 08:08 charlesastaylor