From 750c13e5fede33809da8053e68437c700e98f8b0 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 11 Jun 2021 23:01:07 +0400 Subject: [PATCH] Add OpenGL init crash checker. --- Telegram/SourceFiles/core/application.cpp | 31 ++++++++++++++++++++ Telegram/SourceFiles/core/application.h | 3 +- Telegram/SourceFiles/core/core_settings.cpp | 3 +- Telegram/SourceFiles/core/launcher.cpp | 3 ++ Telegram/SourceFiles/core/ui_integration.cpp | 20 +++++++++++++ Telegram/SourceFiles/core/ui_integration.h | 6 ++++ Telegram/lib_ui | 2 +- 7 files changed, 64 insertions(+), 4 deletions(-) diff --git a/Telegram/SourceFiles/core/application.cpp b/Telegram/SourceFiles/core/application.cpp index c3775bd74..d6cf194dc 100644 --- a/Telegram/SourceFiles/core/application.cpp +++ b/Telegram/SourceFiles/core/application.cpp @@ -25,6 +25,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "chat_helpers/emoji_keywords.h" #include "chat_helpers/stickers_emoji_image_loader.h" #include "base/platform/base_platform_last_input.h" +#include "base/platform/base_platform_info.h" #include "platform/platform_specific.h" #include "mainwindow.h" #include "dialogs/dialogs_entry.h" @@ -281,6 +282,36 @@ void Application::run() { for (const auto &error : Shortcuts::Errors()) { LOG(("Shortcuts Error: %1").arg(error)); } + + if (!Platform::IsMac() + && Ui::Integration::Instance().openglLastCheckFailed()) { + showOpenGLCrashNotification(); + } +} + +void Application::showOpenGLCrashNotification() { + const auto enable = [=] { + Ui::GL::ForceDisable(false); + Ui::Integration::Instance().openglCheckFinish(); + Core::App().settings().setDisableOpenGL(false); + Local::writeSettings(); + App::restart(); + }; + const auto keepDisabled = [=] { + Ui::GL::ForceDisable(true); + Ui::Integration::Instance().openglCheckFinish(); + Core::App().settings().setDisableOpenGL(true); + Local::writeSettings(); + }; + _window->show(Box( + "Last time OpenGL crashed on initialization. " + "Perhaps it is a problem with your graphics card driver.\n\n" + "Right now OpenGL was disabled. You can try to enable it back " + "or keep it disabled, if it continues crashing.", + "Enable", + "Keep Disabled", + enable, + keepDisabled)); } void Application::startDomain() { diff --git a/Telegram/SourceFiles/core/application.h b/Telegram/SourceFiles/core/application.h index 586c27ad0..26ba71300 100644 --- a/Telegram/SourceFiles/core/application.h +++ b/Telegram/SourceFiles/core/application.h @@ -299,13 +299,12 @@ private: void startEmojiImageLoader(); void startSystemDarkModeViewer(); - void stateChanged(Qt::ApplicationState state); - friend void App::quit(); static void QuitAttempt(); void quitDelayed(); [[nodiscard]] bool readyToQuit(); + void showOpenGLCrashNotification(); void clearPasscodeLock(); bool openCustomUrl( diff --git a/Telegram/SourceFiles/core/core_settings.cpp b/Telegram/SourceFiles/core/core_settings.cpp index ff75ef189..0fa64b74e 100644 --- a/Telegram/SourceFiles/core/core_settings.cpp +++ b/Telegram/SourceFiles/core/core_settings.cpp @@ -510,7 +510,8 @@ void Settings::addFromSerialized(const QByteArray &serialized) { _emojiVariants = std::move(emojiVariants); _disableOpenGL = (disableOpenGL == 1); if (!Platform::IsMac()) { - Ui::GL::ForceDisable(_disableOpenGL); + Ui::GL::ForceDisable(_disableOpenGL + || Ui::Integration::Instance().openglLastCheckFailed()); } } diff --git a/Telegram/SourceFiles/core/launcher.cpp b/Telegram/SourceFiles/core/launcher.cpp index 3748be153..c72db6627 100644 --- a/Telegram/SourceFiles/core/launcher.cpp +++ b/Telegram/SourceFiles/core/launcher.cpp @@ -18,6 +18,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/sandbox.h" #include "base/concurrent_timer.h" +//#include + namespace Core { namespace { @@ -525,6 +527,7 @@ void Launcher::processArguments() { int Launcher::executeApplication() { FilteredCommandLineArguments arguments(_argc, _argv); Sandbox sandbox(this, arguments.count(), arguments.values()); + //QLoggingCategory::setFilterRules("qt.qpa.gl.debug=true"); Ui::MainQueueProcessor processor; base::ConcurrentTimerEnvironment environment; return sandbox.start(); diff --git a/Telegram/SourceFiles/core/ui_integration.cpp b/Telegram/SourceFiles/core/ui_integration.cpp index a7a54fa5c..043854828 100644 --- a/Telegram/SourceFiles/core/ui_integration.cpp +++ b/Telegram/SourceFiles/core/ui_integration.cpp @@ -85,6 +85,10 @@ const auto kBadPrefix = u"http://"_q; return true; } +[[nodiscard]] QString OpenGLCheckFilePath() { + return cWorkingDir() + "tdata/opengl_crash_check"; +} + } // namespace void UiIntegration::postponeCall(FnMut &&callable) { @@ -103,6 +107,22 @@ QString UiIntegration::emojiCacheFolder() { return cWorkingDir() + "tdata/emoji"; } +void UiIntegration::openglCheckStart() { + auto f = QFile(OpenGLCheckFilePath()); + if (f.open(QIODevice::WriteOnly)) { + f.write("1", 1); + f.close(); + } +} + +void UiIntegration::openglCheckFinish() { + QFile::remove(OpenGLCheckFilePath()); +} + +bool UiIntegration::openglLastCheckFailed() { + return QFile::exists(OpenGLCheckFilePath()); +} + void UiIntegration::textActionsUpdated() { if (const auto window = App::wnd()) { window->updateGlobalMenu(); diff --git a/Telegram/SourceFiles/core/ui_integration.h b/Telegram/SourceFiles/core/ui_integration.h index 2f9cfc618..391e40074 100644 --- a/Telegram/SourceFiles/core/ui_integration.h +++ b/Telegram/SourceFiles/core/ui_integration.h @@ -38,6 +38,10 @@ public: QString emojiCacheFolder() override; + void openglCheckStart() override; + void openglCheckFinish() override; + bool openglLastCheckFailed() override; + void textActionsUpdated() override; void activationFromTopPanel() override; @@ -71,4 +75,6 @@ public: }; +[[nodiscard]] bool OpenglLastCheckFailed(); + } // namespace Core diff --git a/Telegram/lib_ui b/Telegram/lib_ui index 802918dd1..f58fd1b92 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit 802918dd11eba3382ae9607babf01db47e232f58 +Subproject commit f58fd1b9277301d1d5a167fc0809558425ce608e