ios icon indicating copy to clipboard operation
ios copied to clipboard

interop.Reference to Array crashes App

Open cvietor opened this issue 4 years ago • 0 comments

Hi, i'm getting on error (app crashes) when trying to construct an interop.Reference to an array on @nativescript/ios. Given the following method to construct a reference to an array:

(https://github.com/NativeScript/ios-runtime/issues/1263#issuecomment-602615528)

function toReferenceToCArray<T>(a: T[], type: interop.Type<T>): interop.Reference<T> {
    const ref = new interop.Reference<T>(type, interop.alloc(interop.sizeof(type) * a.length));
    for (let i = 0; i < a.length; i++) {
        ref[i] = a[i]; // <---- ref[i] crashes
    }

    return ref;
}

const coordinates: CLLocationCoordinate2D[] = [CLLocationCoordinate2DMake(1, 2), CLLocationCoordinate2DMake(60, 190)];

const refCoords = toReferenceToCArray(coordinates, CLLocationCoordinate2D);

if i switch the iOS runtime to tns-ios (6.5.3), it works !

I created a small sample repo here: https://github.com/cvietor/ns7-ios-v8-marshalling-bug This may be related: https://github.com/NativeScript/ios-runtime/issues/1263

Error Log:

====== Assertion failed ======
Native stack trace:
1          0x10348e12c tns::Assert(bool, v8::Isolate*) + 128
2          0x103456244 tns::Reference::GetTypeEncodingDataPair(v8::Local<v8::Object>) + 152
3          0x103455f60 tns::Reference::IndexedPropertySetCallback(unsigned int, v8::Local<v8::Value>, v8::PropertyCallbackInfo<v8::Value> const&) + 64
4          0x1037de7b0 v8::internal::PropertyCallbackArguments::CallIndexedSetter(v8::internal::Handle<v8::internal::InterceptorInfo>, unsigned int, v8::internal::Handle<v8::internal::Object>) + 480
5          0x1037d33c0 v8::internal::(anonymous namespace)::SetPropertyWithInterceptorInternal(v8::internal::LookupIterator*, v8::internal::Handle<v8::internal::InterceptorInfo>, v8::Maybe<v8::internal::ShouldThrow>, v8::internal::Handle<v8::internal::Object>) + 216
6          0x1037d5eb0 v8::internal::JSObject::SetPropertyWithInterceptor(v8::internal::LookupIterator*, v8::Maybe<v8::internal::ShouldThrow>, v8::internal::Handle<v8::internal::Object>) + 52
7          0x1038f6194 v8::internal::Object::SetPropertyInternal(v8::internal::LookupIterator*, v8::internal::Handle<v8::internal::Object>, v8::Maybe<v8::internal::ShouldThrow>, v8::internal::StoreOrigin, bool*) + 236
8          0x1038f5ff8 v8::internal::Object::SetProperty(v8::internal::LookupIterator*, v8::internal::Handle<v8::internal::Object>, v8::internal::StoreOrigin, v8::Maybe<v8::internal::ShouldThrow>) + 76
9          0x1039c3708 v8::internal::Runtime::SetObjectProperty(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, v8::internal::StoreOrigin, v8::Maybe<v8::internal::ShouldThrow>) + 328
10         0x1039c6e44 v8::internal::Runtime_SetKeyedProperty(int, unsigned long*, v8::internal::Isolate*) + 88
11         0x103d5cc4c Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_NoBuiltinExit + 108
12         0x103dcfeac Builtins_StaKeyedPropertyHandler + 140
13         0x103cf56b4 Builtins_InterpreterEntryTrampoline + 244
14         0x103cf56b4 Builtins_InterpreterEntryTrampoline + 244
15         0x103d9b54c Builtins_PromiseConstructor + 1708
16         0x103cf126c Builtins_JSBuiltinsConstructStub + 204
17         0x103dd7de0 Builtins_ConstructHandler + 192
18         0x103cf56b4 Builtins_InterpreterEntryTrampoline + 244
19         0x103cee504 Builtins_ArgumentsAdaptorTrampoline + 228
20         0x103cf2a04 Builtins_ConstructProxy + 484
21         0x103dd7de0 Builtins_ConstructHandler + 192
22         0x103cf56b4 Builtins_InterpreterEntryTrampoline + 244
23         0x103cee504 Builtins_ArgumentsAdaptorTrampoline + 228
24         0x103cf56b4 Builtins_InterpreterEntryTrampoline + 244
25         0x103cee504 Builtins_ArgumentsAdaptorTrampoline + 228
26         0x103cf56b4 Builtins_InterpreterEntryTrampoline + 244
27         0x103cf56b4 Builtins_InterpreterEntryTrampoline + 244
28         0x103cf56b4 Builtins_InterpreterEntryTrampoline + 244
29         0x103cf56b4 Builtins_InterpreterEntryTrampoline + 244
30         0x103cf2f64 Builtins_JSEntryTrampoline + 164
31         0x103cf2c08 Builtins_JSEntry + 168
32         0x127314000 32  ???                                 0x0000000127314000 0x0 + 4952506368

cvietor avatar Nov 20 '20 07:11 cvietor