0
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.

iBug
  • 35,554
  • 7
  • 89
  • 134
  • 1
    `sdl.PushEvent` takes an `Event` not a `*Event`, but that's not the main problem here. The problem is that the `Data1` and `Data2` pointers here must be C pointers, not Go pointers. You'll need to allocate some C memory for this. – torek Aug 20 '22 at 10:38
  • @torek FYI: `Event` is an interface, so either `UserEvent` or `*UserEvent` should be fine. – iBug Aug 20 '22 at 16:19
  • Ah, I didn't get as far as finding the type of `Event` itself in my rapid scan (though it should have occurred to me that it probably was an interface, since sdl.UserEvent isn't itself an Event). – torek Aug 20 '22 at 16:24

0 Answers0