Hello. I have a #soa[dynamic]Sprite that I want to zero out
First I tried this:
. But then I got some bug like one of the fields of different entity was overwritten. So then I tried:
And it solved that bug. Do I have to manually assign each field of that sprite to zero value or is there a better way?
r.sprites[e] = {} should be correct, but there does seem to be a bug with it. It always seems to write 8 bytes of data into every field’s data, regardless of what the actual type is.
This seems to reproduce it, including on the latest release:
package mre
import "core:fmt"
Sprite :: struct {
a: u8,
b: u16,
c: u32,
d: u64,
e: u128,
}
main :: proc() {
sprites := make(#soa[dynamic]Sprite, 0, 32)
for _ in 0..<32 {
append(&sprites, Sprite {1, 2, 3, 4 << 32 | 4, 5 << 64 | 5})
}
sprites[16] = {}
for &sprite, i in sprites {
fmt.println(i, sprite)
}
}
This clear 8 consecutive indices of a, 4 of b, 2 of c, correctly just the one of d, and doesn’t fully clear e.
Make a GitHub issue, if there isn’t one for this already.
Odin is great, but even the best programming language won’t make one a good architect.
You could try using the ordered_remove_soa, but that may break other code sections where the logic depends on the array’s length.
How about this?
zero_sprite := Sprite{}
r.sprites[e] = zero_sprite
zero_sprite := Sprite{}
r.sprites[e] = zero_sprite
Seems to solve the problem. But I don’t know if thats the intended behaviour or a bug that you can’t just do r.sprites[e] = Sprite{}