From d9d0f8538d885efb6fd72501c479363e977ffde3 Mon Sep 17 00:00:00 2001 From: Thilo Graf Date: Tue, 26 Mar 2019 10:00:09 +0100 Subject: [PATCH] cc_item_picture.cpp: avoid possible crash if image paint was failed Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/b70f338f85f5f96acdac6c9c03f1a61e1d54da41 Author: Thilo Graf Date: 2019-03-26 (Tue, 26 Mar 2019) --- src/gui/components/cc_item_picture.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/gui/components/cc_item_picture.cpp b/src/gui/components/cc_item_picture.cpp index afb35f7b0..862b11430 100644 --- a/src/gui/components/cc_item_picture.cpp +++ b/src/gui/components/cc_item_picture.cpp @@ -322,15 +322,20 @@ void CComponentsPicture::paintPicture() is_image_painted = g_PicViewer->DisplayImage(pic_name, x_pic, y_pic, width-2*fr_thickness, height-2*fr_thickness); else is_image_painted = frameBuffer->paintIcon(pic_name, x_pic, y_pic, height, 1, do_paint, paint_bg, col_body); - frameBuffer->SetTransparentDefault(); - if (enable_cache && do_scale){ - dprintf(DEBUG_DEBUG, "\033[31m[CComponentsPicture] %s - %d: create cached image from pic_name=%s\033[0m\n", __func__, __LINE__, pic_name.c_str()); - dxc = width-2*fr_thickness; - dyc = height-2*fr_thickness; - image_cache = getScreen(x_pic, y_pic, dxc, dyc); + + if (is_image_painted){ + frameBuffer->SetTransparentDefault(); + if (enable_cache && do_scale){ + dprintf(DEBUG_DEBUG, "\033[32m[CComponentsPicture] %s - %d: create cached image from pic_name=%s\033[0m\n", __func__, __LINE__, pic_name.c_str()); + dxc = width-2*fr_thickness; + dyc = height-2*fr_thickness; + image_cache = getScreen(x_pic, y_pic, dxc, dyc); + } } + else + dprintf(DEBUG_NORMAL, "\033[31m[CComponentsPicture] %s - %d: error: paint of image failed: %s\033[0m\n", __func__, __LINE__, pic_name.c_str()); }else{ - dprintf(DEBUG_DEBUG, "\033[36m[CComponentsPicture] %s - %d: paint cached image from pic_name=%s\033[0m\n", __func__, __LINE__, pic_name.c_str()); + dprintf(DEBUG_DEBUG, "\033[32m[CComponentsPicture] %s - %d: paint cached image from pic_name=%s\033[0m\n", __func__, __LINE__, pic_name.c_str()); frameBuffer->RestoreScreen(x_pic, y_pic, dxc, dyc, image_cache); } }