Skip to content

Commit

Permalink
Fixed Pattern Brush vector out of bound
Browse files Browse the repository at this point in the history
  • Loading branch information
danvim committed Feb 28, 2019
1 parent addffd3 commit 167f9bf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
12 changes: 11 additions & 1 deletion PatternBrush.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "CurvedBrush.h"
#include <FL/Fl_Native_File_Chooser.H>

volatile bool PatternBrush::isGenerating = false;
std::vector< ImageWrapper<GLubyte> > PatternBrush::patterns{};
std::vector< ImageWrapper<GLubyte> > PatternBrush::scaledPatterns{};
std::random_device PatternBrush::rd{};
Expand Down Expand Up @@ -71,6 +72,7 @@ void PatternBrush::BrushBegin(const Point source, const Point target)

if (newSize != size)
{
isGenerating = true;
size = newSize;
//make scaled images
const Dim newDim = { size, size };
Expand All @@ -95,6 +97,7 @@ void PatternBrush::BrushBegin(const Point source, const Point target)

scaledPatterns.push_back(v);
}
isGenerating = false;
}

BrushMove(source, target);
Expand All @@ -109,6 +112,11 @@ void PatternBrush::BrushMove(const Point source, const Point target)
return;
}

if (isGenerating)
{
return; //Scaled brushes still generating
}

if (source.x > docPtr->m_nPaintWidth || source.y < 0)
{
return;
Expand All @@ -117,7 +125,9 @@ void PatternBrush::BrushMove(const Point source, const Point target)
if (step == 0)
{
//Make new pattern
auto& alpha = scaledPatterns[dis(gen)];
const auto i = dis(gen);
if (i < 0 || scaledPatterns.size() >= i) return;
auto& alpha = scaledPatterns[i];

const int tX0 = target.x - alpha.dim.width / 2;
const int tY0 = target.y - alpha.dim.height / 2;
Expand Down
1 change: 1 addition & 0 deletions PatternBrush.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class PatternBrush: public ImpBrush
int step = 0;
static Fl_Callback cb_set_patterns;
static std::vector< ImageWrapper<GLubyte> > patterns;
static volatile bool isGenerating;

static void setPatterns(const std::string& directoryName);

Expand Down

0 comments on commit 167f9bf

Please sign in to comment.