ios-jsc
ios-jsc copied to clipboard
Audio Toolkit crash in marshaling
Environment
- Real iPhone device (Cannot use emulator, as emulator doesn't support Audio Toolkit)
- CLI: 5.2.x (latest)
- Cross-platform modules: 5.2.x (latest)
- iOS Runtime: 5.2.x (latest)
- Plugin(s): None
Describe the bug About 1 in 6 times when I activate the record (after a re-starting of app) the app will just vanish. The app will complete crash out without any errors; messages, nor anything in the console. Even viewing the native (tns device log) does not appear to show any error; just that the app quit.
Most the time everything works great; but occasionally it just poof vanishes. The app is a very simple sample app with a record and stop button (and console logging to show data callbacks are working). If the first record in the app works; then all other record's work (as far as I've seen while doing testing). Only the first record on a app restart can cause it to fail.
To Reproduce
- Click "Start";
- If works, restart app; go to step 1.
Expected behavior Always works.
Sample project Private app; please let me know where to send it.
Additional context I believe it must be some marshaling issue; not 100% sure if the issue is marshaling into the native; or from native back to the callback.
It sounds like it could be related to #1106. I'm still investigating it and trying to come up with a solution, but I've found the main reason for the crash. In 5.2 we've addressed a memory leak which prevented instances of JavaScript implemented classes to be deallocated. This, however, has lead to cases where native objects can be deallocated prematurely. Hopefully, a proper fix will be released with 5.3.0 or shortly after in a patch version. Meanwhile I think I've found a workaround by manually adding a reference from some other JavaScript object which will keep the callback alive (e.g. in the case of the sample app from #1106, one can ensure the delegate is kept alive by adding audioPlayer.__js_delegate = this;
here https://github.com/KkevinLi/NativescriptAudioTest/blob/61927489ea5b51bc65a8d1c22d62ac947febe7b2/src/app/item/audio-player.ts#L113)
@mbektchiev - LOL, initially I was going to put this on #1106 - however, this code does NOT use a delegate. So I figured this was probably a different issue.
This code uses a lot of interop
functionality and including things like a interop.FunctionReference
to a callback... I'm not a 100% sure exactly what causes it to go poof. (The logs basically say process has died) When it goes poof; my last console log always shows me starting the process; and then poof nothing else. It could be the start of the process is dying or it could be the callback (from native to JS) call is dying.
@mbektchiev - Martin, btw, I can give you access to it a several ways, let me know which -- and I can use your progress email account...
- I have a private gitlab site where I can give you access to the repo with the project setup. (clone and then just install node modules/platforms)
- I have a file sending/downloading site; the file can be zipped up with no modules/platforms. :grinning:
- I can email you the three files (i.e. main screen js/xml, and required .js file), and you can create a new JS project and then just drop them into it.
- Slack upload
- ???