xamarin / ios-samples

Xamarin.iOS sample apps
http://docs.microsoft.com/xamarin/ios/
Other
1.59k stars 1.92k forks source link

ARKit / iOS - App crashes in release mode using SceneView.Snapshot() #446

Closed smazza94 closed 2 years ago

smazza94 commented 2 years ago

I'm developing an AR application based on "Placing Objects" template, but trying to get a snapshot from the SceneView I got a crash in release mode (if I try in debug mode it's working perfectly).

I tried to debug using Device Log tool and I found the following Exception:

Unhandled managed exception: Unable to marshal the parameter #1 whose managed type is 'SceneKit.SCNSceneRenderer' to managed

Screenshot 2022-03-21 at 10 41 14

It seems that snapshot goes in conflict with RendererUpdateAtTime, but I can't find a way to fix it.

Anyone can help me?

chamons commented 2 years ago

Thanks for the feedback!

So that appears to be coming from xamarin_invoke_trampoline in trampolines-invoke.m.

Since you said it only happens in release mode, I wonder if the linker is removing that code, and we are unexpectedly needing it in this case.

As a debugging measure, try setting the linker to "Don't link" and re-running your test in Release mode.

It would also be helpful if you could produce a small sample project showing the crash.

smazza94 commented 2 years ago

I did the following change and the problem went away

instead of

[Export("renderer:updateAtTime:")]
public void RendererUpdateAtTime(SCNSceneRenderer renderer, double updateAtTime)

use

[Export("renderer:updateAtTime:")]
public void Update(ISCNSceneRenderer renderer, double timeInSeconds)

Maybe a conflict with the SCNSceneRenderer... any ideas?

Thanks anyway! @chamons

chamons commented 2 years ago

Oh I missed this on my first read:

image

Hey @rolfbjarne thoughts?

rolfbjarne commented 2 years ago

Looks like this is a problem from back in Classic Xamarin days, this is the api definition:

https://github.com/xamarin/xamarin-macios/blob/5740e372a0e3ddb019beaa16bbc6f22959da7a25/src/scenekit.cs#L3273-L3275

in other words: using ISCNSceneRender as the first parameter type is correct (and the fix).

chamons commented 2 years ago

I'll PR that fix shortly.