aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2009-07-03 02:52:27 +0000
committerGravatar reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2009-07-03 02:52:27 +0000
commit8433b5db1a0f94cd92d2606817d5374ab899b87a (patch)
tree361e06f838515e6b70b470a43df46c8a22b5a610
parent1c12abe3508cd69615c2dd50653f782835e325ce (diff)
more checks for null shapes in pictures
git-svn-id: http://skia.googlecode.com/svn/trunk@249 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r--include/core/SkTDArray.h12
-rw-r--r--samplecode/SampleShapes.cpp6
-rw-r--r--src/core/SkPicturePlayback.cpp10
-rw-r--r--src/core/SkPictureRecord.cpp2
4 files changed, 21 insertions, 9 deletions
diff --git a/include/core/SkTDArray.h b/include/core/SkTDArray.h
index 4d2d7f7ed3..5f6bbd8612 100644
--- a/include/core/SkTDArray.h
+++ b/include/core/SkTDArray.h
@@ -251,7 +251,17 @@ public:
}
this->reset();
}
-
+
+ void safeUnrefAll() {
+ T* iter = fArray;
+ T* stop = fArray + fCount;
+ while (iter < stop) {
+ SkSafeUnref(*iter);
+ iter += 1;
+ }
+ this->reset();
+ }
+
#ifdef SK_DEBUG
void validate() const {
SkASSERT((fReserve == 0 && fArray == NULL) ||
diff --git a/samplecode/SampleShapes.cpp b/samplecode/SampleShapes.cpp
index 95efd0fb48..07f2d0037c 100644
--- a/samplecode/SampleShapes.cpp
+++ b/samplecode/SampleShapes.cpp
@@ -90,9 +90,9 @@ protected:
pict.serialize(&ostream);
SkMemoryStream istream(ostream.getStream(), ostream.getOffset());
- SkPicture newPict(&istream);
-
- canvas->drawPicture(newPict);
+ SkPicture* newPict = new SkPicture(&istream);
+ canvas->drawPicture(*newPict);
+ newPict->unref();
#else
canvas->drawPicture(pict);
#endif
diff --git a/src/core/SkPicturePlayback.cpp b/src/core/SkPicturePlayback.cpp
index 77ac9122a7..ad0a7aa08b 100644
--- a/src/core/SkPicturePlayback.cpp
+++ b/src/core/SkPicturePlayback.cpp
@@ -125,8 +125,9 @@ SkPicturePlayback::SkPicturePlayback(const SkPictureRecord& record) {
if (fShapeCount > 0) {
fShapes = SkNEW_ARRAY(SkShape*, fShapeCount);
for (int i = 0; i < fShapeCount; i++) {
- fShapes[i] = shapes[i];
- fShapes[i]->ref();
+ SkShape* s = shapes[i];
+ SkSafeRef(s);
+ fShapes[i] = s;
}
}
@@ -205,8 +206,9 @@ SkPicturePlayback::SkPicturePlayback(const SkPicturePlayback& src) {
fShapeCount = src.fShapeCount;
fShapes = SkNEW_ARRAY(SkShape*, fShapeCount);
for (int i = 0; i < fShapeCount; i++) {
- fShapes[i] = src.fShapes[i];
- fShapes[i]->ref();
+ SkShape* s = src.fShapes[i];
+ SkSafeRef(s);
+ fShapes[i] = s;
}
fRegionCount = src.fRegionCount;
diff --git a/src/core/SkPictureRecord.cpp b/src/core/SkPictureRecord.cpp
index 4778726943..b908670baf 100644
--- a/src/core/SkPictureRecord.cpp
+++ b/src/core/SkPictureRecord.cpp
@@ -413,7 +413,7 @@ void SkPictureRecord::reset() {
fPaints.reset();
fPictureRefs.unrefAll();
fRegions.reset();
- fShapes.unrefAll();
+ fShapes.safeUnrefAll();
fWriter.reset();
fHeap.reset();