Skip to content

Commit

Permalink
Fixed an OpenGL problem which causes a crash on some systems.
Browse files Browse the repository at this point in the history
When in OpenGL mode, SDL_GL_SwapBuffers should be used instead of SDL_Flip.
And only once per frame.
  • Loading branch information
karadoc committed Jan 13, 2024
1 parent 123b37f commit 7138594
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
10 changes: 6 additions & 4 deletions src/Engine/Screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ void Screen::flip()

if (getWidth() != _baseWidth || getHeight() != _baseHeight || useOpenGL())
{
Zoom::flipWithZoom(_surface.get(), _screen, _topBlackBand, _bottomBlackBand, _leftBlackBand, _rightBlackBand, &glOutput);
Zoom::blitWithZoom(_surface.get(), _screen, _topBlackBand, _bottomBlackBand, _leftBlackBand, _rightBlackBand, &glOutput);
}
else
{
Expand All @@ -221,9 +221,11 @@ void Screen::flip()
_pushPalette = false;
}



if (SDL_Flip(_screen) == -1)
if (useOpenGL())
{
SDL_GL_SwapBuffers();
}
else if (SDL_Flip(_screen) == -1)
{
throw Exception(SDL_GetError());
}
Expand Down
3 changes: 1 addition & 2 deletions src/Engine/Zoom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ bool Zoom::haveSSE2()
* @param rightBlackBand Size of right black band in pixels (letterboxing).
* @param glOut OpenGL output.
*/
void Zoom::flipWithZoom(SDL_Surface *src, SDL_Surface *dst, int topBlackBand, int bottomBlackBand, int leftBlackBand, int rightBlackBand, OpenGL *glOut)
void Zoom::blitWithZoom(SDL_Surface *src, SDL_Surface *dst, int topBlackBand, int bottomBlackBand, int leftBlackBand, int rightBlackBand, OpenGL *glOut)
{
int dstWidth = dst->w - leftBlackBand - rightBlackBand;
int dstHeight = dst->h - topBlackBand - bottomBlackBand;
Expand All @@ -677,7 +677,6 @@ void Zoom::flipWithZoom(SDL_Surface *src, SDL_Surface *dst, int topBlackBand, in
SDL_BlitSurface(src, 0, glOut->surface.get(), 0); // TODO; this is less than ideal...

glOut->refresh(glOut->linear, glOut->iwidth, glOut->iheight, dst->w, dst->h, topBlackBand, bottomBlackBand, leftBlackBand, rightBlackBand);
SDL_GL_SwapBuffers();
}
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion src/Engine/Zoom.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Zoom

public:
/// Flip screen given src and dst; might use software or OpenGL.
static void flipWithZoom(SDL_Surface *src, SDL_Surface *dst, int topBlackBand, int bottomBlackBand, int leftBlackBand, int rightBlackBand, OpenGL *glOut);
static void blitWithZoom(SDL_Surface *src, SDL_Surface *dst, int topBlackBand, int bottomBlackBand, int leftBlackBand, int rightBlackBand, OpenGL *glOut);
/// Copy src to dst, resizing as needed. Please don't use flipx or flipy as the optimized functions ignore these parameters.
static int _zoomSurfaceY(SDL_Surface * src, SDL_Surface * dst, int flipx, int flipy);
/// Check for SSE2 instructions using CPUID.
Expand Down

0 comments on commit 7138594

Please sign in to comment.