Log in or register to post comments

HTC Desire restart in running demo ImageTargets

February 14, 2011 - 7:44pm #1

hi everyone, when i use HTC Desire to run the demo ImageTargets i found a problem,that the phone will die and restart when run the demo app,and the logcat report this,someone can help me? Thanks!

02-15 11:43:00.740: WARN/SharedBufferStack(185): waitForCondition(LockCondition) timed out (identity=3, status=0). CPU may be pegged. trying again.
02-15 11:43:00.780: DEBUG/dalvikvm(704): GC_FOR_MALLOC freed 9065 objects / 490232 bytes in 85ms
02-15 11:43:01.740: WARN/SharedBufferStack(185): waitForCondition(LockCondition) timed out (identity=3, status=0). CPU may be pegged. trying again.
02-15 11:43:02.740: WARN/SharedBufferStack(185): waitForCondition(LockCondition) timed out (identity=3, status=0). CPU may be pegged. trying again.
02-15 11:43:02.760: DEBUG/dalvikvm(672): GC_EXTERNAL_ALLOC freed 797 objects / 45872 bytes in 75ms
02-15 11:43:03.000: DEBUG/TypoClock(672): HTC Alarm Clock does not exists
02-15 11:43:03.000: DEBUG/TypoClock(672): Found Standard Alarm Clock --> com.android.deskclock/com.android.deskclock.AlarmClock
02-15 11:43:03.010: DEBUG/TypoClock(672): Standard Alarm Clock2 does not exists
02-15 11:43:03.010: DEBUG/TypoClock(672): Froyo Nexus Alarm Clock does not exists
02-15 11:43:03.010: DEBUG/TypoClock(672): Moto Blur Alarm Clock does not exists
02-15 11:43:03.740: WARN/SharedBufferStack(185): waitForCondition(LockCondition) timed out (identity=3, status=0). CPU may be pegged. trying again.
02-15 11:43:04.740: WARN/SharedBufferStack(185): waitForCondition(LockCondition) timed out (identity=3, status=0). CPU may be pegged. trying again.
02-15 11:43:05.740: WARN/SharedBufferStack(185): waitForCondition(LockCondition) timed out (identity=3, status=0). CPU may be pegged. trying again.
02-15 11:43:06.740: WARN/SharedBufferStack(185): waitForCondition(LockCondition) timed out (identity=3, status=0). CPU may be pegged. trying again.
02-15 11:43:07.170: ERROR/Adreno200-ES20(1414): gsl_device_waittimestamp failed in rb_timestamp_wait_on_timestamp
02-15 11:43:07.180: ERROR/Adreno200-ES20(185): gsl_device_waittimestamp failed in rb_timestamp_wait_on_timestamp
02-15 11:43:07.690: DEBUG/dalvikvm(704): GC_FOR_MALLOC freed 10823 objects / 569296 bytes in 48ms
02-15 11:43:08.180: WARN/SharedBufferStack(1414): waitForCondition(LockCondition) timed out (identity=29, status=0). CPU may be pegged. trying again.
02-15 11:43:08.190: WARN/SharedBufferStack(185): waitForCondition(LockCondition) timed out (identity=3, status=0). CPU may be pegged. trying again.
02-15 11:43:09.180: WARN/SharedBufferStack(1414): waitForCondition(LockCondition) timed out (identity=29, status=0). CPU may be pegged. trying again.
02-15 11:43:09.190: WARN/SharedBufferStack(185): waitForCondition(LockCondition) timed out (identity=3, status=0). CPU may be pegged. trying again.

Re: HTC Desire restart in running demo ImageTargets

February 21, 2011 - 7:07am #15

This code clears the OpenGL color and depth buffers, at the start of the frame before you do your rendering. In most cases, if you are rendering the video to the background you can probably skip clearing the color buffer. This could cause a problem on devices that use multiple layers for the video instead of rendering it in OpenGL, however. You could try something like this to work across all devices:

if (QCAR::requiresAlpha())
    glClear(GL_COLOR_BUFFER_BIT);

glClear(GL_DEPTH_BUFFER_BIT);

The video background is drawn in the Renderer::begin method, when OpenGL is used to draw it (which is the case on most devices, including yours). Since the video covers the whole screen you do not need to clear the color buffer in this case.

Make sure that you have set the glClearColor before glClear is called:

glClearColor(0.0f, 0.0f, 0.0f, QCAR::requiresAlpha() ? 0.0f : 1.0f);

You need to clear the depth buffer if GL_DEPTH_TEST is enabled, which is typically true if you are rendering 3D objects.

- Kim

Re: HTC Desire restart in running demo ImageTargets

February 21, 2011 - 1:13am #14

what this code use for?

Is necessary for every QCAR app?

Re: HTC Desire restart in running demo ImageTargets

February 21, 2011 - 1:07am #13

ksiva,I had found out the result of the issue that phone crash at startup Imagetargets demo.
when I comment out this code in method Java_com_qualcomm_QCARSamples_Dominoes_DominoesRenderer_renderFrame
of the ImageTargets.cpp the phone is running well.

 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

can you tell me why? Thanks for you help.

Re: HTC Desire restart in running demo ImageTargets

February 18, 2011 - 6:04am #12

If you start with the sample projects, you should be able to change this single line in the Java Activity to change the orientation:

int screenOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;

Be careful when rewriting the initialization code, order is important. You'll want to set the screen orientation before calling QCAR.init().

- Kim

Re: HTC Desire restart in running demo ImageTargets

February 17, 2011 - 6:03pm #11

ksiva , i hava another issue ...
i startup with the config of VideoBackground

	setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    	setActivityPortraitMode(true);

the app is running well.
but i want to change the screen orientation to landscape,so i do this code

setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE );
				  initApplicationNative(800,480);
				 setActivityPortraitMode(false); 
				 stopCamera();
	                startCamera();

i found the VideoBackground turnde 90 degrees clockwise
why it happened??

Re: HTC Desire restart in running demo ImageTargets

February 17, 2011 - 4:41pm #10

ok,when i find it . i will tell you.

Re: HTC Desire restart in running demo ImageTargets

February 17, 2011 - 9:02am #9

So this code works for you, correct? If you wanted to localize the issue you could methodically comment things back in, starting with the OpenGL initialization logic (e.g. creating the textures). I'd be curious to know at what point it breaks.

- Kim

Re: HTC Desire restart in running demo ImageTargets

February 16, 2011 - 8:59pm #8

The version of my os is 2.2 and my phone always connected to the internet.
I comment out all of the initialization code,
This is the ImageTargets.cpp I had edited


JNIEXPORT void JNICALL
Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_setActivityPortraitMode(JNIEnv *, jobject, jboolean isPortrait)
{
		LOG("IN setActivityPortraitMode");
    isActivityInPortraitMode = isPortrait;
    LOG("OUT setActivityPortraitMode");
}

JNIEXPORT int JNICALL
Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargetsRenderer_renderFrame(JNIEnv *, jobject)
{
	   
	if(sflag==1){
		LOG("111111");
	int textureIndex=0;
    //LOG("Java_com_qualcomm_QCARSamples_ImageTargets_GLRenderer_renderFrame");

    // Clear color and depth buffer 
   // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	LOG("222222222");
    // Render video background:
    QCAR::State state = QCAR::Renderer::getInstance().begin();
        	LOG("33333333");

    // Did we find any trackables this frame?
    for(int tIdx = 0; tIdx < state.getNumActiveTrackables(); tIdx++)
    {
        // Get the trackable:
        const QCAR::Trackable* trackable = state.getActiveTrackable(tIdx);
        //QCAR::Matrix44F modelViewMatrix =
          //  QCAR::Tool::convertPose2GLMatrix(trackable->getPose());        

        // Choose the texture based on the target name:
        //textureIndex = (!strcmp(trackable->getName(), "s1")) ? 1 : 2;
        	if(strcmp(trackable->getName(), "ftfm")){
        		textureIndex=1;
        	}
        	if(strcmp(trackable->getName(), "jtfm")){
        		textureIndex=2;
        	}
        	if(strcmp(trackable->getName(), "hb")){
        		textureIndex=3;
        	}
        	
        
		LOG("YOYUYOUOYOYY");
    }


		        	LOG("4444444444");
    QCAR::Renderer::getInstance().end();
    	 LOG("OUT 111 renderFrame");
    	return textureIndex;
	}else{
		 LOG("ELSE IN renderFrame");
		return 0;
	}
	
}



void
configureVideoBackground()
{
    // Get the default video mode:
     LOG("the4");
    QCAR::CameraDevice& cameraDevice = QCAR::CameraDevice::getInstance();
    	 LOG("the5");
    QCAR::VideoMode videoMode = cameraDevice.
                                getVideoMode(QCAR::CameraDevice::MODE_DEFAULT);
 LOG("the6");
    // Configure the video background
    QCAR::VideoBackgroundConfig config;
    config.mEnabled = true;
    config.mSynchronous = true;
    config.mPosition.data[0] = 0.0f;
    config.mPosition.data[1] = 0.0f;
     LOG("the7");
    if (isActivityInPortraitMode)
    {
        //LOG("configureVideoBackground PORTRAIT");
        config.mSize.data[0] = videoMode.mHeight
                                * (screenHeight / (float)videoMode.mWidth);
        config.mSize.data[1] = screenHeight;
    }
    else
    {
        //LOG("configureVideoBackground LANDSCAPE");
        config.mSize.data[0] = screenWidth;
        config.mSize.data[1] = videoMode.mHeight
                            * (screenWidth / (float)videoMode.mWidth);
    }

    // Set the config:
     LOG("the8");
    QCAR::Renderer::getInstance().setVideoBackgroundConfig(config);
    	 LOG("the9");
}


JNIEXPORT void JNICALL
Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_initApplicationNative(
                            JNIEnv* env, jobject obj, jint width, jint height)
{
    LOG("Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_initApplicationNative");
    
    // Store screen dimensions
    screenWidth = width;
    screenHeight = height;
        
    // Handle to the activity class:
   /* jclass activityClass = env->GetObjectClass(obj);

    jmethodID getTextureCountMethodID = env->GetMethodID(activityClass,
                                                    "getTextureCount", "()I");
    if (getTextureCountMethodID == 0)
    {
        LOG("Function getTextureCount() not found.");
        return;
    }

    textureCount = (int) env->CallObjectMethod(obj, getTextureCountMethodID);    
    if (!textureCount)
    {
        LOG("getTextureCount() returned zero.");
        return;
    }

    textures = new Texture*[textureCount];

    jmethodID getTextureMethodID = env->GetMethodID(activityClass,
        "getTexture", "(I)Lcom/qualcomm/QCARSamples/ImageTargets/Texture;");

    if (getTextureMethodID == 0)
    {
        LOG("Function getTexture() not found.");
        return;
    }

    // Register the textures
    for (int i = 0; i < textureCount; ++i)
    {

        jobject textureObject = env->CallObjectMethod(obj, getTextureMethodID, i); 
        if (textureObject == NULL)
        {
            LOG("GetTexture() returned zero pointer");
            return;
        }

        textures[i] = Texture::create(env, textureObject);
    }*/
     LOG("OUT initApplicationNative");
}


JNIEXPORT void JNICALL
Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_deinitApplicationNative(
                                                        JNIEnv* env, jobject obj)
{
    LOG("Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_deinitApplicationNative");
 LOG("in deinitApplicationNative");
    // Release texture resources
    if (textures != 0)
    {    
        for (int i = 0; i < textureCount; ++i)
        {
            delete textures[i];
            textures[i] = NULL;
        }
    
        delete[]textures;
        textures = NULL;
        
        textureCount = 0;
    }
     LOG("out deinitApplicationNative");
}


JNIEXPORT void JNICALL
Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_startCamera(JNIEnv *,
                                                                         jobject)
{
    LOG("Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_startCamera");
		 LOG("in startCamera");
    // Initialize the camera:
    if (!QCAR::CameraDevice::getInstance().init())
        return;

    // Configure the video background
    configureVideoBackground();

    // Select the default mode:
    if (!QCAR::CameraDevice::getInstance().selectVideoMode(
                                QCAR::CameraDevice::MODE_DEFAULT))
        return;

    // Start the camera:
    if (!QCAR::CameraDevice::getInstance().start())
        return;

    // Start the tracker:
    QCAR::Tracker::getInstance().start();
 
    // Cache the projection matrix:
    const QCAR::Tracker& tracker = QCAR::Tracker::getInstance();
    const QCAR::CameraCalibration& cameraCalibration =
                                    tracker.getCameraCalibration();
    //projectionMatrix = QCAR::Tool::getProjectionGL(cameraCalibration, 2.0f,
                           //                 2000.0f);
                                             LOG("out startCamera");
	sflag=1;
}


JNIEXPORT void JNICALL
Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_stopCamera(JNIEnv *,
                                                                   jobject)
{
    LOG("Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_stopCamera");
LOG("in stopCamera");
    QCAR::Tracker::getInstance().stop();

    QCAR::CameraDevice::getInstance().stop();
    QCAR::CameraDevice::getInstance().deinit();
    	sflag=0;
    	LOG("out stopCamera");
}


JNIEXPORT void JNICALL
Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargetsRenderer_initRendering(
                                                    JNIEnv* env, jobject obj)
{
    LOG("Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargetsRenderer_initRendering");
	LOG("in initRendering");
    // Define clear color
  //  glClearColor(0.0f, 0.0f, 0.0f, QCAR::requiresAlpha() ? 0.0f : 1.0f);
    
    // Now generate the OpenGL texture objects and add settings
  /*  for (int i = 0; i < textureCount; ++i)
    {
        glGenTextures(1, &(textures[i]->mTextureID));
        glBindTexture(GL_TEXTURE_2D, textures[i]->mTextureID);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
            glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, textures[i]->mWidth,
                textures[i]->mHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
                (GLvoid*)  textures[i]->mData);
                
    }
#ifndef USE_OPENGL_ES_1_1
  
    shaderProgramID     = SampleUtils::createProgramFromBuffer(cubeMeshVertexShader,
                                                            cubeFragmentShader);

    vertexHandle        = glGetAttribLocation(shaderProgramID,
                                                "vertexPosition");
    normalHandle        = glGetAttribLocation(shaderProgramID,
                                                "vertexNormal");
    textureCoordHandle  = glGetAttribLocation(shaderProgramID,
                                                "vertexTexCoord");
    mvpMatrixHandle     = glGetUniformLocation(shaderProgramID,
                                                "modelViewProjectionMatrix");

#endif */
	LOG("out initRendering");
}


JNIEXPORT void JNICALL
Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargetsRenderer_updateRendering(
                        JNIEnv* env, jobject obj, jint width, jint height)
{
    LOG("Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargetsRenderer_updateRendering");
    LOG("the1");
    // Update screen dimensions
    screenWidth = width;
    screenHeight = height;
 LOG("the2");
    // Reconfigure the video background
    configureVideoBackground();
     LOG("the3");
}


#ifdef __cplusplus
}
#endif

Re: HTC Desire restart in running demo ImageTargets

February 16, 2011 - 10:57am #7

I wish I could tell you how to fix this, we've never been able to reproduce the bug reliably. I only see it once every few weeks, and restarting the device makes it go away completely (I'm also using a HTC Desire).

I find it interesting that commenting out the OpenGL code fixed the issue temporarily... Did you only comment out the rendering code in the renderFrame method, or all of the initialization code as well?

Other questions:

What version of the Android OS is on your device?
Is your device connected to the internet?

- Kim

Re: HTC Desire restart in running demo ImageTargets

February 16, 2011 - 5:08am #6

I tested your method. I set the 5 second delay ,but the nothing change the phone also crash . Is a ar sdk bug??because i use many app are using OpenGL but nerver see to crash.How can fit it?

Re: HTC Desire restart in running demo ImageTargets

February 16, 2011 - 4:45am #5

ksiva,I seems to solve this problem. I comment out all about opengl in the ImageTargets.cpp .After that the app running well and never crash . I don't know why,maybe some opengl initialization make the deadlock.
I will test your method in another demo ---Dominoes which also had the same problem.
and I will tell you the testing result.
thanks for your help!

Re: HTC Desire restart in running demo ImageTargets

February 15, 2011 - 6:25pm #4

You could, but it would be difficult, and you would lose the video background (as it is drawn in OpenGL).

Does it typically crash at startup? If so, I'd like you to try something for me. Open ImageTargets.java, and comment out this line:

mRenderer.mIsActive = true;

Then, open ImageTargetsRenderer.java, and add this to the end of the onSurfaceCreated method:

mIsActive = true;

If that doesn't work, let's add one more step... Instead of setting mIsActive to true in onSurfaceCreated, use this code to delay it a second instead:

public void onSurfaceCreated(GL10 gl, EGLConfig config)
{
    DebugLog.LOGD("GLRenderer::onSurfaceCreated");

    // Call native function to initialize rendering:
    initRendering();
    
    // Call QCAR function to (re)initialize rendering after first use
    // or after OpenGL ES context was lost (e.g. after onPause/onResume):
    QCAR.onSurfaceCreated();
    
    int delay = 1000; // in ms 
    Timer timer = new Timer();
    TimerTask task = new TimerTask() {
    	public void run() {
    		mIsActive = true;
    		this.cancel();
    	}
    };
    timer.schedule(task, delay);
}

Be sure that you've still commented out that other line in ImageTargets.java.

The goal here is to create a bit of delay between OpenGL being ready to render, and it actually rendering. I'm not at all sure if this will help, but please give it a try and let me know how it goes!

- Kim

Re: HTC Desire restart in running demo ImageTargets

February 15, 2011 - 5:46pm #3

hi ksiva,thanks for reply.Yesterday I did'nt sleep until 2 am for fit the issue ,but i failure. I just found this bug is more offen happen when the phone is connected to computer. if i don't use opengl just use the ar sdk to track a image ,can i fix this issue? can i use surfaceView instead of GLSurfaceView?

Re: HTC Desire restart in running demo ImageTargets

February 15, 2011 - 10:11am #2

The CPU Pegged bug is a well-known but little understood issue that plagues many Android applications using OpenGL. I find that it tends to occur most often after using the device for a couple hours, and especially if many applications are running in the background. The best fix is to disconnect the device from your computer, pop out the battery and let it rest for 30 seconds before starting it back up.

Have you seen this issue often? Do you see it after restarting the phone using the above method?

- Kim

Log in or register to post comments