Author Topic: error No free temp registers, and no hide object  (Read 4841 times)

Offline ggp

  • byte
  • *
  • Posts: 39
    • View Profile
error No free temp registers, and no hide object
« on: February 12, 2014, 02:43:02 pm »
show this error in jpct-ae last version

Code: [Select]
02-12 13:34:15.693: E/dalvikvm(370): No free temp registers
02-12 13:34:15.693: E/dalvikvm(370): Jit: aborting trace compilation, reverting to interpreter
02-12 13:34:15.703: E/dalvikvm(370): No free temp registers
02-12 13:34:15.703: E/dalvikvm(370): Jit: aborting trace compilation, reverting to interpreter

and no hide ramp with puss down sphere with function selectAnyObjectAt


here the full code
Code: [Select]
package com.threed.jpct.example;

import java.io.InputStream;
import java.lang.reflect.Field;

import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLDisplay;
import javax.microedition.khronos.opengles.GL10;

import android.app.Activity;
import android.content.res.Resources;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;

import com.threed.jpct.Camera;
import com.threed.jpct.Config;
import com.threed.jpct.FrameBuffer;
import com.threed.jpct.Interact2D;
import com.threed.jpct.Light;
import com.threed.jpct.Loader;
import com.threed.jpct.Logger;
import com.threed.jpct.Matrix;
import com.threed.jpct.Object3D;
import com.threed.jpct.Primitives;
import com.threed.jpct.RGBColor;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.Texture;
import com.threed.jpct.World;
import com.threed.jpct.util.MemoryHelper;

/**
 * A simple demo. This shows more how to use jPCT-AE than it shows how to write
 * a proper application for Android. It includes basic activity management to
 * handle pause and resume...
 *
 * @author EgonOlsen
 *
 */
public class HelloWorld extends Activity {

    // Used to handle pause and resume...
    private static HelloWorld master = null;

    private GLSurfaceView mGLView;
    private MyRenderer renderer = null;
    private FrameBuffer fb = null;
    private World world = null;
    private RGBColor back = new RGBColor(255, 0, 0);

    private float touchTurn = 0;
    private float touchTurnUp = 0;

    private float xpos = -1;
    private float ypos = -1;


    //private int fps = 0;

    private Light sun = null;

    //------------------------
    private Texture font = null;
   
    private float move = 0;
   
    private static final long serialVersionUID = 1L;

    private static final float DAMPING = 0.1f;

    private static final float SPEED = 1f;

    private static final float MAXSPEED = 1f;
   
    private Object3D plane = null;

    private Object3D ramp = null;

    private Object3D cube = null;

    private Object3D cube2 = null;

    private Object3D sphere = null;

    private float dxx;

    private SimpleVector moveRes = new SimpleVector(0, 0, 0);

    private SimpleVector ellipsoid = new SimpleVector(2, 2, 2);
   
    private Camera cam = null;
   
    private Object3D selectedObject = null;
   
    protected void onCreate(Bundle savedInstanceState) {

        Logger.log("onCreate");

        if (master != null) {
            copy(master);
        }

        super.onCreate(savedInstanceState);
        mGLView = new GLSurfaceView(getApplication());

        mGLView.setEGLConfigChooser(new GLSurfaceView.EGLConfigChooser() {
            public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) {
                // Ensure that we get a 16bit framebuffer. Otherwise, we'll fall
                // back to Pixelflinger on some device (read: Samsung I7500)
                int[] attributes = new int[] { EGL10.EGL_DEPTH_SIZE, 16, EGL10.EGL_NONE };
                EGLConfig[] configs = new EGLConfig[1];
                int[] result = new int[1];
                egl.eglChooseConfig(display, attributes, configs, 1, result);
                return configs[0];
            }
        });

        renderer = new MyRenderer();
        mGLView.setRenderer(renderer);
        setContentView(mGLView);
    }

    @Override
    protected void onPause() {
        super.onPause();
        mGLView.onPause();
    }

    @Override
    protected void onResume() {
        super.onResume();
        mGLView.onResume();
    }

    @Override
    protected void onStop() {
        super.onStop();
    }

    private void copy(Object src) {
        try {
            Logger.log("Copying data from master Activity!");
            Field[] fs = src.getClass().getDeclaredFields();
            for (Field f : fs) {
                f.setAccessible(true);
                f.set(this, f.get(src));
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public boolean onTouchEvent(MotionEvent me) {

        if (me.getAction() == MotionEvent.ACTION_DOWN) {
            xpos = me.getX();
            ypos = me.getY();
            return true;
        }

        if (me.getAction() == MotionEvent.ACTION_UP) {
            xpos = -1;
            ypos = -1;
            touchTurn = 0;
            touchTurnUp = 0;
            return true;
        }

        if (me.getAction() == MotionEvent.ACTION_MOVE) {
            float xd = me.getX() - xpos;
            float yd = me.getY() - ypos;

            xpos = me.getX();
            ypos = me.getY();

            touchTurn = xd / -100f;
            touchTurnUp = yd / -100f;
           
            dxx = -xd / -200f;
            cube.rotateY(-dxx);
            return true;
        }

        try {
            Thread.sleep(15);
        } catch (Exception e) {
            // No need for this...
        }

        return super.onTouchEvent(me);
    }
   
    private int selectAnyObjectAt( int mouseX, int mouseY){
        //Camera cam = world.getCamera();
        SimpleVector ray=Interact2D.reproject2D3DWS(cam, fb, mouseX, mouseY).normalize();
        Object[] res = world.calcMinDistanceAndObject3D(cam.getPosition(), ray, 10000F);
        if (res==null || res[1] == null || res[0] == (Object)Object3D.RAY_MISSES_BOX) {
            //Log.d("SELECTION", "You missed! x="+mouseX+" y="+mouseY);   
            selectedObject = null;
            return -1;
        }
        Object3D obj = (Object3D)res[1];
        Log.d("SELECTION", "x="+mouseX+" y="+mouseY+" id2="+obj.getID()+" name="+obj.getName());
        selectedObject = obj;   
       
       
       
        if(obj.getID()==4){   
            if(ramp.getVisibility()==true){
                ramp.setVisibility(false);
               
               
            }else{
                //SoundManager.getInstance().play(SoundManager.COLLECTED);   
                 ramp.setVisibility(true);
                 
            }
         
        }
       
       
        return obj.getID();
    }

    public boolean onKeyDown(int keyCode, KeyEvent msg) {
        if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
            move = 1f;
            return true;
        }

        if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
            move = -1f;
            return true;
        }

        if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
            cube.rotateY((float) Math.toRadians(-1));
            return true;
        }

        if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
            cube.rotateY((float) Math.toRadians(1));
            return true;
        }

       

        return super.onKeyDown(keyCode, msg);
    }
   
    public boolean onKeyUp(int keyCode, KeyEvent msg) {
        if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
            move = 0;
            return true;
        }

        if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
            move = 0;
            return true;
        }

        if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
           
            return true;
        }

        if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
           
            return true;
        }

       

        return super.onKeyUp(keyCode, msg);
    }

   
    protected boolean isFullscreenOpaque() {
        return true;
    }

    class MyRenderer implements GLSurfaceView.Renderer {
        private int fps = 0;
        private int lfps = 0;
       
        private long time = System.currentTimeMillis();
        private boolean stop = false;
        public MyRenderer() {
           
            Config.maxPolysVisible = 500;
             Config.farPlane = 1500;
             Config.glTransparencyMul = 0.1f;
             Config.glTransparencyOffset = 0.1f;
             Config.useVBO=true;
             
             Texture.defaultToMipmapping(false);
             Texture.defaultTo4bpp(true);
        }
        public void stop() {
            stop = true;
        }

        public void onSurfaceChanged(GL10 gl, int w, int h) {
            if (fb != null) {
                fb.dispose();
            }
            fb = new FrameBuffer(gl, w, h);

            if (master == null) {
                Resources res = getResources();
                world = new World();
                world.setAmbientLight(20, 20, 20);

                sun = new Light(world);
                sun.setIntensity(250, 250, 250);
               
                //keyMapper = new KeyMapper(this);
               
                plane = Primitives.getPlane(20, 10);
                plane.rotateX((float) Math.PI / 2f);

                ramp = Primitives.getCube(20);
                ramp.rotateX((float) Math.PI / 2f);

                sphere = Primitives.getSphere(30);
                sphere.translate(-50, 10, 50);

                cube2 = Primitives.getCube(20);
                cube2.translate(60, -20, 60);
               
                cube = loadModel(res.openRawResource(R.raw.flecha), 0.5f);
                //cube = Primitives.getCube(2);
                //cube.rotateY((float) Math.PI / 2f);
                cube.translate(-50, -10, -50);
                cube.setAdditionalColor(RGBColor.GREEN);
                cube.strip();
                cube.build();

                plane.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
                ramp.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
                sphere.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
                cube2.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
                cube.setCollisionMode(Object3D.COLLISION_CHECK_SELF);
                ramp.setVisibility(false);
               
                world.addObject(plane);
                world.addObject(ramp);
                world.addObject(cube);
                world.addObject(sphere);
                world.addObject(cube2);
               
                Light light = new Light(world);
                light.setPosition(new SimpleVector(0, -80, 0));
                light.setIntensity(140, 120, 120);
                light.setAttenuation(-1);

                world.setAmbientLight(20, 20, 20);
               
                cam = world.getCamera();
                cam.moveCamera(Camera.CAMERA_MOVEOUT, 100);
                cam.moveCamera(Camera.CAMERA_MOVEUP, 100);
                cam.lookAt(ramp.getTransformedCenter());
               
                //long start = System.currentTimeMillis();
                //long fps = 0;

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

                if (master == null) {
                    Logger.log("Saving master Activity!");
                    master = HelloWorld.this;
                }
            }
        }
       
        private Object3D loadModel(InputStream filename, float scale) {
            Loader.setVertexOptimization(false);
           
            Object3D[] model = Loader.load3DS(filename, scale);
            Object3D o3d = new Object3D(0);
            Object3D temp = null;

            for (int i = 0; i < model.length; i++) {
                temp = model[i];
                temp.setCenter(SimpleVector.ORIGIN);
                temp.rotateX((float)( -.5*Math.PI));
                temp.rotateY((float)(-Math.PI));
                temp.rotateMesh();
                temp.setRotationMatrix(new Matrix());
                o3d = Object3D.mergeObjects(o3d, temp);
       
            }
            o3d.build();
            return o3d;
    }
        public void onSurfaceCreated(GL10 gl, EGLConfig config) {
        }

        public void onDrawFrame(GL10 gl) {
            try {
               
               
                selectAnyObjectAt((int) xpos, (int) ypos);
               
               
                if (!stop) {
                    //move();
                   
         cam = world.getCamera();
            cam.setPositionToCenter(cube);
            cam.align(cube);
            cam.rotateCameraY(0.0174532925f * 90f);
            cam.rotateCameraX((float) Math.toRadians(30));
            cam.moveCamera(Camera.CAMERA_MOVEOUT, 40);
         
            SimpleVector t = cube.getXAxis();
            t.scalarMul(move);
            moveRes.add(t);
           
            // avoid high speeds
            if (moveRes.length() > MAXSPEED) {
                moveRes.makeEqualLength(new SimpleVector(0, 0, MAXSPEED));
            }

            cube.translate(0, -0.02f, 0);

            moveRes = cube.checkForCollisionEllipsoid(moveRes, ellipsoid, 8);
            cube.translate(moveRes);

            // finally apply the gravity:
            //SimpleVector t = cube.getZAxis();
            SimpleVector tt = new SimpleVector(0, 1, 0);
            tt = cube.checkForCollisionEllipsoid(tt, ellipsoid, 1);
            cube.translate(tt);

            // damping
            if (moveRes.length() > DAMPING) {
                moveRes.makeEqualLength(new SimpleVector(0, 0, DAMPING));
            } else {
                moveRes = new SimpleVector(0, 0, 0);
            }
             
           
           
            fb.clear(back);
            world.renderScene(fb);
            world.draw(fb);
            blitNumber(lfps, 5, 5);
           
            fb.display();
           
           
            if (System.currentTimeMillis() - time >= 1000) {
                Logger.log(fps + "fps");
                lfps = fps;
                fps = 0;
                time = System.currentTimeMillis();
            }
            fps++;
                } else {
                    if (fb != null) {
                        fb.dispose();
                        fb = null;
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
                Logger.log("Drawing thread terminated!", Logger.MESSAGE);
            }
        }
       
        private void blitNumber(int number, int x, int y) {
            if (font != null) {
                String sNum = Integer.toString(number);

                for (int i = 0; i < sNum.length(); i++) {
                    char cNum = sNum.charAt(i);
                    int iNum = cNum - 48;
                    fb.blit(font, iNum * 5, 0, x, y, 5, 9, FrameBuffer.TRANSPARENT_BLITTING);
                    x += 5;
                }
            }
        }
    }
}



« Last Edit: February 12, 2014, 02:59:05 pm by ggp »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: error No free temp registers, and no hide object
« Reply #1 on: February 12, 2014, 04:38:13 pm »
The first issue is none: https://code.google.com/p/android/issues/detail?id=18647

And for the second one...i don't get the actual question... ???

Offline ggp

  • byte
  • *
  • Posts: 39
    • View Profile
Re: error No free temp registers, and no hide object
« Reply #2 on: February 12, 2014, 04:52:36 pm »
is easy

-touch sphere   obj ID= 4
   show ramp
-touch sphere
   hide  ramp
-touch sphere 
   show ramp
...

no working!
why??

Code: [Select]

private int selectAnyObjectAt( int mouseX, int mouseY){
        //Camera cam = world.getCamera();
        SimpleVector ray=Interact2D.reproject2D3DWS(cam, fb, mouseX, mouseY).normalize();
        Object[] res = world.calcMinDistanceAndObject3D(cam.getPosition(), ray, 10000F);
        if (res==null || res[1] == null || res[0] == (Object)Object3D.RAY_MISSES_BOX) {
            //Log.d("SELECTION", "You missed! x="+mouseX+" y="+mouseY);   
            selectedObject = null;
            return -1;
        }
        Object3D obj = (Object3D)res[1];
        Log.d("SELECTION", "x="+mouseX+" y="+mouseY+" id2="+obj.getID()+" name="+obj.getName());
        selectedObject = obj;   
       
       
       
        if(obj.getID()==4){   
            if(ramp.getVisibility()==true){
                ramp.setVisibility(false);
               
               
            }else{
                //SoundManager.getInstance().play(SoundManager.COLLECTED);   
                 ramp.setVisibility(true);
                 
            }
         
        }
       
       
        return obj.getID();
    }


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: error No free temp registers, and no hide object
« Reply #3 on: February 12, 2014, 05:04:17 pm »
Maybe you should add some debug output...are you sure that the sphere has id 4?

Offline ggp

  • byte
  • *
  • Posts: 39
    • View Profile
Re: error No free temp registers, and no hide object
« Reply #4 on: February 12, 2014, 05:30:54 pm »
Ok Thank you

sphere Object4 is ID=2 ::)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: error No free temp registers, and no hide object
« Reply #5 on: February 12, 2014, 05:34:32 pm »
 :)

You shouldn't hard code these ids. Always obtain them from the object itself, because future initializations of the Activity can lead to different ids.