aboutsummaryrefslogtreecommitdiffstats
path: root/subsurface-helper.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2020-11-20 10:08:17 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-11-20 11:46:17 -0800
commit4c3b6e6df2229d9b22336d28b63e11af0744251d (patch)
tree384508e317760112183ef58ee3b7a3a586584db7 /subsurface-helper.cpp
parente6804152e55db38afc7a43385b02994cf9ebdef8 (diff)
downloadsubsurface-4c3b6e6df2229d9b22336d28b63e11af0744251d.tar.gz
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 <dirk@hohndel.org>
Diffstat (limited to 'subsurface-helper.cpp')
-rw-r--r--subsurface-helper.cpp19
1 files 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<QApplication *>(QCoreApplication::instance()))->setFont(newDefaultFont);
- qDebug() << "Detected OnePlus device, trying to force bundled font" << family;
- QFont defaultFont = (static_cast<QApplication *>(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<QApplication *>(QCoreApplication::instance()))->setFont(newDefaultFont);
+ qDebug() << "Detected OnePlus device, trying to force bundled font" << family;
+ QFont defaultFont = (static_cast<QApplication *>(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);