Sample/AAGeometry: stop leaking linked list

Change-Id: I8bba87244becf1352e713c08aee355ebbd83e45f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/227058
Auto-Submit: Hal Canary <halcanary@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
This commit is contained in:
Hal Canary 2019-07-12 10:04:14 -04:00 committed by Skia Commit-Bot
parent 41248071ac
commit 8918d532ab

View File

@ -7,16 +7,14 @@
#include "include/core/SkBitmap.h" #include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h" #include "include/core/SkCanvas.h"
#include "include/core/SkString.h"
#include "include/private/SkMacros.h" #include "include/private/SkMacros.h"
#include "include/utils/SkTextUtils.h"
#include "samplecode/Sample.h" #include "samplecode/Sample.h"
#include "src/core/SkGeometry.h" #include "src/core/SkGeometry.h"
#include "src/core/SkPointPriv.h"
#include "src/pathops/SkIntersections.h" #include "src/pathops/SkIntersections.h"
#include "src/pathops/SkOpEdgeBuilder.h" #include "src/pathops/SkOpEdgeBuilder.h"
// #include "SkPathOpsSimplifyAA.h"
// #include "SkPathStroker.h"
#include "include/core/SkString.h"
#include "include/utils/SkTextUtils.h"
#include "src/core/SkPointPriv.h"
#if 0 #if 0
void SkStrokeSegment::dump() const { void SkStrokeSegment::dump() const {
@ -781,7 +779,7 @@ struct Stroke {
struct PathUndo { struct PathUndo {
SkPath fPath; SkPath fPath;
PathUndo* fNext; std::unique_ptr<PathUndo> fNext;
}; };
class AAGeometryView : public Sample { class AAGeometryView : public Sample {
@ -813,7 +811,7 @@ class AAGeometryView : public Sample {
Button fJoinButton; Button fJoinButton;
Button fInOutButton; Button fInOutButton;
SkTArray<Stroke> fStrokes; SkTArray<Stroke> fStrokes;
PathUndo* fUndo; std::unique_ptr<PathUndo> fUndo;
int fActivePt; int fActivePt;
int fActiveVerb; int fActiveVerb;
bool fHandlePathMove; bool fHandlePathMove;
@ -840,7 +838,6 @@ public:
, fBisectButton('b') , fBisectButton('b')
, fJoinButton('j') , fJoinButton('j')
, fInOutButton('|') , fInOutButton('|')
, fUndo(nullptr)
, fActivePt(-1) , fActivePt(-1)
, fActiveVerb(-1) , fActiveVerb(-1)
, fHandlePathMove(true) , fHandlePathMove(true)
@ -882,6 +879,14 @@ public:
init_buttonList(); init_buttonList();
} }
~AAGeometryView() override {
// Free linked list without deep recursion.
std::unique_ptr<PathUndo> undo = std::move(fUndo);
while (undo) {
undo = std::move(undo->fNext);
}
}
bool constructPath() { bool constructPath() {
construct_path(fPath); construct_path(fPath);
return true; return true;
@ -894,32 +899,23 @@ public:
if (fUndo && fUndo->fPath == fPath) { if (fUndo && fUndo->fPath == fPath) {
return; return;
} }
PathUndo* undo = new PathUndo; std::unique_ptr<PathUndo> undo(new PathUndo);
undo->fPath = fPath; undo->fPath = fPath;
undo->fNext = fUndo; undo->fNext = std::move(fUndo);
fUndo = undo; fUndo = std::move(undo);
} }
bool undo() { bool undo() {
if (!fUndo) { if (!fUndo) {
return false; return false;
} }
fPath = fUndo->fPath; fPath = std::move(fUndo->fPath);
fUndo = std::move(fUndo->fNext);
validatePath(); validatePath();
PathUndo* next = fUndo->fNext;
delete fUndo;
fUndo = next;
return true; return true;
} }
void validatePath() { void validatePath() {}
PathUndo* undo = fUndo;
int match = 0;
while (undo) {
match += fPath == undo->fPath;
undo = undo->fNext;
}
}
void set_controlList(int index, UniControl* control, MyClick::ControlType type) { void set_controlList(int index, UniControl* control, MyClick::ControlType type) {
kControlList[index].fControl = control; kControlList[index].fControl = control;