Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A single GPU_Flip() isn't updating the screen #245

Open
ramirez7 opened this issue Jan 24, 2023 · 7 comments
Open

A single GPU_Flip() isn't updating the screen #245

ramirez7 opened this issue Jan 24, 2023 · 7 comments

Comments

@ramirez7
Copy link
Contributor

ramirez7 commented Jan 24, 2023

I've been writing a little tool to visualize hitbox collisions. It's a function that takes two hitboxes, draws them + their collision manifold (if any), and then waits for Quit/Esc.

The code is basically

  • GPU_Init() with default flags
  • Draw shapes
  • Visualize manifold with circles and lines
  • GPU_Flip()
  • Loop over SDL events until Quit/Esc
  • GPU_Quit()

For some reason, the screen isn't being updated on that GPU_Flip() for me (it's just showing the pixels that were there if that makes sense - the way it behaves when you just spawn a window).

When I put GPU_Flip() in my wait loop and call it a bunch of times, everything does work. But I'm surprised a single one isn't working.

There is some indirection here: I am calling sdl-gpu from Haskell in its repl using my bindings. That said, I think I've done everything I need to for that to work (RTS is threaded, I'm using more than one native thread to back the green threads, the loop is running in a bound thread and not being shifted around OS thread in the b/g, etc). It is possible this is something on my end of the Haskell/C divide, but I figured I'd ask (and I'd like to fix it on my side anyways ofc).

@ramirez7
Copy link
Contributor Author

I've noticed that if I do a certain amount of GPU_Flips in a row before my wait loop, it works. On my machine, it's about 20. Which makes it feel like some sort of race condition to me.

@ramirez7
Copy link
Contributor Author

I've refactored the code to be more like my game loops:

  • GPU_Init() with default flags
  • Loop:
    • GPU_Clear()
    • Draw shapes and manifolds
    • SDL_PollEvent() and see if any Quit/Esc events are in there
      • If no, GPU_Flip() and SDL_Delay(100)
      • If so, GPU_Quit()

And it works fine. So maybe my understanding of how sdl-gpu works is off.

@grimfang4
Copy link
Owner

I am not at a computer to test anything, but you could try GPU_FlushBlitBuffer() before the flip. SDL_gpu does hold on to data in order to render it all in one go and double-buffering could also be involved (so front and back buffers might appear out of sync if you aren't clearing and flipping them every frame).

@ramirez7
Copy link
Contributor Author

GPU_FlushBlitBuffer() didn't make a difference either.

@ramirez7
Copy link
Contributor Author

I'll confirm I can make a minimal repro in C.

@albertvaka
Copy link
Contributor

Can you share it with us?

@ramirez7
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants