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
over 8 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).
P
Pedro Antonio Seco de Herrera Gómez
said
over 8 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
over 8 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.
A
Andreas Schacherbauer
said
about 8 years ago
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
L
Lorenzo
said
over 8 years ago
I've implemented the Wikitude SDK in my app in order to display my Wikitude Studio content inside my app. Everything works fine except for a thing, if I start the AR class then I go back to the home screen and finally I restart the AR the app crashes. The crash occurs when calling: self.architectView = ;
Does anyone know why does it happen and how to fix it?
Thanks
N
Nicola Radacher
said
over 8 years ago
Hi Lorenzo,
Can you please over further details on the crash (crash log, stack trace) so we know the reason for the crash.
Thx and greetings
Nicola
L
Lorenzo
said
over 8 years ago
This is the error log:
F1020 14:23:49.317847 2670616576 utilities.cc:320> Check failed: !IsGoogleLoggingInitialized() You called InitGoogleLogging() twice!
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
P
Pedro Antonio Seco de Herrera Gómez
said
over 8 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 !!
A
Alexey Volkov
said
about 8 years ago
For me it worked once.
On the second enter/exit it crashes with the same error for me.
F
Frank Ortner
said
about 8 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.
P
Pedro Antonio Seco de Herrera Gómez
said
over 8 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 8 years ago
I'm sorry but I never used Xamarin and I have no idea how the code works.. sorry
A
Andreas Schacherbauer
said
over 8 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.
Lorenzo