From a9d706ed38a2f88209ecd00ce2a7fb165865a1c5 Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Thu, 19 Apr 2018 16:12:22 -0700 Subject: [PATCH] Throw an error or return null if FlutterView.getBitmap fails (flutter/engine#5051) getBitmap had been doing FXL_CHECK assertions to check memory allocation failures and other errors. getBitmap will now return null to the caller instead. (The VM may throw OutOfMemoryError or other exceptions if JNI APIs fail) Fixes https://github.com/flutter/flutter/issues/16750 --- .../android/platform_view_android_jni.cc | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/engine/src/flutter/shell/platform/android/platform_view_android_jni.cc b/engine/src/flutter/shell/platform/android/platform_view_android_jni.cc index f75f54a896..9c16ebdd30 100644 --- a/engine/src/flutter/shell/platform/android/platform_view_android_jni.cc +++ b/engine/src/flutter/shell/platform/android/platform_view_android_jni.cc @@ -351,10 +351,14 @@ static jobject GetBitmap(JNIEnv* env, jobject jcaller, jlong shell_holder) { const SkISize& frame_size = screenshot.frame_size; jsize pixels_size = frame_size.width() * frame_size.height(); jintArray pixels_array = env->NewIntArray(pixels_size); - FXL_CHECK(pixels_array); + if (pixels_array == nullptr) { + return nullptr; + } jint* pixels = env->GetIntArrayElements(pixels_array, nullptr); - FXL_CHECK(pixels); + if (pixels == nullptr) { + return nullptr; + } auto pixels_src = static_cast(screenshot.data->data()); @@ -371,27 +375,39 @@ static jobject GetBitmap(JNIEnv* env, jobject jcaller, jlong shell_holder) { env->ReleaseIntArrayElements(pixels_array, pixels, 0); jclass bitmap_class = env->FindClass("android/graphics/Bitmap"); - FXL_CHECK(bitmap_class); + if (bitmap_class == nullptr) { + return nullptr; + } jmethodID create_bitmap = env->GetStaticMethodID( bitmap_class, "createBitmap", "([IIILandroid/graphics/Bitmap$Config;)Landroid/graphics/Bitmap;"); - FXL_CHECK(create_bitmap); + if (create_bitmap == nullptr) { + return nullptr; + } jclass bitmap_config_class = env->FindClass("android/graphics/Bitmap$Config"); - FXL_CHECK(bitmap_config_class); + if (bitmap_config_class == nullptr) { + return nullptr; + } jmethodID bitmap_config_value_of = env->GetStaticMethodID( bitmap_config_class, "valueOf", "(Ljava/lang/String;)Landroid/graphics/Bitmap$Config;"); - FXL_CHECK(bitmap_config_value_of); + if (bitmap_config_value_of == nullptr) { + return nullptr; + } jstring argb = env->NewStringUTF("ARGB_8888"); - FXL_CHECK(argb); + if (argb == nullptr) { + return nullptr; + } jobject bitmap_config = env->CallStaticObjectMethod( bitmap_config_class, bitmap_config_value_of, argb); - FXL_CHECK(bitmap_config); + if (bitmap_config == nullptr) { + return nullptr; + } return env->CallStaticObjectMethod(bitmap_class, create_bitmap, pixels_array, frame_size.width(), frame_size.height(),