Commit cf836c0f authored by Aloshi's avatar Aloshi

Fixed SliderComponent going beyond its min/max values.

Defensive measures against a possible SVG reinitialization bug.
parent d1814053
......@@ -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();
}
......
......@@ -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;
......
......@@ -22,4 +22,6 @@ protected:
void deinitSVG();
NSVGimage* mSVGImage;
size_t mLastWidth;
size_t mLastHeight;
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment