Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Barcode (VIN) scanning in Android

$
0
0

In our app we have functionality that uses a native library to scan VIN barcodes see here: http://forums.xamarin.com/discussion/9304/building-a-barcode-scanning-feature-with-xamarin-we-are-encountering-specific-problem .

It worked fine until the last Xamarin update (current Xamarin.Android version is 4.10.1073).

After the last update, the behavior became strange:

1) I'll copy my code here: [DllImport("b4hvinscanner", EntryPoint = "Java_com_bees4honey_vinscanner_B4HScanner_parse")] static extern IntPtr _Parse( IntPtr jnienv, // JNIEnv.Handle IntPtr self, // For instance method, this reference IntPtr data, // JNI handle to Java-side byte[] int size, int width, int height, int q, IntPtr context); // JNI handle to Java-side Context

public static string Parse(byte[] data, int size, int width, int height, int q, Context context) { IntPtr lrefData = IntPtr.Zero; try { lrefData = JNIEnv.NewArray(data); var contextPtr = context == null ? IntPtr.Zero : context.Handle; IntPtr resultRef = _Parse(JNIEnv.Handle, IntPtr.Zero, lrefData, size, width, height, q, contextPtr); var result = JNIEnv.GetString(resultRef, JniHandleOwnership.TransferLocalRef); return result; } finally { if (lrefData != IntPtr.Zero) { JNIEnv.DeleteLocalRef(lrefData); } } }

I'm able to call Parse method, and it works ok (it does still parse VIN barcodes), but after VIN is successfully scanned, app freezes after several seconds.

btw, method Parse called twice a second until 'data' array will contain good preview with VIN barcode. app freezes ONLY after successful scan (in this case 'result' string will be not empty)

Looking to log, I see:

12-20 11:33:35.051 E/mono-rt (25147): ================================================================= 12-20 11:33:35.051 E/mono-rt (25147): Got a SIGSEGV while executing native code. This usually indicates 12-20 11:33:35.051 E/mono-rt (25147): a fatal error in the mono runtime or one of the native libraries 12-20 11:33:35.051 E/mono-rt (25147): used by your application. 12-20 11:33:35.051 E/mono-rt (25147): =================================================================

before this message, there are several lines like this: 01-20 13:37:43.859 W/dalvikvm( 9956): JNI: unpinPrimitiveArray(0x431d7370) failed to find entry (valid=1)

Most of times the app freezes when I call var doc = new XmlDocument(); after 'Parce' method usage

And in this case log contains: 01-20 13:37:44.996 W/Mono ( 9956): The request to load the assembly System.Xml v2.0.5.0 was remapped to v2.0.0.0

My gues is that I am not properly deallocating some resources (maybe I should deallocate 'resultRef' somehow, or maybe JNIEnv.DeleteLocalRef(lrefData); line is wrong).

I want to clarify once again: this code worked fine a month ago!

Any help would be much appreciated.


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>