Start a new topic

IOS app crashes when starting AR

IOS app crashes when starting AR

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


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.

For me it worked once.

On the second enter/exit it crashes with the same error for me.

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 !!


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) {

    base.ViewWillDisappear (animated);

    if (_architectView != null) {
        _architectView.Stop ();
        _architectView.RemoveFromSuperview ();
    this.Dispose (true);


protected override void Dispose(bool disposing) {


     if (_architectView != null) {
          _architectView = null;

So not only the RemoveFromSuperview is important, also the overridden Dispose method is important too.

I hope it will work for you.

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


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).


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:

Check failed: !IsGoogleLoggingInitialized() You called InitGoogleLogging() twice!
*** Check failure stack trace: ***
   @        0x1002444b8  google::LogMessage::Flush()
   @        0x1002452d8  google::LogMessageFatal::~LogMessageFatal()
   @        0x100244804  google::LogMessageFatal::~LogMessageFatal()
   @        0x100248954  google::glog_internal_namespace_::InitGoogleLoggingUtilities()
   @        0x100377714  wikitude::common_library::impl::iOSConsoleWriter::iOSConsoleWriter()
   @        0x10019eca8  -
   @        0x10019c0b4  -
   @        0x10019bfac  -
   @        0x100149a38  -
   @        0x188993610  <redacted>
   @        0x1889ab6ec  <redacted>
   @        0x188b3fd68  <redacted>
   @        0x188a4f430  <redacted>
   @        0x188a4f10c  <redacted>
   @        0x188a4f074  <redacted>
   @        0x18898eff0  <redacted>
   @        0x188195f14  <redacted>
   @        0x188190b20  <redacted>
   @        0x1881909e0  <redacted>
   @        0x18819007c  <redacted>
   @        0x18818fdd0  <redacted>
   @        0x1881894bc  <redacted>
   @        0x1833f3c30  <redacted>
   @        0x1833f19d4  <redacted>
   @        0x1833f1e04  <redacted>
   @        0x183320dc0  CFRunLoopRunSpecific
   @        0x18e474088  GSEventRunModal
   @        0x1889faf44  UIApplicationMain
   @        0x100142000  main
   @        0x19885e8b8  <redacted>

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.



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.

One more thing ... on xamarin there is no way for do         


you can only do:

 architectView.Start or architectView.Stop





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 ();

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


I'm sorry but I never used Xamarin and I have no idea how the code works.. sorry

Hi Lorenzo,

I Have the same problem using the Xamarin plugin. Do you have any solution for this?



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
Login or Signup to post a comment