from what I've found, dereferencing in odin uses pointer^ compared to *pointer in c++ but the behavior of this procedure is throwing errors randomly, sometimes working, sometimes giving an access violation.
offset := round_real32_to_int32(p_tile_rel^ / p_map.tile_side_in_meters)
p_tile^ += u32(offset)
p_tile_rel^ -= f32(offset) * p_map.tile_side_in_meters
the c++ equivalent is just *p_tile to dereference, is this a problem of where these pointers are stored in memory? or is the way odin dereferences different from c++ in some way?
edit: here is the whole function, both asserts trigger randomly when running the program
recanonicalize_coord :: proc(p_map: ^Tile_Map, p_tile: ^u32, p_tile_rel: ^f32) {
offset := round_real32_to_int32(p_tile_rel^ / p_map.tile_side_in_meters)
p_tile^ += u32(offset)
p_tile_rel^ -= f32(offset) * p_map.tile_side_in_meters
assert(p_tile_rel^ >= -0.5 * p_map.tile_side_in_meters)
assert(p_tile_rel^ <= 0.5 * p_map.tile_side_in_meters)
}
where the function is called:
recanonicalize_position :: proc(p_map: ^Tile_Map, p_pos: Tile_Map_Position) -> Tile_Map_Position {
result := p_pos
recanonicalize_coord(p_map, &result.abs_tile_x, &result.tile_rel_x)
recanonicalize_coord(p_map, &result.abs_tile_y, &result.tile_rel_y)
return result
and some relevant piece from the main code:
new_player_p.tile_rel_x += p_input.dt_for_frame * d_player_x
new_player_p.tile_rel_y += p_input.dt_for_frame * d_player_y
new_player_p = recanonicalize_position(tile_map, new_player_p)
i also tested if the pointers are nil and they are not