tystol / MonoTouch.ZBar

3 stars 5 forks source link

Crash occurring while presenting ZBarReaderViewController #4

Closed Willseph closed 11 years ago

Willseph commented 11 years ago

Hello, I'm currently using this binding in a Xamarin.iOS app I'm building but I'm consistently running into an issue. Although this repo isn't very active, hopefully you could maybe shed some insight.

I've written a detailed post on the Xamarin forums, but I'll copy what I've written for convenience: http://forums.xamarin.com/discussion/6773/app-crash-when-opening-zbar-barcode-scanning-view-controller#latest


When it wants to work, everything works great. The scanning is very accurate and quick, and it would really be a shame if I had to switch libraries.

Unfortunately, I'm running into a really weird issue with it. It starts off with me compiling the binding project and referencing the .dll in my real application. The library contains a child class of UIViewController, called ZBarReaderViewController. This view controller activates the camera and displays what it sees, and (from what I assume) periodically takes snapshots and analyzes them for valid barcodes.

In my app, I have a button in my navigation bar which instantiates my own child class of ZBarReaderViewController in order for the user to start scanning. This is where I run into my issue. After a seemingly random amount of time, or number of app launches, all of a sudden when I click the camera button, the app instantly crashes. This happens again and again, consecutively, until I either rebuild both the binding project and my app (which doesn't always work), or reboot the device (which also doesn't always work).

No exception is thrown either, so there isn't anything useful in Xamarin Studio while debugging, and often times the program itself will crash or otherwise experience issues after the app on the phone does. All I have to go by is the Xcode console output during the crash, which you can see here: http://pastebin.com/raw.php?i=x11YHYpu

Unfortunately I'm still a newbie at deciphering these iOS errors, so I'm not even sure where to look at this point. If anyone has any suggestions or things to try to at least narrow down the cause of the issue, I would be very grateful.

tystol commented 11 years ago

Can I see your child class of ZBarReaderViewController? That might offer some hints to what's causing it.

The other thing to try (and what you should prob be doing for performance anyway) is to only create 1 ZbarReaderViewController and reuse it each time you need to scan.

Willseph commented 11 years ago

Thanks for the quick reply. Here's my child class: http://pastebin.com/raw.php?i=MmLzRTLa

I'll change the way I'm bringing up that view controller to only create one instance like you advised, hopefully that will help it out. But let me know if you see any red flags in my child class.

Willseph commented 11 years ago

I just modified the child class to maintain only one instance, using the Singleton pattern. The scanning view controller is now presented, rather than navigated to, from the initiating view controller. The view controller that's actually presented is the singleton BarcodeScanningNavController (since I want the top toolbar to remain).

It did work a few times but it seems to be crashing once again.

Here's my updated class: http://pastebin.com/raw.php?i=uVZmWy4V

Willseph commented 11 years ago

And, if it helps, here's a new Xcode console output from a crash after making those modifications: http://pastebin.com/raw.php?i=Be4LV7YM

tystol commented 11 years ago

I don't know, sorry. Your class is doing quite a few things, I would start by cutting back features and retesting until it no longer occurs.

If you can reproduce it in a simple example, then please re-open this issue and I will look into it.

One thing I did notice was that you add your BottomBarView via some Add method of the controller - is that an extension method of yours? What does it do? If it is adding it to the controller's View property, that might be causing issues. The ZBarReaderViewController has a Overlay UIView property designed for your custom overlays, you shouldn't manipulate the view directly as it is managed by the base class controller. I expose it in the binding here: https://github.com/Its-Tyson/MonoTouch.ZBar/blob/master/binding/ApiDefinition.cs#L200-L204

This whole binding is a pretty thin wrapper around the obj-c library you linked to above - Make sure you've read their documentation in detail.

Cheers. Tyson.

Willseph commented 11 years ago

I've reached the point now where I'm simply presenting a new instance of the ZBarReaderViewController, without any of my child classes or anything, ie:

PresentViewController (new ZBar.ZBarReaderViewController(), true, () => {});

I'm starting to see a pattern now, too, that it's consistently crashing on Ad-Hoc mode, but it seems to be working on Release and Debug builds. I checked the iOS Build configurations and the Release and Ad-Hoc configuration settings are exactly the same, both of them with that "--nosymbolstrip=ZBarReaderControllerResults" additional mtouch argument.

Is there anything you can think of that would cause it to crash on Ad-Hoc all the time?

tystol commented 11 years ago

Do you have consistent compile settings for all your non-debug builds (Release, Ad-Hoc, AppStore)? I always compile all my release builds with LLVM enabled, although it should work either way.

Willseph commented 11 years ago

Yes I do. Here are my non-debug build settings: https://i.imgur.com/dEhMj77.png https://i.imgur.com/c8yYqO0.png

And my debug build settings: https://i.imgur.com/5WvY8Ml.png https://i.imgur.com/oB6g2Af.png

My build configurations for Release, Ad-Hoc and App Store are all identical.

tystol commented 11 years ago

Those screenshots show LLVM is disabled for Release builds. Can you try with it enabled - I always use LLVM (and I strip all assemblies, not just sdk)

but yeah no idea how to explain that it works in release and not ad