Apple’s new way of handling returned values in form of blocks instead of delegate methods makes it a bit easier to implement such methods in Xojo, but currently in my attempts it makes it much more unstable too.
I ran into the following: I use an iOSBlock to receive the buffer data and timestamp from an AVAudioEngine. This runs nicely; the block is called frequently and I can see the changes in both values by logging them to the console. But I cannot analyze them. When I try to create an object from their pointer values inside the block (buffer is an AVAudioPCMBuffer, Time an AVAudiotime object), Simulator crashes with a StackOverflow.
I can, anyway, write the ptr values to properties attached to the iOSView. But I could not find a way to trigger their analyzation afterwards. A timer.CallLater in the block gives me another StackOverflow, so I tried attaching a timer to the iOSView with a very short delay, set to modes.off. Inside the block, I activate it with timer.modes.single. Nothing happens, the action method never gets called.
I then tried to make the timer run repeatedly. It fires then, but only if I comment everything in the block. If the block contains code to execute, the whole thing crashes again, this time with a retainCount sent to a forbidden address this looks like a destructor at work but I cannot convince the debug methods to work in that case. Before I get a hint on what object it tries to deallocate, the crash appears.
For those of you into iOS or OS X declares: How do you handle such cases? I thought maybe creating a custom class with a custom method on its iOS side that is called from the block can help but that looks like more problems than the good old complicated delegate handling. And how, if a custom iOS method succeeds, would I jump from it into the main thread again to trigger for example a visualization of the analyzed data from a Xojo method?