From aa87ed10aada03b3a6ed8ae11897a2b903345759 Mon Sep 17 00:00:00 2001 From: Thilo Graf Date: Sun, 23 Feb 2014 16:25:16 +0100 Subject: [PATCH] CComponents: add member CheckFbData() for fbdata check This check happens several times, therefore it is senseful, to move into own member. Function returns false on error and is used here to show an error message if something was wrong. Such errors can happen on position or dimension errors e.g. out of screen or too large display values. Note: this is only an emergency helper for debugging on fatal errors during developing of window stuff. Mostly errors of this kind causing crashes and must be fixed. Origin commit data ------------------ Branch: ni/coolstream Commit: https://github.com/neutrino-images/ni-neutrino/commit/f813b9ea98a1795b6debfd41218612778381a02c Author: Thilo Graf Date: 2014-02-23 (Sun, 23 Feb 2014) Origin message was: ------------------ CComponents: add member CheckFbData() for fbdata check This check happens several times, therefore it is senseful, to move into own member. Function returns false on error and is used here to show an error message if something was wrong. Such errors can happen on position or dimension errors e.g. out of screen or too large display values. Note: this is only an emergency helper for debugging on fatal errors during developing of window stuff. Mostly errors of this kind causing crashes and must be fixed. ------------------ This commit was generated by Migit --- src/gui/components/cc_base.cpp | 53 ++++++++++++++++++++-------------- src/gui/components/cc_base.h | 3 ++ 2 files changed, 35 insertions(+), 21 deletions(-) diff --git a/src/gui/components/cc_base.cpp b/src/gui/components/cc_base.cpp index c9c49528a..223253ecc 100644 --- a/src/gui/components/cc_base.cpp +++ b/src/gui/components/cc_base.cpp @@ -31,7 +31,7 @@ #include #include #include "cc_base.h" - +#include using namespace std; //abstract basic class CComponents @@ -83,15 +83,30 @@ void CComponents::initVarBasic() saved_screen.pixbuf = NULL; } +bool CComponents::CheckFbData(const comp_fbdata_t& fbdata) +{ + if ( (fbdata.x <= 0 || fbdata.y <= 0) || + (fbdata.dx == 0 || fbdata.dy == 0) || + (fbdata.dx > (int32_t)frameBuffer->getScreenWidth(true) || fbdata.dy > (int32_t)frameBuffer->getScreenHeight(true))){ + printf("\33[31m\t[CComponents] WARNING! Position <= 0 [%s - %d]\n\tx = %d y = %d\n\tdx = %d dy = %d\n\033[37m", + __func__, __LINE__, + fbdata.x, fbdata.y, + fbdata.dx, fbdata.dy); + return false; + } + return true; +} + //paint framebuffer stuff and fill buffer void CComponents::paintFbItems(bool do_save_bg) { //save background before first paint, do_save_bg must be true - if (firstPaint && do_save_bg) { + if (firstPaint && do_save_bg){ for(size_t i=0; isave screen: %d, fbdata_type: %d\n\tx = %d\n\ty = %d\n\tdx = %d\n\tdy = %d\n", __func__, @@ -103,27 +118,23 @@ void CComponents::paintFbItems(bool do_save_bg) v_fbdata[i].dx, v_fbdata[i].dy); #endif - saved_screen.x = v_fbdata[i].x; - saved_screen.y = v_fbdata[i].y; - saved_screen.dx = v_fbdata[i].dx; - saved_screen.dy = v_fbdata[i].dy; - clearSavedScreen(); - saved_screen.pixbuf = getScreen(saved_screen.x, saved_screen.y, saved_screen.dx, saved_screen.dy); - firstPaint = false; - break; - } + saved_screen.x = v_fbdata[i].x; + saved_screen.y = v_fbdata[i].y; + saved_screen.dx = v_fbdata[i].dx; + saved_screen.dy = v_fbdata[i].dy; + clearSavedScreen(); + saved_screen.pixbuf = getScreen(saved_screen.x, saved_screen.y, saved_screen.dx, saved_screen.dy); + firstPaint = false; + break; } } - for(size_t i=0; i< v_fbdata.size() ;i++){ - // Don't paint if dx or dy are 0 - if ((v_fbdata[i].dx == 0) || (v_fbdata[i].dy == 0)){ -#ifdef DEBUG_CC - printf("\t[CComponents] WARNING: [%s - %d], dx = %d dy = %d\n", __func__, __LINE__, v_fbdata[i].dx, v_fbdata[i].dy); -#endif + for(size_t i=0; i< v_fbdata.size(); i++){ + // Don't paint on dimension or position error dx or dy are 0 + if (!CheckFbData(v_fbdata[i])){ + DisplayErrorMessage("Display error, please show log and report!"); continue; } - int fbtype = v_fbdata[i].fbdata_type; #ifdef DEBUG_CC printf("\t[CComponents]\n\t[%s - %d], fbdata_[%d]\n\tx = %d\n\ty = %d\n\tdx = %d\n\tdy = %d\n", diff --git a/src/gui/components/cc_base.h b/src/gui/components/cc_base.h index a726361a8..6ae2c533c 100644 --- a/src/gui/components/cc_base.h +++ b/src/gui/components/cc_base.h @@ -104,6 +104,9 @@ class CComponents ///parameter do_save_bg=true, saves background of element to pixel buffer, this can be restore with hide() void paintFbItems(bool do_save_bg = true); + ///check current fbdtata position and dimensions, parameter fbdata is an element of v_fbdata, returns false on error + bool CheckFbData(const comp_fbdata_t& fbdata); + ///clean up old screen buffer saved in v_fbdata virtual void clearFbData();