From cf836c0f8ae2b273dbcd785157be5a147158f331 Mon Sep 17 00:00:00 2001 From: Aloshi Date: Sat, 22 Mar 2014 18:17:14 -0500 Subject: [PATCH] Fixed SliderComponent going beyond its min/max values. Defensive measures against a possible SVG reinitialization bug. --- src/components/SliderComponent.cpp | 8 ++++---- src/resources/SVGResource.cpp | 15 +++++++++++++-- src/resources/SVGResource.h | 2 ++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/components/SliderComponent.cpp b/src/components/SliderComponent.cpp index 78dc0468b..1de0065e1 100644 --- a/src/components/SliderComponent.cpp +++ b/src/components/SliderComponent.cpp @@ -85,10 +85,10 @@ void SliderComponent::render(const Eigen::Affine3f& parentTrans) void SliderComponent::setValue(float value) { mValue = value; - if(value < mMin) - value = mMin; - else if(value > mMax) - value = mMax; + if(mValue < mMin) + mValue = mMin; + else if(mValue > mMax) + mValue = mMax; onValueChanged(); } diff --git a/src/resources/SVGResource.cpp b/src/resources/SVGResource.cpp index 39ece9e51..1f50466f5 100644 --- a/src/resources/SVGResource.cpp +++ b/src/resources/SVGResource.cpp @@ -2,12 +2,14 @@ #include "../nanosvg/nanosvg.h" #include "../nanosvg/nanosvgrast.h" #include "../Log.h" +#include "../Util.h" #define DPI 96 SVGResource::SVGResource(const std::string& path, bool tile) : TextureResource(path, tile), mSVGImage(NULL) { - assert(tile == false); + mLastWidth = 0; + mLastHeight = 0; } SVGResource::~SVGResource() @@ -40,11 +42,20 @@ void SVGResource::initFromMemory(const char* file, size_t length) return; } - rasterizeAt((int)mSVGImage->width, (int)mSVGImage->height); + if(mLastWidth && mLastHeight) + rasterizeAt(mLastWidth, mLastHeight); + else + rasterizeAt((int)round(mSVGImage->width), (int)round(mSVGImage->height)); } void SVGResource::rasterizeAt(size_t width, size_t height) { + if(width != (int)round(mSVGImage->width) && height != (int)round(mSVGImage->height)) + { + mLastWidth = width; + mLastHeight = height; + } + if(!mSVGImage) return; diff --git a/src/resources/SVGResource.h b/src/resources/SVGResource.h index 46519d799..c28b29396 100644 --- a/src/resources/SVGResource.h +++ b/src/resources/SVGResource.h @@ -22,4 +22,6 @@ protected: void deinitSVG(); NSVGimage* mSVGImage; + size_t mLastWidth; + size_t mLastHeight; };