Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IllegalArgumentException: Both dimensions must be greater than 0 #272

Closed
ankitjp opened this issue Feb 18, 2016 · 13 comments
Closed

IllegalArgumentException: Both dimensions must be greater than 0 #272

ankitjp opened this issue Feb 18, 2016 · 13 comments
Labels
Milestone

Comments

@ankitjp
Copy link

ankitjp commented Feb 18, 2016

i am getting crash on my device while open QR Scanner.

Throw exception in ZXBitMatrix.m line no: 34
Method Name: - (id)initWithWidth:(int)width height:(int)height
OS running in Device: iOS 9.2

: CGContextSetAllowsAntialiasing: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
: CGContextSetInterpolationQuality: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
: CGContextDrawImage: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
: CGBitmapContextGetData: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Both dimensions must be greater than 0'
*** First throw call stack:

(0x180a39900 0x1800a7f80 0x1000edd14 0x100133920 0x100134f80 0x1000ead90 0x100184e68 0x100145744 0x1001445e8 0x1000f7d3c 0x186ce74c0 0x186ce7358 0x1829f4084 0x182a0fcf4 0x10143dbb0 0x101455f54 0x101440154 0x10144a8e4 0x1014418a0 0x10144a8e4 0x1014418a0 0x10144c7e0 0x10144c4d8 0x1806a1470 0x1806a1020)

@EchoLi0904
Copy link

I have the same issue now, any answer?

@dpolivy
Copy link

dpolivy commented Nov 8, 2018

I'm seeing the same crash occuring on some devices in the wild (haven't repro'ed it locally yet). It's happening on an iPhone XS Max with iOS 12.0.1. Any ideas on where to look, or what might trigger this?

NSInvalidArgumentException: Both dimensions must be greater than 0

2            -[ZXBitMatrix initWithWidth:height:] (ZXBitMatrix.m:37:7)
3            -[ZXGlobalHistogramBinarizer blackMatrixWithError:] (ZXGlobalHistogramBinarizer.m:89:25)
4            -[ZXHybridBinarizer blackMatrixWithError:] (ZXHybridBinarizer.m:71:19)
5            -[ZXBinaryBitmap blackMatrixWithError:] (ZXBinaryBitmap.m:61:19)
6            -[ZXQRCodeReader decode:hints:error:] (ZXQRCodeReader.m:56:25)
7            -[ZXMultiFormatReader decodeInternal:error:] (ZXMultiFormatReader.m:194:26)
8            -[ZXMultiFormatReader decode:hints:error:] (ZXMultiFormatReader.m:84:10)
9            -[ZXCapture captureOutput:didOutputSampleBuffer:fromConnection:] (ZXCapture.m:396:28)
10            -[AVCaptureVideoDataOutput _processSampleBuffer:]

@benjohnde benjohnde reopened this Nov 9, 2018
@benjohnde
Copy link
Member

Interesting. It should not be invoked with a dimension lower or equal than zero. I am trying to investigate the bug this week.

@dpolivy
Copy link

dpolivy commented Nov 27, 2018

@benjohnde It's definitely a frequent occurrence in our app, I'm seeing 143 errors reported so far. 80% on iPhone XS Max if that helps pinpoint it (the rest are on iPhone XR). The one thing that I see in the trace breadcrumbs is that there appears to be a transition from portrait to landscapeleft on the device a few seconds before the crash. I don't have an XS Max or XR to physically test with, and haven't been able to repro with the remote test service I use.

@benjohnde
Copy link
Member

@dpolivy not quite sure. Could be related to rotation.

It seems to me (maybe you can recheck that with your stack traces), that it always happens here:

https://github.com/TheLevelUp/ZXingObjC/blob/master/ZXingObjC/common/ZXHybridBinarizer.m#L70

Which basically indicates some weird behaviour, because the image should "never" be that small. Hence, I assume that the incoming ZXBinaryBitmap is already too small. But that is somehow another bug. For me, it feels that the ZXHybridBinarizer should check not only for too small but for irregular bitmaps. That said, the better approach would be to, in that particular case, propagate a well-formulated NSError back.

@benjohnde
Copy link
Member

I am investigating the issue a bit more and going to prepare a fix this week.

Maybe due to rotation the incoming image is just empty (zero).

@benjohnde benjohnde added this to the 3.7.0 milestone Nov 27, 2018
@benjohnde
Copy link
Member

Something like TheLevelUp/ZXingObjC@e5326ed

@benjohnde
Copy link
Member

I am still doing some tests and diving through the code.

@dpolivy
Copy link

dpolivy commented Nov 27, 2018

It'd be much better if I had an XS Max to use for repro testing 😄 I think you're right on ZXHybridBinarizer.m being in the middle of it. The stack is pretty consistent, basically the same as what I posted earlier in the thread. It's going through ZXQRCodeReader.m. Perhaps when rotated to landscapeleft, one of the width/height dimensions is coming back negative?

@benjohnde
Copy link
Member

Yeah, you are right. Either it is coming back negative or zero. Both would lead to this issue. Should be fixed with the latest commit. I am going to fix a bunch of other stuff and then releasing 3.7.0. Stay tuned: hopefully on Monday I am ready to release the new version.

@benjohnde
Copy link
Member

benjohnde commented Nov 30, 2018

@dpolivy I released the fix with 3.6.2. Hopefully it serves you well!

@dpolivy
Copy link

dpolivy commented Nov 30, 2018

@benjohnde Thanks! Will incorporate into my next app rev. But, does code handle the negative case, or just 0 case? Bigger question, if it is negative/zero, is that a sign of an issue higher up the chain? Should the QR code reader work if the device is rotated?

benjohnde added a commit that referenced this issue Dec 4, 2018
@benjohnde
Copy link
Member

@dpolivy you are right, now the fix also handles negative values.

Hmm good question, hard for me to test it here. I believe it could be an issue higher up the chain. I believe the QR code reader works even if the device is rotated. Maybe one or two frames directly after the rotation may misbehave. Could also be an error in ZXCapture, hard to tell right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants