"Cgo argument has Go pointer to Go pointer" with sdl.PushEvent and non-empty struct

105 Views Asked by At
package main

import (
    "unsafe"

    "github.com/veandco/go-sdl2/sdl"
)

type MyType struct {
    A int
}

func main() {
    if err := sdl.Init(sdl.INIT_EVENTS); err != nil {
        panic(err)
    }

    ty := sdl.RegisterEvents(1)
    sdl.PushEvent(&sdl.UserEvent{
        Type:      ty,
        Timestamp: sdl.GetTicks(),
        Data1:     unsafe.Pointer(&MyType{}),
    })
}

I am trying to send a Go struct through sdl.PushEvent, which gives the error in the title if and only if the struct is not empty. I can't use an empty struct because it would be meaningless. Is there any way to do this?

To clarify: With type MyType struct{} the code works, but if MyType has any member it fails.

I'm running on Go 1.19.

0

There are 0 best solutions below