nativescript-barcodescanner icon indicating copy to clipboard operation
nativescript-barcodescanner copied to clipboard

Invoking barcode scanner causes application crash on latest NativeScript ios platform (8.1.0)

Open bmacdonald opened this issue 2 years ago • 13 comments

When the barcode scanner is invoked, the application crashes on ios with the latest nativescript runtime.

NativeScript Info

✔ Component nativescript has 8.1.1 version and is up to date. ✔ Component @nativescript/core has 8.1.1 version and is up to date. ✔ Component @nativescript/ios has 8.1.0 version and is up to date.

Steps

  • Create an example application with the barcode scanner implemented.
  • configure beepOnScan to false.
  • Invoke the barcode scanner.

The crash has something to do with the _addVolumeObserver.

Stack

2021-09-10 14:08:28.074065-0400 someapp[844:112105] 58 0x101978e68 tns::Tasks::Drain() + 104 2021-09-10 14:08:28.074274-0400 someapp[844:112105] 59 0x101973088 +[NativeScript start:] + 572 2021-09-10 14:08:28.074308-0400 someapp[844:112105] 60 0x100e877a0 main + 676 2021-09-10 14:08:28.074339-0400 someapp[844:112105] 61 0x186469cf8 + 4 2021-09-10 14:08:28.074359-0400 someapp[844:112105] JavaScript stack trace: 2021-09-10 14:08:28.103018-0400 someapp[844:112105] at _addVolumeObserver (file:///app/vendor.js:146876:32)

Temporary fix:

        if (scanner['_observer']) {
            scanner['_observer']['_owner'] = undefined;
            scanner['_observer'] = undefined;
        }

bmacdonald avatar Sep 13 '21 15:09 bmacdonald

@bmacdonald Hello, I got the same issue on NS 8.1.0. How do you apply temporary fix for this issue ?

tdhman avatar Sep 14 '21 14:09 tdhman

@tdhman It's pretty gross and I am not proud of it, but you need to configure beepOnScan = false. Then create an instance of the barcode scanner class. Apply the properties to the class. I am using an angular service which wraps the scanner, but you don't have to do that. The reason it works is because there is an _addVolumeObserver method which will return if there is no _observer. This is intended to be a temporary hack. Hopefully, @EddyVerbruggen can possibly take a look.

        config.beepOnScan = false;
        const scanner =  new BarcodeScanner();
        if (scanner['_observer']) {
            scanner['_observer']['_owner'] = undefined;
            scanner['_observer'] = undefined;
        }
        return scanner.scan(config);

bmacdonald avatar Sep 14 '21 15:09 bmacdonald

One more tidbit of information about the crash, it looks like it is only occurring on the phones and ipad pro. It does not seem to crash on regular ipads.

bmacdonald avatar Sep 14 '21 15:09 bmacdonald

I'm also getting the same crash with NativeScript 8.1 on iPhone X iOS 14.

CONSOLE LOG: DEBUG_LOG: Creating barcode scanner...
====== Assertion failed ======
Native stack trace:
1          0x103cdc320 tns::Assert(bool, v8::Isolate*) + 128
2          0x103cfafe8 tns::Interop::WriteValue(v8::Local<v8::Context>, tns::TypeEncoding const*, void*, v8::Local<v8::Value>) + 5144
3          0x103cf9bac tns::Interop::SetFFIParams(v8::Local<v8::Context>, tns::TypeEncoding const*, tns::FFICall*, int, int, tns::V8Args&) + 120
4          0x103cf980c tns::Interop::CallFunctionInternal(tns::MethodCall&) + 356
5          0x103c6332c tns::ArgConverter::Invoke(v8::Local<v8::Context>, objc_class*, v8::Local<v8::Object>, tns::V8Args&, tns::MethodMeta const*, bool) + 780
6          0x103cb6bc8 tns::MetadataBuilder::InvokeMethod(v8::Local<v8::Context>, tns::MethodMeta const*, v8::Local<v8::Object>, tns::V8Args&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool) + 88
7          0x103cb6454 tns::MetadataBuilder::MethodCallback(v8::FunctionCallbackInfo<v8::Value> const&) + 220
8          0x103debe60 v8::internal::FunctionCallbackArguments::Call(v8::internal::CallHandlerInfo) + 544
9          0x103deb360 v8::internal::MaybeHandle<v8::internal::Object> v8::internal::(anonymous namespace)::HandleApiCallHelper<false>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::internal::Handle<v8::internal::Object>, v8::internal::BuiltinArguments) + 524
10         0x103deaaf8 v8::internal::Builtin_Impl_HandleApiCall(v8::internal::BuiltinArguments, v8::internal::Isolate*) + 228
11         0x1044c63cc Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_BuiltinExit + 108
12         0x10445f598 Builtins_InterpreterEntryTrampoline + 248
13         0x10445f598 Builtins_InterpreterEntryTrampoline + 248
14         0x10445f598 Builtins_InterpreterEntryTrampoline + 248
15         0x10445c578 construct_stub_create_deopt_addr + 344
16         0x10454f848 Builtins_ConstructHandler + 648
17         0x10445f598 Builtins_InterpreterEntryTrampoline + 248
// ...
72         0x10445f598 Builtins_InterpreterEntryTrampoline + 248
73         0x10445d36c Builtins_JSEntryTrampoline + 172
74         0x10445d004 Builtins_JSEntry + 164
75         0x103f37a70 v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) + 2532
76         0x103f37058 v8::internal::Execution::Call(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, int, v8::internal::Handle<v8::internal::Object>*) + 216
77         0x1040c2d14 v8::internal::Object::SetPropertyWithAccessor(v8::internal::LookupIterator*, v8::internal::Handle<v8::internal::Object>, v8::Maybe<v8::internal::ShouldThrow>) + 864
78         0x1040c6804 v8::internal::Object::SetPropertyInternal(v8::internal::LookupIterator*, v8::internal::Handle<v8::internal::Object>, v8::Maybe<v8::internal::ShouldThrow>, v8::internal::StoreOrigin, bool*) + 420
79         0x1040c6584 v8::internal::Object::SetProperty(v8::internal::LookupIterator*, v8::internal::Handle<v8::internal::Object>, v8::internal::StoreOrigin, v8::Maybe<v8::internal::ShouldThrow>) + 80
80         0x103faab54 v8::internal::StoreIC::Store(v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::Object>, v8::internal::StoreOrigin) + 1188
81         0x103fafc04 v8::internal::Runtime_StoreIC_Miss(int, unsigned long*, v8::internal::Isolate*) + 320
82         0x1044c628c Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_NoBuiltinExit + 108
83         0x1045468f4 Builtins_StaNamedPropertyHandler + 148
84         0x10445f598 Builtins_InterpreterEntryTrampoline + 248
85         0x10445f598 Builtins_InterpreterEntryTrampoline + 248
86         0x10445d36c Builtins_JSEntryTrampoline + 172
87         0x10445d004 Builtins_JSEntry + 164
88         0x103f37a70 v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) + 2532
89         0x103f37058 v8::internal::Execution::Call(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, int, v8::internal::Handle<v8::internal::Object>*) + 216
90         0x103d8a50c v8::Function::Call(v8::Local<v8::Context>, v8::Local<v8::Value>, int, v8::Local<v8::Value>*) + 448
91         0x103c64794 tns::ArgConverter::MethodCallback(ffi_cif*, void*, void**, void*) + 1164
92         0x103d57974 ffi_closure_SYSV_inner + 800
93         0x103d581b4 .Ldo_closure + 20
114        0x18f25c018 <redacted> + 768
115        0x18f25b7d0 CFRunLoopRunSpecific + 572
116        0x1a599d570 GSEventRunModal + 160
117        0x191b882d0 <redacted> + 1052
118        0x191b8d84c UIApplicationMain + 164
119        0x103d58044 ffi_call_SYSV + 68
120        0x103d571d8 ffi_call_int + 968
121        0x103cf9854 tns::Interop::CallFunctionInternal(tns::MethodCall&) + 428
122        0x103cbbb9c std::__1::__function::__func<tns::MetadataBuilder::CFunctionCallback(v8::FunctionCallbackInfo<v8::Value> const&)::$_2, std::__1::allocator<tns::MetadataBuilder::CFunctionCallback(v8::FunctionCallbackInfo<v8::Value> const&)::$_2>, void ()>::operator()() + 564
123        0x103d1ce68 tns::Tasks::Drain() + 104
124        0x103d17088 +[NativeScript start:] + 572
125        0x102d6e900 125 mobile                              0x0000000102d6e900 mobile + 26880
126        0x18ef3a140 <redacted> + 4
JavaScript stack trace:
at _addVolumeObserver (file: src/webpack:/mobile/node_modules/nativescript-barcodescanner/barcodescanner.ios.js:96:0)
at <anonymous> (file: src/webpack:/mobile/node_modules/nativescript-barcodescanner/barcodescanner.ios.js:178:0)
at new ZoneAwarePromise (file: src/webpack:/mobile/node_modules/zone.js/fesm2015/zone.js:1387:0)
at scan (file: src/webpack:/mobile/node_modules/nativescript-barcodescanner/barcodescanner.ios.js:169:0)
at createBarcodeScanner (file: src/webpack:/mobile/src/app/modules/scanner/barcode-scanner/barcode-scanner.component.ts:121:7)
at <anonymous> (file: src/webpack:/mobile/src/app/modules/scanner/barcode-scanner/barcode-scanner.component.ts:59:15)
at <anonymous> (file: src/webpack:/mobile/node_modules/rxjs/dist/cjs/internal/Subscriber.js:161:0)
at exports.modules../node_modules/rxjs/dist/cjs/internal/Subscriber.js.Subscriber._next (file: src/webpack:/mobile/node_modules/rxjs/dist/cjs/internal/Subscriber.js:101:0)
at exports.modules../node_modules/rxjs/dist/cjs/internal/Subscriber.js.Subscriber.next (file: src/webpack:/mobile/node_modules/rxjs/dist/cjs/internal/Subscriber.js:72:0)
at exports.modules../node_modules/rxjs/dist/cjs/internal/BehaviorSubject.js.BehaviorSubject._subscribe (file: src/webpack:/mobile/node_modules/rxjs/dist/cjs/internal/BehaviorSubject.js:36:0)

rob4226 avatar Sep 14 '21 18:09 rob4226

Same issue as #275

I updated all versions meanwhile, but still the same.

✔ Xcode is installed and is configured properly. ✔ xcodeproj is installed and is configured properly. ✔ CocoaPods are installed. ✔ CocoaPods update is not required. ✔ CocoaPods are configured properly. ✔ Your current CocoaPods version is newer than 1.0.0. ✔ Python installed and configured correctly. ✔ The Python 'six' package is found. ✔ Xcode version 13.0.0 satisfies minimum required version 10. ✔ Getting NativeScript components versions information... ✔ Component nativescript has 8.1.2 version and is up to date. ✔ Component @nativescript/core has 8.1.3 version and is up to date. ✔ Component @nativescript/ios has 8.1.0 version and is up to date.

LaKing avatar Sep 30 '21 16:09 LaKing

Yeah this is a known problem with NS v8.1. You can try the temporary hack:

const scanner =  new BarcodeScanner();
if (scanner['_observer']) {
  scanner['_observer']['_owner'] = undefined;
  scanner['_observer'] = undefined;
}
return scanner.scan(config);

rob4226 avatar Oct 01 '21 03:10 rob4226

Yes, thank you @rob4226 , that workaround works.

LaKing avatar Oct 01 '21 04:10 LaKing

This will fix it https://github.com/EddyVerbruggen/nativescript-barcodescanner/pull/278 - the actual instance was undefined and was still getting passed the (!this._observer) check so it would crash when adding it. Fix tested and works on iOS 15 and NS 8.1. Demo app functioning in that PR confirmed.

bradmartin avatar Oct 14 '21 18:10 bradmartin

@bradmartin Nice job!! Tried it and it seems to be working well now!

rob4226 avatar Oct 15 '21 03:10 rob4226

@EddyVerbruggen any update on this one?

grigala avatar Nov 01 '21 11:11 grigala

would be great if this can be merged

eikaramba avatar Aug 16 '22 21:08 eikaramba

@eikaramba given the activity record of Eddy lately, I doubt anything would change in this repo anytime soon.

You need to pull the same plugin from @nstudio namespace - @nstudio/nativescript-barcodescanner which is up-to date and includes the solution of this problem.

grigala avatar Aug 17 '22 06:08 grigala

Thanks for the tip!

eikaramba avatar Aug 17 '22 13:08 eikaramba