From a9fc84d568ba3be76b7ee62c2a71e3b56c8d64de Mon Sep 17 00:00:00 2001 From: Thomas Geymayer Date: Fri, 19 Jul 2013 23:37:04 +0200 Subject: [PATCH] Canvas: clip region rounding and catch negative size. --- simgear/canvas/elements/CanvasElement.cxx | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/simgear/canvas/elements/CanvasElement.cxx b/simgear/canvas/elements/CanvasElement.cxx index adb1d665..319c07d2 100644 --- a/simgear/canvas/elements/CanvasElement.cxx +++ b/simgear/canvas/elements/CanvasElement.cxx @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -413,7 +414,7 @@ namespace canvas const std::string sep(", \t\npx"); int comp = 0; - int values[4]; + float values[4]; for(size_t pos = RECT.size(); comp < 4; ++comp) { @@ -435,6 +436,15 @@ namespace canvas return; } + float width = values[1] - values[3], + height = values[2] - values[0]; + + if( width < 0 || height < 0 ) + { + SG_LOG(SG_GENERAL, SG_WARN, "Canvas: negative clip size: " << clip); + return; + } + float scale_x = 1, scale_y = 1; @@ -451,10 +461,10 @@ namespace canvas osg::Scissor* scissor = new osg::Scissor(); // , , , - scissor->x() = scale_x * values[3]; - scissor->y() = scale_y * values[0]; - scissor->width() = scale_x * (values[1] - values[3]); - scissor->height() = scale_y * (values[2] - values[0]); + scissor->x() = SGMiscf::roundToInt(scale_x * values[3]); + scissor->y() = SGMiscf::roundToInt(scale_y * values[0]); + scissor->width() = SGMiscf::roundToInt(scale_x * width); + scissor->height() = SGMiscf::roundToInt(scale_y * height); if( canvas ) // Canvas has y axis upside down -- 2.39.5