question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

width and height must be > 0

See original GitHub issue

New Issue Checklist

  • [X ] I have searched for a similar issue in the project and found none

Issue Info

Info Value
Device Info e.g. ZTE BLADE V9, and most Android 9 to lower
System Version e.g. 7 to 9
APNG4Android Library Version e.g. 2.17
Repro rate e.g. all the time (100%)
Repro with our demo project e.g. does it happen with our demo project?
Demo project link none

Issue Description and Steps

Im trying to solve error and to pass error with Try Catch without success, i have hours and days of debugging to check if app is passing a null image but not, it only happens on old Android devices when i load about 30 animated webps in imageviews, on newer version of android is OK.

Fatal Exception: java.lang.IllegalArgumentException: width and height must be > 0 at android.graphics.Bitmap.createBitmap(Bitmap.java:1114) at android.graphics.Bitmap.createBitmap(Bitmap.java:1081) at android.graphics.Bitmap.createBitmap(Bitmap.java:1031) at android.graphics.Bitmap.createBitmap(Bitmap.java:992) at com.github.penfeizhou.animation.decode.FrameSeqDecoder.obtainBitmap(FrameSeqDecoder.java:130) at com.github.penfeizhou.animation.webp.decode.WebPDecoder.renderFrame(WebPDecoder.java:146) at com.github.penfeizhou.animation.decode.FrameSeqDecoder.step(FrameSeqDecoder.java:505) at com.github.penfeizhou.animation.decode.FrameSeqDecoder.access$200(FrameSeqDecoder.java:36) at com.github.penfeizhou.animation.decode.FrameSeqDecoder$1.run(FrameSeqDecoder.java:60) at com.github.penfeizhou.animation.decode.FrameSeqDecoder.innerStart(FrameSeqDecoder.java:310) at com.github.penfeizhou.animation.decode.FrameSeqDecoder.access$900(FrameSeqDecoder.java:36) at com.github.penfeizhou.animation.decode.FrameSeqDecoder$9.run(FrameSeqDecoder.java:446) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:240) at android.os.HandlerThread.run(HandlerThread.java:67)

Happens on FrameSeqDecoder.obtainBitmap, i have more than 1000 alerts of errors on Crashlytics.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:41 (15 by maintainers)

github_iconTop GitHub Comments

2reactions
Ferdaricommented, Jan 20, 2022

Hi again, after heavy testing and debugging the new version, there is still the same problem,

Checking my webp files, i found one that is causing this bug, if webp has a transparent frame or blank frame it causes error width and height must be > 0 even if it has same height and width than next frames: imagen Look at first frame, it are blank frame/transparent frame, if use it in my app, app crashes(only on some phones).

But if i delete blank frame it work like charm in app, so the problem is in some devices blank frames are detected without size. apparently APNG detects the size of frame correctly, but not android.graphics.Bitmap.createBitmap 0x0px when passed to system.

Affected webp, test on your phone this files: https://cdn.noten.in/temp/badwebp.webp ❌ With blank frame https://cdn.noten.in/temp/goodwebp.webp ✔️Edited on EzGif

So how to check if frame is transparent? by size? by color depth? maybe can skip transparent frames.

My app loads dynamically a grid of imageviews, so i cant edit one by one, i have like 125,620 webps on server to load.

1870 user phones has same error imagen

1reaction
penfeizhoucommented, Jan 20, 2022

When parsing WebP formats, there is no relation to android platform api. And according to webp spec, the width and height cannot be less than 1.Because this is a unsigned value.

Canvas Width Minus One: 24 bits
1-based width of the canvas in pixels. The actual canvas width is '1 + Canvas Width Minus One'
Canvas Height Minus One: 24 bits
1-based height of the canvas in pixels. The actual canvas height is '1 + Canvas Height Minus One'

This could only happen when there is no ANIM Chunk, this library treats it as non animated webp. In this case, it calls platform api to get width and height.

if (!anim) {
            //静态图
            if (!vp8x) {
                BitmapFactory.Options options = new BitmapFactory.Options();
                options.inJustDecodeBounds = true;
                BitmapFactory.decodeStream(reader.toInputStream(), null, options);
                canvasWidth = options.outWidth;
                canvasHeight = options.outHeight;
            }
            frames.add(new StillFrame(reader, canvasWidth, canvasHeight));
            this.loopCount = 1;
        }
Read more comments on GitHub >

github_iconTop Results From Across the Web

IllegalArgumentException: width and height must be > 0 while ...
java.lang.IllegalArgumentException: width and height must be > 0 is because in your Bitmap.
Read more >
java.lang.IllegalArgumentException: width and height ... - GitHub
This code got the exception when I used imageloader.. The text was updated successfully, but these errors were encountered: ...
Read more >
Getting width and height must be >0 - Android - CodeRanch
I am capturing the view of the scroll view and create the bimap object and then saving the image into the device
Read more >
[Solved] How to fix Crashlytics "width and height must be > 0 ...
Fatal Exception: java.lang.IllegalArgumentException: width and height must be > 0 at android.graphics.Bitmap.createBitmap(Bitmap.java:829)
Read more >
Crash in java.lang.IllegalArgumentException: width and height ...
Crash in java.lang.IllegalArgumentException: width and height must be > 0 at android.graphics.Bitmap.createBitmap(Bitmap.java).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found