mirror of
https://github.com/WinampDesktop/winamp.git
synced 2025-06-20 00:05:41 -04:00
Qt: Fix crash on language change with system active
This commit is contained in:
@ -709,12 +709,14 @@ std::string MainWindow::getDeviceDiscPath(const QString& title)
|
||||
|
||||
void MainWindow::recreate()
|
||||
{
|
||||
if (s_system_valid)
|
||||
const bool was_display_created = m_display_created;
|
||||
if (was_display_created)
|
||||
{
|
||||
requestShutdown(false, true, true);
|
||||
|
||||
while (s_system_valid)
|
||||
g_emu_thread->setSurfaceless(true);
|
||||
while (m_display_widget || !g_emu_thread->isSurfaceless())
|
||||
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents, 1);
|
||||
|
||||
m_display_created = false;
|
||||
}
|
||||
|
||||
// We need to close input sources, because e.g. DInput uses our window handle.
|
||||
@ -724,11 +726,19 @@ void MainWindow::recreate()
|
||||
g_main_window = nullptr;
|
||||
|
||||
MainWindow* new_main_window = new MainWindow();
|
||||
DebugAssert(g_main_window == new_main_window);
|
||||
new_main_window->show();
|
||||
deleteLater();
|
||||
|
||||
// Reload the sources we just closed.
|
||||
g_emu_thread->reloadInputSources();
|
||||
|
||||
if (was_display_created)
|
||||
{
|
||||
g_emu_thread->setSurfaceless(false);
|
||||
g_main_window->updateEmulationActions(false, System::IsValid(), Achievements::IsHardcoreModeActive());
|
||||
g_main_window->onFullscreenUIStateChange(g_emu_thread->isRunningFullscreenUI());
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::destroySubWindows()
|
||||
@ -2464,10 +2474,11 @@ void MainWindow::showEvent(QShowEvent* event)
|
||||
void MainWindow::closeEvent(QCloseEvent* event)
|
||||
{
|
||||
// If there's no VM, we can just exit as normal.
|
||||
if (!s_system_valid)
|
||||
if (!s_system_valid || !m_display_created)
|
||||
{
|
||||
saveGeometryToConfig();
|
||||
g_emu_thread->stopFullscreenUI();
|
||||
if (m_display_created)
|
||||
g_emu_thread->stopFullscreenUI();
|
||||
destroySubWindows();
|
||||
QMainWindow::closeEvent(event);
|
||||
return;
|
||||
|
@ -53,8 +53,6 @@ static QString FixLanguageName(const QString& language);
|
||||
static std::string GetFontPath(const GlyphInfo* gi);
|
||||
static void UpdateGlyphRanges(const std::string_view& language);
|
||||
static const GlyphInfo* GetGlyphInfo(const std::string_view& language);
|
||||
|
||||
static std::vector<ImWchar> s_glyph_ranges;
|
||||
} // namespace QtHost
|
||||
|
||||
static std::vector<QTranslator*> s_translators;
|
||||
@ -133,9 +131,18 @@ void QtHost::InstallTranslator()
|
||||
qApp->installTranslator(translator);
|
||||
s_translators.push_back(translator);
|
||||
|
||||
UpdateGlyphRanges(language.toStdString());
|
||||
|
||||
Host::ClearTranslationCache();
|
||||
// We end up here both on language change, and on startup.
|
||||
if (g_emu_thread)
|
||||
{
|
||||
Host::RunOnCPUThread([language = language.toStdString()]() {
|
||||
UpdateGlyphRanges(language);
|
||||
Host::ClearTranslationCache();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateGlyphRanges(language.toStdString());
|
||||
}
|
||||
}
|
||||
|
||||
QString QtHost::FixLanguageName(const QString& language)
|
||||
@ -233,10 +240,11 @@ void QtHost::UpdateGlyphRanges(const std::string_view& language)
|
||||
const GlyphInfo* gi = GetGlyphInfo(language);
|
||||
|
||||
std::string font_path;
|
||||
s_glyph_ranges.clear();
|
||||
std::vector<ImWchar> glyph_ranges;
|
||||
glyph_ranges.clear();
|
||||
|
||||
// Base Latin range is always included.
|
||||
s_glyph_ranges.insert(s_glyph_ranges.begin(), std::begin(s_base_latin_range), std::end(s_base_latin_range));
|
||||
glyph_ranges.insert(glyph_ranges.begin(), std::begin(s_base_latin_range), std::end(s_base_latin_range));
|
||||
|
||||
if (gi)
|
||||
{
|
||||
@ -247,8 +255,8 @@ void QtHost::UpdateGlyphRanges(const std::string_view& language)
|
||||
{
|
||||
// Always should be in pairs.
|
||||
DebugAssert(ptr[0] != 0 && ptr[1] != 0);
|
||||
s_glyph_ranges.push_back(*(ptr++));
|
||||
s_glyph_ranges.push_back(*(ptr++));
|
||||
glyph_ranges.push_back(*(ptr++));
|
||||
glyph_ranges.push_back(*(ptr++));
|
||||
}
|
||||
}
|
||||
|
||||
@ -258,16 +266,15 @@ void QtHost::UpdateGlyphRanges(const std::string_view& language)
|
||||
// If we don't have any specific glyph range, assume Central European, except if English, then keep the size down.
|
||||
if ((!gi || !gi->used_glyphs) && language != "en")
|
||||
{
|
||||
s_glyph_ranges.insert(s_glyph_ranges.begin(), std::begin(s_central_european_ranges),
|
||||
std::end(s_central_european_ranges));
|
||||
glyph_ranges.insert(glyph_ranges.begin(), std::begin(s_central_european_ranges),
|
||||
std::end(s_central_european_ranges));
|
||||
}
|
||||
|
||||
// List terminator.
|
||||
s_glyph_ranges.push_back(0);
|
||||
s_glyph_ranges.push_back(0);
|
||||
glyph_ranges.push_back(0);
|
||||
glyph_ranges.push_back(0);
|
||||
|
||||
ImGuiManager::SetFontPath(std::move(font_path));
|
||||
ImGuiManager::SetFontRange(s_glyph_ranges.data());
|
||||
ImGuiManager::SetFontPathAndRange(std::move(font_path), std::move(glyph_ranges));
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
|
Reference in New Issue
Block a user