diff options
| author | Nathan Lee <2431820-nathanal@users.noreply.gitlab.com> | 2019-05-25 10:14:13 +0000 |
|---|---|---|
| committer | Marc Jeanmougin <marcjeanmougin@free.fr> | 2019-07-15 10:35:33 +0000 |
| commit | cdfe88fdf72647144a10d3230c663977364f3d00 (patch) | |
| tree | 0aad4da5f080ed20e24cc70581194f8012440d35 /src | |
| parent | Override navigation in swatch/gradient list (diff) | |
| download | inkscape-cdfe88fdf72647144a10d3230c663977364f3d00.tar.gz inkscape-cdfe88fdf72647144a10d3230c663977364f3d00.zip | |
Check knot's pattern still exists before update
Stop crash when pattern changed via swatch palette,
and knot is still present.
https://gitlab.com/inkscape/inkscape/issues/70
Diffstat (limited to 'src')
| -rw-r--r-- | src/knot-holder-entity.cpp | 22 | ||||
| -rw-r--r-- | src/knot-holder-entity.h | 4 | ||||
| -rw-r--r-- | src/knotholder.cpp | 11 |
3 files changed, 34 insertions, 3 deletions
diff --git a/src/knot-holder-entity.cpp b/src/knot-holder-entity.cpp index 7abd16cba..e8f97e453 100644 --- a/src/knot-holder-entity.cpp +++ b/src/knot-holder-entity.cpp @@ -172,6 +172,27 @@ static Geom::Point sp_pattern_knot_get(SPPattern const *pat, gdouble x, gdouble return Geom::Point(x, y) * pat->getTransform(); } +bool +PatternKnotHolderEntityXY::knot_missing() const +{ + SPPattern *pat = _fill ? SP_PATTERN(item->style->getFillPaintServer()) : SP_PATTERN(item->style->getStrokePaintServer()); + return (pat == nullptr); +} + +bool +PatternKnotHolderEntityAngle::knot_missing() const +{ + SPPattern *pat = _fill ? SP_PATTERN(item->style->getFillPaintServer()) : SP_PATTERN(item->style->getStrokePaintServer()); + return (pat == nullptr); +} + +bool +PatternKnotHolderEntityScale::knot_missing() const +{ + SPPattern *pat = _fill ? SP_PATTERN(item->style->getFillPaintServer()) : SP_PATTERN(item->style->getStrokePaintServer()); + return (pat == nullptr); +} + Geom::Point PatternKnotHolderEntityXY::knot_get() const { @@ -183,7 +204,6 @@ Geom::Point PatternKnotHolderEntityAngle::knot_get() const { SPPattern *pat = _fill ? SP_PATTERN(item->style->getFillPaintServer()) : SP_PATTERN(item->style->getStrokePaintServer()); - return sp_pattern_knot_get(pat, pat->width(), 0); } diff --git a/src/knot-holder-entity.h b/src/knot-holder-entity.h index e6d2ba231..1aa686f65 100644 --- a/src/knot-holder-entity.h +++ b/src/knot-holder-entity.h @@ -63,6 +63,7 @@ public: should be derived from KnotHolderEntity and override these functions */ virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, unsigned int state) = 0; virtual void knot_ungrabbed(Geom::Point const &p, Geom::Point const &origin, unsigned int state) = 0; + virtual bool knot_missing() const { return false; } virtual Geom::Point knot_get() const = 0; virtual void knot_click(unsigned int /*state*/) {} @@ -108,6 +109,7 @@ protected: class PatternKnotHolderEntityXY : public KnotHolderEntity { public: PatternKnotHolderEntityXY(bool fill) : KnotHolderEntity(), _fill(fill) {} + bool knot_missing() const override; Geom::Point knot_get() const override; void knot_ungrabbed(Geom::Point const &p, Geom::Point const &origin, guint state) override {}; void knot_set(Geom::Point const &p, Geom::Point const &origin, unsigned int state) override; @@ -119,6 +121,7 @@ private: class PatternKnotHolderEntityAngle : public KnotHolderEntity { public: PatternKnotHolderEntityAngle(bool fill) : KnotHolderEntity(), _fill(fill) {} + bool knot_missing() const override; Geom::Point knot_get() const override; void knot_ungrabbed(Geom::Point const &p, Geom::Point const &origin, guint state) override {}; void knot_set(Geom::Point const &p, Geom::Point const &origin, unsigned int state) override; @@ -129,6 +132,7 @@ private: class PatternKnotHolderEntityScale : public KnotHolderEntity { public: PatternKnotHolderEntityScale(bool fill) : KnotHolderEntity(), _fill(fill) {} + bool knot_missing() const override; Geom::Point knot_get() const override; void knot_ungrabbed(Geom::Point const &p, Geom::Point const &origin, guint state) override {}; void knot_set(Geom::Point const &p, Geom::Point const &origin, unsigned int state) override; diff --git a/src/knotholder.cpp b/src/knotholder.cpp index 9594a233f..d12f61a98 100644 --- a/src/knotholder.cpp +++ b/src/knotholder.cpp @@ -105,8 +105,15 @@ void KnotHolder::updateControlSizes() void KnotHolder::update_knots() { - for (auto e : entity) { - e->update_knot(); + for (auto e = entity.begin(); e != entity.end(); ) { + // check if pattern was removed without deleting the knot + if ((*e)->knot_missing()) { + delete (*e); + e = entity.erase(e); + } else { + (*e)->update_knot(); + ++e; + } } } |
