Inquiry of JPCT + QCAR

Started by teal03, August 26, 2013, 12:01:10 PM

Previous topic - Next topic

teal03

hello~ i'm student of android development.  I have some problem when i integrated the JPCT and QCAR.
I refer your expaination in wiki which name is  Integrating JPCT-AE with Vuforia.
so i followed your sample code. but some problem occur in part of texture.
If i remove this code (texture part)


Texture texture = new Texture(BitmapHelper.rescale(BitmapHelper.convert(mActivity.getResources().getDrawable(R.drawable.markman)), 64, 64));
TextureManager.getInstance().addTexture("texture", texture);


the program is worked without texture.
However, if I insert texture code the program isn't worked!!
I don't know how can i solve this problem. please help me :)
I attach the logcat and my code
thank you for your attention.

error below

08-26 18:59:17.099: D/dalvikvm(6180): GC_FOR_ALLOC freed 72K, 13% free 9596K/10951K, paused 15ms, total 16ms
08-26 18:59:17.099: I/dalvikvm-heap(6180): Grow heap (frag case) to 11.319MB for 775696-byte allocation
08-26 18:59:17.129: D/dalvikvm(6180): GC_CONCURRENT freed 1K, 12% free 10352K/11719K, paused 11ms+1ms, total 31ms
08-26 18:59:19.344: E/SpannableStringBuilder(6180): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
08-26 18:59:19.344: E/SpannableStringBuilder(6180): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
08-26 18:59:21.684: D/dalvikvm(6180): Trying to load lib /data/data/com.qualcomm.QCARSamples.ImageTargets/lib/libQCAR.so 0x41bea720
08-26 18:59:21.689: D/dalvikvm(6180): Added shared lib /data/data/com.qualcomm.QCARSamples.ImageTargets/lib/libQCAR.so 0x41bea720
08-26 18:59:21.694: I/QCAR(6180): Native library libQCAR.so loaded
08-26 18:59:21.699: D/dalvikvm(6180): Trying to load lib /data/data/com.qualcomm.QCARSamples.ImageTargets/lib/libImageTargets.so 0x41bea720
08-26 18:59:21.699: D/dalvikvm(6180): Added shared lib /data/data/com.qualcomm.QCARSamples.ImageTargets/lib/libImageTargets.so 0x41bea720
08-26 18:59:21.699: D/dalvikvm(6180): No JNI_OnLoad found in /data/data/com.qualcomm.QCARSamples.ImageTargets/lib/libImageTargets.so 0x41bea720, skipping init
08-26 18:59:21.699: I/QCAR(6180): Native library libImageTargets.so loaded
08-26 18:59:21.699: D/QCAR(6180): ImageTargets::onCreate
08-26 18:59:21.714: D/dalvikvm(6180): GC_FOR_ALLOC freed 57K, 12% free 10540K/11847K, paused 14ms, total 14ms
08-26 18:59:21.744: D/dalvikvm(6180): GC_FOR_ALLOC freed 17K, 12% free 10779K/12167K, paused 16ms, total 16ms
08-26 18:59:21.759: D/dalvikvm(6180): GC_FOR_ALLOC freed 0K, 12% free 11035K/12487K, paused 11ms, total 11ms
08-26 18:59:21.784: D/dalvikvm(6180): GC_FOR_ALLOC freed 520K, 16% free 10795K/12807K, paused 11ms, total 11ms
08-26 18:59:21.804: D/dalvikvm(6180): GC_FOR_ALLOC freed 16K, 14% free 11035K/12807K, paused 11ms, total 11ms
08-26 18:59:21.819: D/dalvikvm(6180): GC_FOR_ALLOC freed 0K, 12% free 11291K/12807K, paused 12ms, total 12ms
08-26 18:59:21.844: D/dalvikvm(6180): GC_FOR_ALLOC freed 520K, 16% free 11052K/13127K, paused 11ms, total 12ms
08-26 18:59:21.879: D/dalvikvm(6180): GC_CONCURRENT freed 16K, 13% free 11548K/13127K, paused 12ms+2ms, total 24ms
08-26 18:59:21.879: D/dalvikvm(6180): WAIT_FOR_CONCURRENT_GC blocked 1ms
08-26 18:59:21.894: I/QCAR(6180): Activity is in PORTRAIT
08-26 18:59:21.899: D/QCAR(6180): ImageTargets::onResume
08-26 18:59:21.904: I/AR(6180): QCAR has been initialized successfully
08-26 18:59:21.904: I/AR(6180): QCAR SDK version 2.0.31
08-26 18:59:22.004: E/SpannableStringBuilder(6180): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
08-26 18:59:22.004: E/SpannableStringBuilder(6180): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
08-26 18:59:22.014: D/QCAR(6180): InitQCARTask::onPostExecute: QCAR initialization successful
08-26 18:59:22.019: I/QCAR(6180): Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_initTracker
08-26 18:59:22.029: I/QCAR(6180): Successfully initialized ImageTracker.
08-26 18:59:22.029: I/QCAR(6180): Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_initApplicationNative
08-26 18:59:22.029: I/QCAR(6180): Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_initApplicationNative finished
08-26 18:59:22.034: I/QCAR(6180): Using OpenGL ES 2.0
08-26 18:59:22.034: I/QCAR(6180): Using opaque GLView, depth buffer size: 16, stencil size: 0
08-26 18:59:22.039: I/jPCT-AE(6180): Adding Lightsource: 0
08-26 18:59:22.039: D/AndroidRuntime(6180): Shutting down VM
08-26 18:59:22.039: W/dalvikvm(6180): threadid=1: thread exiting with uncaught exception (group=0x411852a0)
08-26 18:59:22.044: E/AndroidRuntime(6180): FATAL EXCEPTION: main
08-26 18:59:22.044: E/AndroidRuntime(6180): java.lang.NullPointerException
08-26 18:59:22.044: E/AndroidRuntime(6180): at com.qualcomm.QCARSamples.ImageTargets.ImageTargetsRenderer.<init>(ImageTargetsRenderer.java:64)
08-26 18:59:22.044: E/AndroidRuntime(6180): at com.qualcomm.QCARSamples.ImageTargets.ImageTargets.initApplicationAR(ImageTargets.java:806)
08-26 18:59:22.044: E/AndroidRuntime(6180): at com.qualcomm.QCARSamples.ImageTargets.ImageTargets.updateApplicationStatus(ImageTargets.java:648)
08-26 18:59:22.044: E/AndroidRuntime(6180): at com.qualcomm.QCARSamples.ImageTargets.ImageTargets.updateApplicationStatus(ImageTargets.java:640)
08-26 18:59:22.044: E/AndroidRuntime(6180): at com.qualcomm.QCARSamples.ImageTargets.ImageTargets.access$3(ImageTargets.java:597)
08-26 18:59:22.044: E/AndroidRuntime(6180): at com.qualcomm.QCARSamples.ImageTargets.ImageTargets$InitQCARTask.onPostExecute(ImageTargets.java:225)
08-26 18:59:22.044: E/AndroidRuntime(6180): at com.qualcomm.QCARSamples.ImageTargets.ImageTargets$InitQCARTask.onPostExecute(ImageTargets.java:1)
08-26 18:59:22.044: E/AndroidRuntime(6180): at android.os.AsyncTask.finish(AsyncTask.java:631)
08-26 18:59:22.044: E/AndroidRuntime(6180): at android.os.AsyncTask.access$600(AsyncTask.java:177)
08-26 18:59:22.044: E/AndroidRuntime(6180): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
08-26 18:59:22.044: E/AndroidRuntime(6180): at android.os.Handler.dispatchMessage(Handler.java:99)
08-26 18:59:22.044: E/AndroidRuntime(6180): at android.os.Looper.loop(Looper.java:137)
08-26 18:59:22.044: E/AndroidRuntime(6180): at android.app.ActivityThread.main(ActivityThread.java:4921)
08-26 18:59:22.044: E/AndroidRuntime(6180): at java.lang.reflect.Method.invokeNative(Native Method)
08-26 18:59:22.044: E/AndroidRuntime(6180): at java.lang.reflect.Method.invoke(Method.java:511)
08-26 18:59:22.044: E/AndroidRuntime(6180): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
08-26 18:59:22.044: E/AndroidRuntime(6180): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
08-26 18:59:22.044: E/AndroidRuntime(6180): at dalvik.system.NativeStart.main(Native Method)




my code below


/** The renderer class for the ImageTargets sample. */
public class ImageTargetsRenderer implements GLSurfaceView.Renderer
{
    public boolean mIsActive = false;
   
    private FrameBuffer fb = null;
private World world = null;
private Light sun = null;
private Object3D obj = null;

    /** Reference to main activity **/
    public ImageTargets mActivity;

    /** Native function for initializing the renderer. */
    public native void initRendering();

    /** Native function to update the renderer. */
    public native void updateRendering(int width, int height);
   
   
    public ImageTargetsRenderer(ImageTargets activity) {
    this.mActivity = activity;
    world = new World();
    world.setAmbientLight(20, 20, 20);
   
    sun = new Light(world);
    sun.setIntensity(250, 250, 250);
   
    // Create a texture out of the icon...:-)
    Texture texture = new Texture(BitmapHelper.rescale(BitmapHelper.convert(mActivity.getResources().getDrawable(R.drawable.markman)), 64,

64));
TextureManager.getInstance().addTexture("texture", texture);

    //obj = Object3D.mergeAll(Loader.loadOBJ(mActivitygetResources().openRawResource(R.raw.mark_obj), getResources().openRawResource

(R.raw.mark_mtl), 25));
   
    obj = Primitives.getCube(10);
    obj.calcTextureWrapSpherical();
   
    obj.setTexture("texture");
    obj.strip();
    obj.build();

    world.addObject(obj);

        Camera cam = world.getCamera();
        cam.moveCamera(Camera.CAMERA_MOVEOUT, 50);
        cam.lookAt(obj.getTransformedCenter());

    SimpleVector sv = new SimpleVector();
    sv.set(obj.getTransformedCenter());
    sv.y -= 100;
    sv.z -= 100;
    sun.setPosition(sv);
    MemoryHelper.compact();


    }


    /** Called when the surface is created or recreated. */
    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();
    }


    /** Called when the surface changed size. */
    public void onSurfaceChanged(GL10 gl, int width, int height)
    {
        DebugLog.LOGD("GLRenderer::onSurfaceChanged");
        updateRendering(width, height);
        QCAR.onSurfaceChanged(width, height);
       
        if (fb != null) {
            fb.dispose();
       }
       fb = new FrameBuffer(width, height);
    }


    /** The native render function. */
    public native void renderFrame();


    /** Called to draw the current frame. */
    public void onDrawFrame(GL10 gl)
    {
world.renderScene(fb);
world.draw(fb);
fb.display();

        if (!mIsActive)
            return;     
        mActivity.updateRenderView();
        renderFrame();
    }
    }

EgonOlsen

Something is null in that line, just like the exception says. This isn't a problem of the engine, it's something your way to setup things that wrong. Check if mActivity or mActivity.getResources() is null.

teal03

#2
thank you. you said something is null?? so I found some different part. in lecture handles just ImageTargetsRenderer.java.
But I have error in ImageTargets.java when i first wrote your sample code.(not in ImageTargetsRenderer.java)

that part is here and i changed and then error was removed so i could build. but still i can't apply texture  :-\
mRenderer = new ImageTargetsRenderer();     --->      mRenderer = new ImageTargetsRenderer(null);


In here, is there something wrong?

teal03

oh!!!!!! great!! I solved my problem
thank you your comments!!!
I just chage like this.
your comments is very helpful for me. i could get hint in your advice..


mRenderer = new ImageTargetsRenderer();     --->      mRenderer = new ImageTargetsRenderer(this);


thank you again.