Log in or register to post comments

Crash on Kindle Fire HD

August 10, 2013 - 6:58pm #1

Hi,

I'm running Unity 3.5.7f6 and the Vuforia plugin v2.5.8, and getting a crash that only seems to affect the Kindle Fire HD.

I'm using the QCARViewFinderTask code found here: https://developer.vuforia.com/resources/dev-guide/extending-unity-android-activity-and-adding-custom-views-eclipse to add Android UI elements to the QCARPlayerActivity

This works well and the AR Activity loads and runs without a hitch on an HTC One (Android 4.2.2), an HTC Desire HD (Android 2.3.7) and a Nexus 7 (Android 4.0.3), but on the Kindle Fire HD 7" (OS 7.4.6) the activity crashes.

Stepping through the code, it appears that qcarView in line 33 is getting set to null in findQCARView().

Looking at the children of rootView, there is only one, and it is a LinearLayout, whereas on the other devices, the only child is a QCARUnityPlayer (as it should be)

Does anyone know of any reason why this would be happening only on this one device, or any workarounds to this issue?

 

Thanks for your help

 

Crash on Kindle Fire HD

August 13, 2013 - 10:44am #16

Well, glad to see it is voled in the end.

Crash on Kindle Fire HD

August 13, 2013 - 10:04am #15

So, after all that, the problem was to do with Flurry.

I wasn't using the correct context to set up the session for that activity. Was using 

FlurryAgent.onStartSession(this, <id>);

instead of 

FlurryAgent.onStartSession(ARActivity.this, <id>);

Gaah!

 

Crash on Kindle Fire HD

August 13, 2013 - 8:09am #14

I'll try that when I have some more free time. I'm just going to tell the client that the Kindle can't run this complex an AR app for the moment.

I'm thinking it might have as much to do with Amazon's proprietary implementation of Android as anything else. Maybe they do something weird when setting up view heirarchies.

 

Thanks for all your help - hope I wasn't too annoying!

 

Crash on Kindle Fire HD

August 13, 2013 - 7:14am #13

Yes, the last implementation looks correct;  

if you still see the issue, then there must be something else going wrong in the project; have you tried implementing the same technique starting from a fresh new Vuforia sample like ImageTargets or Frame Markers ? 

Crash on Kindle Fire HD

August 13, 2013 - 5:54am #12

Ok, this time I think I got it.

 

	public void onResume() {
		super.onResume();
		if (mQCARView == null) {
			// search the QCAR view

			handler.postDelayed(new QCARViewFinderTask(), 1000);

		}
	}

 

handler posts on the UI thread in onResume;

and

	class QCARViewFinderTask implements Runnable {

		@Override
		public void run() {
			if (!QCAR.isInitialized())
				return; // wait for QCAR init
			if (mQCARView != null)
				return;// already found, no need to search
			// else search
			View rootView = ARActivity.this.findViewById(android.R.id.content);
			QCARUnityPlayer qcarView = findQCARView(rootView);
			// if QCAR view has been found, add some android view/widget on top
			if (qcarView != null) {
				...

			}
		}

the search is run in a Runnable.

 

Still same symptoms - HTC One is fine, Kindle finds no qcarView

Crash on Kindle Fire HD

August 13, 2013 - 5:07am #11

No, what I mean is:

- do not use the Thread class (and if you have now removed it, that's fine)

- use the Handler and remove the Timer / TimerTask 

In your latest code you are using the Handler inside the TimerTask; this is not correct (just get rid of the TimerTask)

In the prvious version of your code, you were using the Thread class for some reasons (do not use the Thread class).

 

Crash on Kindle Fire HD

August 13, 2013 - 4:58am #10

Sorry I misinterpreted - I thought you meant remove the Timer stuff completely when implementing the Handler.

 

So now I have,

 

	public void onResume() {
		super.onResume();
		if (mQCARView == null) {
			// search the QCAR view
			viewFinderTimer = new Timer();
			viewFinderTimer.scheduleAtFixedRate(new QCARViewFinderTask(), 1000l, 1000l);
			
		}
	}

and 

	class QCARViewFinderTask extends TimerTask {
		@Override
		public void run() {
			handler.postDelayed(new Runnable() {
				
				@Override
				public void run() {
					if (!QCAR.isInitialized())
						return; // wait for QCAR init
					if (mQCARView != null)
						return;// already found, no need to search
					// else search
					View rootView = ARActivity.this.findViewById(android.R.id.content);
					QCARUnityPlayer qcarView = findQCARView(rootView);
					// if QCAR view has been found, add some android view/widget on top
					if (qcarView != null) {

						...

					}
				}
			}, 1000);
		}

 

and I still have the same symptoms - runs fine on HTC One, but fails on Kindle with no QCarUnityPlayer child.

Crash on Kindle Fire HD

August 13, 2013 - 4:40am #9

Ok, thanks for sharing the code; actually the problem is that you are using the Thread class:

new Thread(new QCARViewFinderTask()).start();

if you check the tutorial implementation, we use a Timer and a TimerTask; a Handler is also possible; but in any case, you should avoid using the Thread class, as this will create synchronization problems with the UI.

 

Crash on Kindle Fire HD

August 13, 2013 - 4:17am #8

Implementing with postDelayed doesn't seem to make a difference, even with a delay of 10s.

 

Maybe it's my implementation.

 

I'm instatiating the handler in onCreate()

handler = new Handler();

 

calling the task in onResume()

if (mQCARView == null) {
    // search the QCAR view
    //viewFinderTimer = new Timer();
    //viewFinderTimer.scheduleAtFixedRate(new QCARViewFinderTask(), 100l, 1000l);
    new Thread(new QCARViewFinderTask()).start();
}

 

 
and this is the task:
 
class QCARViewFinderTask implements Runnable {
   @Override
   public void run() {
   //ARActivity.this.runOnUiThread(new Runnable() {
   handler.postDelayed(new Runnable() {

      @Override
      public void run() {
         if (!QCAR.isInitialized())
            return; // wait for QCAR init
         if (mQCARView != null)
            return;// already found, no need to search
         // else search
         View rootView = ARActivity.this.findViewById(android.R.id.content);
         QCARUnityPlayer qcarView = findQCARView(rootView);
         // if QCAR view has been found, add some android view/widget on top
         if (qcarView != null) {
            ...
         }
      }
   }, 10000);
}

 

Is that what you envisaged? Sorry, I've only ever used AsyncTask for thread stuff.
Anyway, when I run that on the Kindle, qcarView always comes back null, and the rootView doesn't contain a QCARUnityPlayer anywhere in its heirarchy.

 

Crash on Kindle Fire HD

August 13, 2013 - 12:54am #7

The logs indicate a threading issue; basically the app is trying to modify the view hierarchy from the wrong thread;

my guess here is that the use of the TimerTask and Timer is causing the issue; 

I would suggest to try the Handler approach (as I previously suggested), using the postDelayed() method; also, when you use the Handler, make sure to create the Handler in the main UI thread, for instance create it inside the onCreate() or the onResume() methods of the main activity.

Also, if using a Handler which has been created in the main UI thread, you will not need to use the runOnUIThread() method, which is shown in the tutorial.

If approproately implemented, this should resolve the threading issue.

Crash on Kindle Fire HD

August 12, 2013 - 5:55pm #6

Actually, I spoke too soon.

Even after reducing the number of models to get rid of the out of memory crash, the Eclipse modified app still crashes on the Kindle - so the initial problem I posted about is still there.

I tried your suggestion of using a Handler, but it made no difference.

All the info in my initial post is still relevant, but I never posted the actual error from Logcat.

Here it is, if it helps:

08-13 01:52:24.554: W/dalvikvm(9588): threadid=12: thread exiting with uncaught exception (group=0x40b011f8)
08-13 01:52:24.554: W/System.err(9588): android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
08-13 01:52:24.554: W/System.err(9588): at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:4062)
08-13 01:52:24.554: W/System.err(9588): at android.view.ViewRootImpl.invalidateChild(ViewRootImpl.java:730)
08-13 01:52:24.554: W/System.err(9588): at android.view.ViewRootImpl.invalidateChildInParent(ViewRootImpl.java:779)
08-13 01:52:24.554: W/System.err(9588): at android.view.ViewGroup.invalidateChild(ViewGroup.java:4005)
08-13 01:52:24.554: W/System.err(9588): at android.view.View.invalidate(View.java:8605)
08-13 01:52:24.554: W/System.err(9588): at android.view.View.invalidate(View.java:8556)
08-13 01:52:24.554: W/System.err(9588): at android.widget.ImageView.invalidateDrawable(ImageView.java:189)
08-13 01:52:24.554: W/System.err(9588): at android.graphics.drawable.Drawable.invalidateSelf(Drawable.java:350)
08-13 01:52:24.554: W/System.err(9588): at android.graphics.drawable.Drawable.setVisible(Drawable.java:548)
08-13 01:52:24.554: W/System.err(9588): at android.widget.ImageView.onDetachedFromWindow(ImageView.java:1060)
08-13 01:52:24.554: W/System.err(9588): at android.view.View.dispatchDetachedFromWindow(View.java:9847)
08-13 01:52:24.554: W/System.err(9588): at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2266)
08-13 01:52:24.554: W/System.err(9588): at android.view.ViewGroup.removeAllViewsInLayout(ViewGroup.java:3717)
08-13 01:52:24.554: W/System.err(9588): at android.view.ViewGroup.removeAllViews(ViewGroup.java:3672)
08-13 01:52:24.554: W/System.err(9588): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:285)
08-13 01:52:24.554: W/System.err(9588): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:277)
08-13 01:52:24.554: W/System.err(9588): at android.app.Activity.setContentView(Activity.java:1901)
08-13 01:52:24.554: W/System.err(9588): at com.qualcomm.QCARUnityPlayer.QCARPlayerSharedActivity.initUnityPlayer(QCARPlayerSharedActivity.java:584)
08-13 01:52:24.554: W/System.err(9588): at com.qualcomm.QCARUnityPlayer.QCARPlayerSharedActivity.access$300(QCARPlayerSharedActivity.java:40)
08-13 01:52:24.554: W/System.err(9588): at com.qualcomm.QCARUnityPlayer.QCARPlayerSharedActivity$InitUnityTask.onPostExecute(QCARPlayerSharedActivity.java:189)
08-13 01:52:24.554: W/System.err(9588): at com.qualcomm.QCARUnityPlayer.QCARPlayerSharedActivity$InitUnityTask.onPostExecute(QCARPlayerSharedActivity.java:178)
08-13 01:52:24.554: W/System.err(9588): at android.os.AsyncTask.finish(AsyncTask.java:602)
08-13 01:52:24.554: W/System.err(9588): at android.os.AsyncTask.access$600(AsyncTask.java:156)
08-13 01:52:24.554: W/System.err(9588): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:615)
08-13 01:52:24.554: W/System.err(9588): at android.os.Handler.dispatchMessage(Handler.java:99)
08-13 01:52:24.554: W/System.err(9588): at android.os.Looper.loop(Looper.java:137)
08-13 01:52:24.554: W/System.err(9588): at android.os.HandlerThread.run(HandlerThread.java:60)
 
 
In between times I upgraded the Vuforia plugin to v2.6.7, so those line numbers are from that version.
 

Crash on Kindle Fire HD

August 12, 2013 - 8:54am #5

Of course, that was the question I should have asked myself before asking the forum :)

I just installed the Frame Markers sample, and it worked perfectly well.

Playing around with my project a bit more, I removed a frame marker from the scene (there are 3 frame markers and each has 2 or 3 complex animated models that are set to active/inactive through on-screen buttons) and the app ran the way it should. So it looks like it's definitely a memory resource issue.

Thanks for your help anyway!

Crash on Kindle Fire HD

August 11, 2013 - 11:20pm #4

Do you see such a problem with our samples too ? or just on your custom application ?

 

Crash on Kindle Fire HD

August 11, 2013 - 5:37pm #3
Hi Alessandro,
 
Thanks for the quick reply!
I was looking further into this and discovered that even the initial apk that is generated from the Unity build process doesn't run on the Kindle.
It's initialising QCAR, creating and finding the markers, starting QCAR and then crashing after that.
Logcat snippet at crash point below. 
 
08-11 22:42:54.665: E/dalvikvm(12225): Thread creation failed (err=Out of memory)
08-11 22:42:54.665: E/dalvikvm(12225): JNI ERROR (app bug): accessed stale local reference 0x1d400031 (index 12 in a table of size 11)
08-11 22:42:54.665: E/dalvikvm(12225): VM aborting
08-11 22:42:54.665: A/libc(12225): Fatal signal 11 (SIGSEGV) at 0xdeadd00d (code=1)
08-11 22:42:55.165: I/DEBUG(108): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
08-11 22:42:55.165: I/DEBUG(108): Build fingerprint: 'Android/tate/tate:4.0.3/IML74K/7.4.6_user_4620220:user/release-keys'
08-11 22:42:55.165: I/DEBUG(108): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr deadd00d
 

Would the device really be running out of memory? It has 1GB of RAM, same as the Nexus 7 and more than the HTC Desire HD (768MB) 

Thanks

Jase

Crash on Kindle Fire HD

August 11, 2013 - 10:50am #2

That's a bit weird; the only thing I can think of is a threading issue; 

one thing you could try to use a Handler (use the post() method) instead of the Timer, so to execute the view search with some delay, see :

http://developer.android.com/reference/android/os/Handler.html

 

Log in or register to post comments