Skip to content

fix(image_layers) image layers crash on Android#119

Merged
hm21 merged 5 commits intohm21:stablefrom
ekuleshov:android_image_recycle
Apr 11, 2026
Merged

fix(image_layers) image layers crash on Android#119
hm21 merged 5 commits intohm21:stablefrom
ekuleshov:android_image_recycle

Conversation

@ekuleshov
Copy link
Copy Markdown
Contributor

Description

Related Issue: Closes #118

Type of Change

  • ✨ New feature (non-breaking change which adds functionality)
  • 🛠️ Bug fix (non-breaking change which fixes an issue)
  • ❌ Breaking change (fix or feature that would cause existing functionality to change)
  • 🧹 Code refactor
  • ✅ Build configuration change
  • 📝 Documentation
  • 🗑️ Chore

Copy link
Copy Markdown
Owner

@hm21 hm21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! I looked into the Bitmap.scale() extension from androidx.core.graphics it delegates to Bitmap.createScaledBitmap(), which returns the same object when width and height already match. So calling recycle() on that would indeed crash. The defensive !== check in change 1 (line ~92) is a valid fix for that edge case.

However, I want to point out that change 2 (line ~110) is logically redundant, the scale() call is already inside an if block that checks sizedBitmap.width != videoWidth || sizedBitmap.height != videoHeight, so at least one dimension always differs, meaning createScaledBitmap will always return a new object there. The added guard can never trigger. It's harmless but i think it's unnecessary. Could you try remove it and check if it's still crash then?

…oid_image_recycle

# Conflicts:
#	android/src/main/kotlin/ch/waio/pro_video_editor/src/features/render/helpers/ApplyImageLayer.kt
@ekuleshov
Copy link
Copy Markdown
Contributor Author

ekuleshov commented Apr 10, 2026

However, I want to point out that change 2 (line ~110) is logically redundant, the scale() call is already inside an if block that checks sizedBitmap.width != videoWidth || sizedBitmap.height != videoHeight...

You are right. Though apparently the check for "same image" in the scale() code is a bit more elaborate than the outer condition here. So, I figured that removing outer condition and let scale() deal with the same size is cleaner approach, if you are okay with that.

Also noticed that generate thumbnails code doesn't do recycle() on interim bitmaps either. I've pushed a chenge to this PR as well.

Let me know if you don't want these changes. I'll revert.

Copy link
Copy Markdown
Owner

@hm21 hm21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM and thanks for the update

@hm21 hm21 merged commit 1aa2d52 into hm21:stable Apr 11, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: recycled bitmaps on Android

2 participants