grimfang4 / sdl-gpu

A library for high-performance, modern 2D graphics with SDL written in C.
MIT License
1.19k stars 123 forks source link

SIGSEGV illegal storage access when trying to access window after init #234

Closed BTOdell closed 2 years ago

BTOdell commented 2 years ago

We're using Nim and the sdl2_nim binding library to access sdl2 and sdl2_gpu. GPU_Init is invoked to create the screen target and this successfully creates the underlying window and everything works fine.

However, by default the window has no title or icon. We tried to use the code below to access the underlying window so we could call SDL functions for setting the title and icon. This works on Linux but on Windows it generates a fatal SIGSEGV exception when it accesses target.context:

let target = init(uint16 gameWidth, uint16 gameHeight, uint32 windowFlags)
if target == nil:
  raise newException(Exception, "Failed to init SDL!")

if target.context != nil:
  let window = getWindowFromId(target.context.windowID)
  window.setWindowTitle(title)
  if iconFilename.len > 0:
    let iconSurface = loadSurface(iconFilename)
    window.setWindowIcon(iconSurface)
    freeSurface(iconSurface)

image

My guess is that the binding wrapper struct for the Target object may be out of date and missing certain fields that cause the context field to be misaligned. We're going to review the bindings to see if we can find anything missing, but if you can suggest any solutions that would be great! Thanks!

I'm working on this with @avahe-kellenberger AND THERE IS ONLY 32 HOURS LEFT IN THE GAME JAM HELP!

BTOdell commented 2 years ago

It was the bindings...

grimfang4 commented 2 years ago

Glad it was just that. I hope it wasn't too much of a hurdle for your jam.