From 4c3b6e6df2229d9b22336d28b63e11af0744251d Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Fri, 20 Nov 2020 10:08:17 -0800 Subject: [PATCH] android: avoid crash with failed font load Check that we found font families before accessing them. But the larger issue is likely that bundling the font failed. Signed-off-by: Dirk Hohndel --- subsurface-helper.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/subsurface-helper.cpp b/subsurface-helper.cpp index b2afbfc60..f22afec4c 100644 --- a/subsurface-helper.cpp +++ b/subsurface-helper.cpp @@ -67,13 +67,18 @@ void run_ui() if (getAndroidHWInfo().contains("/OnePlus/")) { QFontDatabase db; int id = QFontDatabase::addApplicationFont(":/fonts/Roboto-Regular.ttf"); - QString family = QFontDatabase::applicationFontFamilies(id).at(0); - QFont newDefaultFont; - newDefaultFont.setFamily(family); - (static_cast(QCoreApplication::instance()))->setFont(newDefaultFont); - qDebug() << "Detected OnePlus device, trying to force bundled font" << family; - QFont defaultFont = (static_cast(QCoreApplication::instance()))->font(); - qDebug() << "Qt reports default font is set as" << defaultFont.family(); + QStringList fontFamilies = QFontDatabase::applicationFontFamilies(id); + if (fontFamilies.count() > 0) { + QString family = fontFamilies.at(0); + QFont newDefaultFont; + newDefaultFont.setFamily(family); + (static_cast(QCoreApplication::instance()))->setFont(newDefaultFont); + qDebug() << "Detected OnePlus device, trying to force bundled font" << family; + QFont defaultFont = (static_cast(QCoreApplication::instance()))->font(); + qDebug() << "Qt reports default font is set as" << defaultFont.family(); + } else { + qDebug() << "Detected OnePlus device, but can't determine font family used"; + } } #endif QScreen *appScreen = QApplication::screens().at(0);