diff options
author | Mike Reed <reed@google.com> | 2009-07-30 11:05:57 -0400 |
---|---|---|
committer | Mike Reed <reed@google.com> | 2009-07-30 11:05:57 -0400 |
commit | a04e555dc91b11ad833cb5db4a24e38082d1dc45 (patch) | |
tree | 6d14e5190801396b159777b92e5ab563d2aaf137 /core | |
parent | 2bad713f31d642d5350949b90b3abe00fbd9ca55 (diff) | |
download | frameworks_base-a04e555dc91b11ad833cb5db4a24e38082d1dc45.zip frameworks_base-a04e555dc91b11ad833cb5db4a24e38082d1dc45.tar.gz frameworks_base-a04e555dc91b11ad833cb5db4a24e38082d1dc45.tar.bz2 |
check for null native objects, which never happens on a real subclass (we throw in that case)
but can happen because we allow the callers to create the base class from java.
Diffstat (limited to 'core')
-rw-r--r-- | core/jni/android/graphics/MaskFilter.cpp | 22 | ||||
-rw-r--r-- | core/jni/android/graphics/Shader.cpp | 20 |
2 files changed, 26 insertions, 16 deletions
diff --git a/core/jni/android/graphics/MaskFilter.cpp b/core/jni/android/graphics/MaskFilter.cpp index e6048cd..05a6d47 100644 --- a/core/jni/android/graphics/MaskFilter.cpp +++ b/core/jni/android/graphics/MaskFilter.cpp @@ -4,15 +4,23 @@ #include <jni.h> +static void ThrowIAE_IfNull(JNIEnv* env, void* ptr) { + if (NULL == ptr) { + doThrowIAE(env); + } +} + class SkMaskFilterGlue { public: static void destructor(JNIEnv* env, jobject, SkMaskFilter* filter) { - SkASSERT(filter); - filter->unref(); + SkSafeUnref(filter); } static SkMaskFilter* createBlur(JNIEnv* env, jobject, float radius, int blurStyle) { - return SkBlurMaskFilter::Create(SkFloatToScalar(radius), (SkBlurMaskFilter::BlurStyle)blurStyle); + SkMaskFilter* filter = SkBlurMaskFilter::Create(SkFloatToScalar(radius), + (SkBlurMaskFilter::BlurStyle)blurStyle); + ThrowIAE_IfNull(env, filter); + return filter; } static SkMaskFilter* createEmboss(JNIEnv* env, jobject, jfloatArray dirArray, float ambient, float specular, float radius) { @@ -24,8 +32,12 @@ public: direction[i] = SkFloatToScalar(values[i]); } - return SkBlurMaskFilter::CreateEmboss(direction, SkFloatToScalar(ambient), - SkFloatToScalar(specular), SkFloatToScalar(radius)); + SkMaskFilter* filter = SkBlurMaskFilter::CreateEmboss(direction, + SkFloatToScalar(ambient), + SkFloatToScalar(specular), + SkFloatToScalar(radius)); + ThrowIAE_IfNull(env, filter); + return filter; } }; diff --git a/core/jni/android/graphics/Shader.cpp b/core/jni/android/graphics/Shader.cpp index b28eb90..8dbe83f 100644 --- a/core/jni/android/graphics/Shader.cpp +++ b/core/jni/android/graphics/Shader.cpp @@ -43,25 +43,23 @@ static int Color_HSVToColor(JNIEnv* env, jobject, int alpha, jfloatArray hsvArra static void Shader_destructor(JNIEnv* env, jobject, SkShader* shader) { - SkASSERT(shader != NULL); - shader->unref(); + SkSafeUnref(shader); } static bool Shader_getLocalMatrix(JNIEnv* env, jobject, const SkShader* shader, SkMatrix* matrix) { - SkASSERT(shader != NULL); - return shader->getLocalMatrix(matrix); + return shader ? shader->getLocalMatrix(matrix) : false; } static void Shader_setLocalMatrix(JNIEnv* env, jobject, SkShader* shader, const SkMatrix* matrix) { - SkASSERT(shader != NULL); - - if (NULL == matrix) { - shader->resetLocalMatrix(); - } - else { - shader->setLocalMatrix(*matrix); + if (shader) { + if (NULL == matrix) { + shader->resetLocalMatrix(); + } + else { + shader->setLocalMatrix(*matrix); + } } } |