Index: src/core/SkPixelRef.cpp |
diff --git a/src/core/SkPixelRef.cpp b/src/core/SkPixelRef.cpp |
index e93882a465ddd0cc2702df8c553d56648d3504cb..da88ca5c71ae6ff6bf1a3dc9ab0a1e67b641779e 100644 |
--- a/src/core/SkPixelRef.cpp |
+++ b/src/core/SkPixelRef.cpp |
@@ -182,6 +182,10 @@ void SkPixelRef::lockPixels() { |
if (1 == ++fLockCount) { |
fPixels = this->onLockPixels(&fColorTable); |
+ // If onLockPixels failed, it will return NULL |
+ if (NULL == fPixels) { |
+ fColorTable = NULL; |
+ } |
} |
} |
} |
@@ -194,9 +198,14 @@ void SkPixelRef::unlockPixels() { |
SkASSERT(fLockCount > 0); |
if (0 == --fLockCount) { |
- this->onUnlockPixels(); |
- fPixels = NULL; |
- fColorTable = NULL; |
+ // don't call onUnlockPixels unless onLockPixels succeeded |
+ if (fPixels) { |
+ this->onUnlockPixels(); |
+ fPixels = NULL; |
+ fColorTable = NULL; |
+ } else { |
+ SkASSERT(NULL == fColorTable); |
+ } |
} |
} |
} |