Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit adee351

Browse files
Throw an error or return null if FlutterView.getBitmap fails (#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 flutter/flutter#16750
1 parent 637e921 commit adee351

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

shell/platform/android/platform_view_android_jni.cc

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,14 @@ static jobject GetBitmap(JNIEnv* env, jobject jcaller, jlong shell_holder) {
351351
const SkISize& frame_size = screenshot.frame_size;
352352
jsize pixels_size = frame_size.width() * frame_size.height();
353353
jintArray pixels_array = env->NewIntArray(pixels_size);
354-
FXL_CHECK(pixels_array);
354+
if (pixels_array == nullptr) {
355+
return nullptr;
356+
}
355357

356358
jint* pixels = env->GetIntArrayElements(pixels_array, nullptr);
357-
FXL_CHECK(pixels);
359+
if (pixels == nullptr) {
360+
return nullptr;
361+
}
358362

359363
auto pixels_src = static_cast<const int32_t*>(screenshot.data->data());
360364

@@ -371,27 +375,39 @@ static jobject GetBitmap(JNIEnv* env, jobject jcaller, jlong shell_holder) {
371375
env->ReleaseIntArrayElements(pixels_array, pixels, 0);
372376

373377
jclass bitmap_class = env->FindClass("android/graphics/Bitmap");
374-
FXL_CHECK(bitmap_class);
378+
if (bitmap_class == nullptr) {
379+
return nullptr;
380+
}
375381

376382
jmethodID create_bitmap = env->GetStaticMethodID(
377383
bitmap_class, "createBitmap",
378384
"([IIILandroid/graphics/Bitmap$Config;)Landroid/graphics/Bitmap;");
379-
FXL_CHECK(create_bitmap);
385+
if (create_bitmap == nullptr) {
386+
return nullptr;
387+
}
380388

381389
jclass bitmap_config_class = env->FindClass("android/graphics/Bitmap$Config");
382-
FXL_CHECK(bitmap_config_class);
390+
if (bitmap_config_class == nullptr) {
391+
return nullptr;
392+
}
383393

384394
jmethodID bitmap_config_value_of = env->GetStaticMethodID(
385395
bitmap_config_class, "valueOf",
386396
"(Ljava/lang/String;)Landroid/graphics/Bitmap$Config;");
387-
FXL_CHECK(bitmap_config_value_of);
397+
if (bitmap_config_value_of == nullptr) {
398+
return nullptr;
399+
}
388400

389401
jstring argb = env->NewStringUTF("ARGB_8888");
390-
FXL_CHECK(argb);
402+
if (argb == nullptr) {
403+
return nullptr;
404+
}
391405

392406
jobject bitmap_config = env->CallStaticObjectMethod(
393407
bitmap_config_class, bitmap_config_value_of, argb);
394-
FXL_CHECK(bitmap_config);
408+
if (bitmap_config == nullptr) {
409+
return nullptr;
410+
}
395411

396412
return env->CallStaticObjectMethod(bitmap_class, create_bitmap, pixels_array,
397413
frame_size.width(), frame_size.height(),

0 commit comments

Comments
 (0)