Hi there. I'm having a kinda beginner moment here. I have a proc that creates a struct and during the struct setup I pass a pointer to it to a callback proc in order to register a "listener".
Relevant code:
create_canvas :: proc(state: ^State, width: i32, height: i32) -> Canvas {
canvas: Canvas = {}
canvas.width = width
canvas.height = height
canvas.surface = wl.wl_compositor_create_surface(state.compositor)
if canvas.surface == nil {
fmt.println("Error creating surface")
return canvas
}
egl_window := wl.egl_window_create(canvas.surface, width, height)
egl_surface := egl.CreateWindowSurface(
state.egl_render_context.display,
state.egl_render_context.config,
egl.NativeWindowType(egl_window),
nil,
)
if egl_surface == egl.NO_SURFACE {
fmt.println("Error creating window surface")
}
if (!egl.MakeCurrent(
state.egl_render_context.display,
egl_surface,
egl_surface,
state.egl_render_context.ctx,
)) {
fmt.println("Error making current!")
}
canvas.egl_surface = egl_surface
canvas.xdg_surface = wl.xdg_wm_base_get_xdg_surface(state.xdg_base, canvas.surface)
toplevel := wl.xdg_surface_get_toplevel(canvas.xdg_surface)
wl.xdg_toplevel_set_title(toplevel, "Odin Wayland")
fmt.println("Canvas", canvas)
wl.xdg_surface_add_listener(canvas.xdg_surface, &surface_listener, &canvas)
return canvas
}
On the call to xdg_surface_add_listener() it's where I pass the canvas pointer. After that the idea would be to return the finished struct.
Problem: the struct pointer get to the callback with all the data corrupted. The argument is a rawptr that I then cast(^Canvas)
If I comment that line and do the exact same thing in the main loop, no issues.
Lost here, feeling i'm missing something important (potentially really basic)