mirror of https://github.com/OpenTTD/OpenTTD
Fix #8825: [OpenGL] Don't clear cursor cache from the game loop thread.
parent
ee69a0dc29
commit
436cdf1fc8
|
@ -1051,6 +1051,19 @@ void OpenGLBackend::DrawMouseCursor()
|
||||||
|
|
||||||
void OpenGLBackend::PopulateCursorCache()
|
void OpenGLBackend::PopulateCursorCache()
|
||||||
{
|
{
|
||||||
|
if (this->clear_cursor_cache) {
|
||||||
|
/* We have a pending cursor cache clear to do first. */
|
||||||
|
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) {
|
for (uint i = 0; i < _cursor.sprite_count; ++i) {
|
||||||
SpriteID sprite = _cursor.sprite_seq[i].sprite;
|
SpriteID sprite = _cursor.sprite_seq[i].sprite;
|
||||||
|
|
||||||
|
@ -1070,14 +1083,11 @@ void OpenGLBackend::PopulateCursorCache()
|
||||||
*/
|
*/
|
||||||
void OpenGLBackend::ClearCursorCache()
|
void OpenGLBackend::ClearCursorCache()
|
||||||
{
|
{
|
||||||
this->last_sprite_pal = (PaletteID)-1;
|
/* If the game loop is threaded, this function might be called
|
||||||
|
* from the game thread. As we can call OpenGL functions only
|
||||||
Sprite *sp;
|
* on the main thread, just set a flag that is handled the next
|
||||||
while ((sp = this->cursor_cache.Pop()) != nullptr) {
|
* time we prepare the cursor cache for drawing. */
|
||||||
OpenGLSprite *sprite = (OpenGLSprite *)sp->data;
|
this->clear_cursor_cache = true;
|
||||||
sprite->~OpenGLSprite();
|
|
||||||
free(sp);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -63,6 +63,7 @@ private:
|
||||||
|
|
||||||
LRUCache<SpriteID, Sprite> cursor_cache; ///< Cache of encoded cursor sprites.
|
LRUCache<SpriteID, Sprite> cursor_cache; ///< Cache of encoded cursor sprites.
|
||||||
PaletteID last_sprite_pal = (PaletteID)-1; ///< Last uploaded remap palette.
|
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();
|
||||||
~OpenGLBackend();
|
~OpenGLBackend();
|
||||||
|
|
Loading…
Reference in New Issue