Fix: ensure switching blitter happens in the main thread

This because video-drivers might need to make changes to their
context, which for most video-drivers has to be done in the same
thread as the window was created; main thread in our case.
This commit is contained in:
Patric Stout
2021-03-08 14:50:06 +01:00
committed by Patric Stout
parent e56d2c63c3
commit 8946b41d20
3 changed files with 44 additions and 10 deletions

View File

@@ -308,18 +308,11 @@ static bool SwitchNewGRFBlitter()
}
if (BlitterFactory::GetBlitterFactory(repl_blitter) == nullptr) continue;
DEBUG(misc, 1, "Switching blitter from '%s' to '%s'... ", cur_blitter, repl_blitter);
Blitter *new_blitter = BlitterFactory::SelectBlitter(repl_blitter);
if (new_blitter == nullptr) NOT_REACHED();
DEBUG(misc, 1, "Successfully switched to %s.", repl_blitter);
/* Inform the video driver we want to switch blitter as soon as possible. */
VideoDriver::GetInstance()->ChangeBlitter(repl_blitter);
break;
}
if (!VideoDriver::GetInstance()->AfterBlitterChange()) {
/* Failed to switch blitter, let's hope we can return to the old one. */
if (BlitterFactory::SelectBlitter(cur_blitter) == nullptr || !VideoDriver::GetInstance()->AfterBlitterChange()) usererror("Failed to reinitialize video driver. Specify a fixed blitter in the config");
}
return true;
}