more checks for null shapes in pictures
git-svn-id: http://skia.googlecode.com/svn/trunk@249 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/core/SkTDArray.h b/include/core/SkTDArray.h
index 4d2d7f7..5f6bbd8 100644
--- a/include/core/SkTDArray.h
+++ b/include/core/SkTDArray.h
@@ -251,7 +251,17 @@
}
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 95efd0f..07f2d00 100644
--- a/samplecode/SampleShapes.cpp
+++ b/samplecode/SampleShapes.cpp
@@ -90,9 +90,9 @@
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 77ac912..ad0a7aa 100644
--- a/src/core/SkPicturePlayback.cpp
+++ b/src/core/SkPicturePlayback.cpp
@@ -125,8 +125,9 @@
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 @@
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 4778726..b908670 100644
--- a/src/core/SkPictureRecord.cpp
+++ b/src/core/SkPictureRecord.cpp
@@ -413,7 +413,7 @@
fPaints.reset();
fPictureRefs.unrefAll();
fRegions.reset();
- fShapes.unrefAll();
+ fShapes.safeUnrefAll();
fWriter.reset();
fHeap.reset();