From a76ef3dfdd9bd7351285fdb4e1995ed4ecfda353 Mon Sep 17 00:00:00 2001 From: shenleban tongying Date: Mon, 19 Jun 2023 05:01:27 -0400 Subject: [PATCH] guard against null img for ZIM --- src/dict/zim.cc | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/dict/zim.cc b/src/dict/zim.cc index c56b9678..df7d9cb9 100644 --- a/src/dict/zim.cc +++ b/src/dict/zim.cc @@ -290,7 +290,14 @@ void ZimDictionary::loadIcon() noexcept try { auto illustration = df.getIllustrationItem( 48 ).getData(); QImage img = QImage::fromData( reinterpret_cast< const uchar * >( illustration.data() ), illustration.size() ); - dictionaryIcon = QIcon( QPixmap::fromImage( img ) ); + + if ( img.isNull() ) { + // Fallback to default icon + dictionaryIcon = QIcon( ":/icons/icon32_zim.png" ); + } + else { + dictionaryIcon = QIcon( QPixmap::fromImage( img ) ); + } dictionaryIconLoaded = true; return; @@ -298,11 +305,6 @@ void ZimDictionary::loadIcon() noexcept catch ( zim::EntryNotFound & e ) { gdDebug( "ZIM icon not loaded for: %s", dictionaryName.c_str() ); } - - // Fallback to default icon - dictionaryIcon = QIcon( ":/icons/icon32_zim.png" ); - - dictionaryIconLoaded = true; } quint32 ZimDictionary::loadArticle( quint32 address, string & articleText, bool rawText )