Skip to content

Instantly share code, notes, and snippets.

@michicc
Created March 8, 2021 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michicc/eace438cd7ec37b61a13c1597f032849 to your computer and use it in GitHub Desktop.
Save michicc/eace438cd7ec37b61a13c1597f032849 to your computer and use it in GitHub Desktop.
diff --git a/src/video/opengl.cpp b/src/video/opengl.cpp
index 64ea02cf2..07b10d720 100644
--- a/src/video/opengl.cpp
+++ b/src/video/opengl.cpp
@@ -1051,6 +1051,18 @@ void OpenGLBackend::DrawMouseCursor()
void OpenGLBackend::PopulateCursorCache()
{
+ if (this->clear_cursor_cache) {
+ this->clear_cursor_cache = false;
+ this->last_sprite_pal = (PaletteID)-1;
+
+ Sprite *sp;
+ while ((sp = this->cursor_cache.Pop()) != nullptr) {
+ OpenGLSprite *sprite = (OpenGLSprite *)sp->data;
+ sprite->~OpenGLSprite();
+ free(sp);
+ }
+ }
+
for (uint i = 0; i < _cursor.sprite_count; ++i) {
SpriteID sprite = _cursor.sprite_seq[i].sprite;
@@ -1070,14 +1082,7 @@ void OpenGLBackend::PopulateCursorCache()
*/
void OpenGLBackend::ClearCursorCache()
{
- this->last_sprite_pal = (PaletteID)-1;
-
- Sprite *sp;
- while ((sp = this->cursor_cache.Pop()) != nullptr) {
- OpenGLSprite *sprite = (OpenGLSprite *)sp->data;
- sprite->~OpenGLSprite();
- free(sp);
- }
+ this->clear_cursor_cache = true;
}
/**
diff --git a/src/video/opengl.h b/src/video/opengl.h
index 3919179e4..c17a8536d 100644
--- a/src/video/opengl.h
+++ b/src/video/opengl.h
@@ -63,6 +63,7 @@ private:
LRUCache<SpriteID, Sprite> cursor_cache; ///< Cache of encoded cursor sprites.
PaletteID last_sprite_pal = (PaletteID)-1; ///< Last uploaded remap palette.
+ bool clear_cursor_cache = false; ///< A clear of the cursor cache is pending.
OpenGLBackend();
~OpenGLBackend();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment