libsdl-org / SDL

Simple Directmedia Layer
https://libsdl.org
zlib License
9.81k stars 1.82k forks source link

Access violation error when pushing user events #11339

Open JBetz opened 2 hours ago

JBetz commented 2 hours ago

Every so often I get an access violation error when trying to push a SDL_UserEvent to the event queue. I haven't found a reliable way to reproduce it, but wanted to report in case anyone recognizes the error, or has any advice around potential issues when using this feature in a language with garbage collection. My understanding is that the SDL_Event is safe to dispose of after SDL_PushEvent returns, so I'm not sure what could be going wrong.

Here's the topmost SDL call which shows values in the event struct:

image

Here's the bottommost SDL call:

image

And here's the assembly in memcpy that throws the exception:

image

JBetz commented 2 hours ago

I just noticed that the event's timestamp field is 174255680834700 / 16r9E7C0FF4CC8C when it should be 0. The values for windowID and code, however, are correct. So likely this is an issue with how Uint64 is represented in the language I'm calling SDL from (Dolphin Smalltalk, which is 32-bit).

JBetz commented 1 hour ago

Usually the timestamp has the correct value, though, and I never set it to anything other than 0. So the weird thing is that it's only sometimes somehow gets a garbage value.

I've added a conditional breakpoint in my application for any case where the timestamp is not equal to zero, to see whether it gets the garbage value before or during the SDL call.

madebr commented 59 minutes ago

It looks like it fails to read event+0x40 (64 bytes). Events must be exactly 128 bytes: https://github.com/libsdl-org/SDL/blob/8468c372b21b937d7adb340c4725d77c7d87c4d9/include/SDL3/SDL_events.h#L996