The problem is the C# Garbage Collector and the fact that the Wikitude SDK expects to be managed correctly and reliable since it is implemented in C++. That's why the xamarin application needs to make sure the memory is manged correctly and unfortunately you have to write some more code to get the garbage collector to do it's job as we expect in C++.
Best regards
Andreas
F
Frank Ortner
said
about 7 years ago
Then there must still be present an instance that has not been taken into account. Look at the example of Wikitude, and check if the instantiation is unique and Dispose() is actually called.
I think that the implementation of Wikitude is not quite comprehensively. I think that an existing instance should be eliminated or used when creating an Architect View.
A
Alexey Volkov
said
about 7 years ago
For me it worked once.
On the second enter/exit it crashes with the same error for me.
P
Pedro Antonio Seco de Herrera Gómez
said
about 7 years ago
It works !!!!!!!
Thank you very much Frank, you saved my life ... i have spent a long time with this issue. Just in time for upload the App with Wikitude 5.
Thanks !!
F
Frank Ortner
said
about 7 years ago
Hi Pedro,
i checked my solution again and noticed that there is another important step to do.
Here is my working code from the ViewController:
public override void ViewWillDisappear (bool animated) {
So not only the RemoveFromSuperview is important, also the overridden Dispose method is important too.
I hope it will work for you.
P
Pedro Antonio Seco de Herrera Gómez
said
about 7 years ago
Hi Frank.
Your solution does not work for me. When i get back and re-open the ViewController then get the error ... it's frustrating
Regards
F
Frank Ortner
said
about 7 years ago
As i wrote before, the Error ist gone by explicitly calling architectView.RemoveFromSuperview() but i have wasted much time with building around the error/bug with a weak reference (seen before in the hint from Andreas Schacherbauer in the technical note).
N
Nicola Radacher
said
about 7 years ago
Hi,
Does this info help:
Please note that the Wikitude iOS SDKs are now more strict when it comes to memory handling. In case an application creates multiple instances of the SDK, the hosting application needs to make sure that the previously created instance is destroyed properly before the new one is created. Otherwise the application will crash with an stack trace like this mentioning InitGoogleLogging() twice:
The reason oftentimes is a retain cycle because the WTArchitectView or WTWikitudeNativeSDK object is strongly referenced in a block. Simply create a weak pointer to your Wikitude SDK object and use this weak pointer inside the block.
Greetings
Nicola
F
Frank Ortner
said
about 7 years ago
In Xamarin i have tryed everything with WeakReferences but without success.
Finaly i set architectView.RemoveFromSuperview(); in the ViewWillDisappear (bool animated) and the Error:
Check failed: !IsGoogleLoggingInitialized() You called InitGoogleLogging() twice! is gone because all references are probably unset.
P
Pedro Antonio Seco de Herrera Gómez
said
over 7 years ago
One more thing ... on xamarin there is no way for do
;
you can only do:
architectView.Start or architectView.Stop
P
Pedro Antonio Seco de Herrera Gómez
said
over 7 years ago
Hello Andreas,
I tried this code on Xamarin, but it doesnt work:
Only work the first time, and the Controller is a Weak Reference like you say
This code works good with xamarin plugin 4.2.1, but fails on 5.0.0, dont know why ...
UIStoryboard story = UIStoryboard.FromName ("MainStoryboard", null); var view = story.InstantiateViewController ("ViewController") as WikitudeViewController; var weakThis = new WeakReference<WikitudeViewController> (view); weakThis.TryGetTarget (out view); var nav = new UINavigationController (view); UIApplication.SharedApplication.Windows .RootViewController = nav; UIApplication.SharedApplication.Windows .MakeKeyAndVisible ();
A
Andreas Schacherbauer
said
over 7 years ago
Hi Pedro, Lorenzo gave the correct answer to the problem. When using the +addObserverForName method from the NSNotificationCenter, you need to make sure to not retain self inside the block. The solution is to create a weak representation of self which you can make with __unsafe_unretained or __weak. This breaks the dependency cycle and the Wikitude SDK can get deallocated.
Best regards
Andreas
L
Lorenzo
said
over 7 years ago
I'm sorry but I never used Xamarin and I have no idea how the code works.. sorry
P
Pedro Antonio Seco de Herrera Gómez
said
over 7 years ago
Hi Lorenzo,
I Have the same problem using the Xamarin plugin. Do you have any solution for this?
Regards
L
Lorenzo
said
over 7 years ago
Ok I got it working, the dealloc wasn't being called because I was referring to 'self' inside a block with a strong reference. What I did was create a weak self with __unsafe_unretained AugmentedRealityViewController *weakSelf = self;
and then inside the various blocks I used weakSelf instead of self, like this:
;
;
Now it works fine
You should update the docs because I took the code from there and with the sdk 5.0 I got this error that is the same error these guys are facing
Lorenzo