Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

11991 Posts in 1587 Topics- by 3509 Members - Latest Member: lioneltenel

27. May 2012, 02:30:50 am
Xith3D CommunityGeneral CategorySupport (Moderator: Marvin Fröhlich)JVM Crash
Pages: [1]
Print
Author Topic: JVM Crash  (Read 1029 times)
badboyboogey
Enjoying the stay
*
Offline Offline

Posts: 40



View Profile
« on: 16. December 2007, 12:48:06 pm »

Hi i keep getting a JVM crash when a moving object comes close to the view or when i add a HUD class, Happens all the time with JOGL_AWT and sometimes but not often with JOGL_SWING (but this is 10 times slower than JOGL_AWT else would just use that),
LWJGL doesn't work at all just stops responding after first frame is drawn.

JVM hs_err log points out native library as cause :-

Has anyone else had this problem?
Can post log file if will help? (should i report this as bug to sun?)

thanx John
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #1 on: 16. December 2007, 01:39:19 pm »

Hmmm. Since LWJGL isn't working at all, I would suspect, that there's something wrong on your machine. Do you have the latest drivers installed? What's your system config?

I have never gotten this crash. I guess, it would help to post a simple testcase, where this happens for you. Then we can try to run it on our machines.

Marvin
Logged
badboyboogey
Enjoying the stay
*
Offline Offline

Posts: 40



View Profile
« Reply #2 on: 16. December 2007, 02:03:03 pm »

Figured out it happens only when i use several renderlayers, if i use background node instead it does'nt happen, although don't think i can achieve everything i want with background.(I'll post another question to clipping thread about background:) )
Started out ok but as i added more and more to the scene and got things moving round it gradually got worse and worse.
Going to run a few more tests and see if i can pin it down to something more specific.
Logged
badboyboogey
Enjoying the stay
*
Offline Offline

Posts: 40



View Profile
« Reply #3 on: 16. December 2007, 02:58:14 pm »

Rite think it happens when i remove a Group from a "layer" and add it to the next closest, the shape3D attached to the Group is also changed for a more detailed 1 between removing and adding. Don't think it's actually anything todo with object coming close to the view, just looks that way because this is when object is moved.
Don't know why HUD makes it crash tho, have removed all other branchgraphs except 1 and HUD and it still crashes.

Yep got latest drivers tried that first Smiley
comp specs:-
Amd 1700xp (1.5ghz)
1024 mb ram
GFX card:- Geforce 6200 256mb
windows xp sp2

LWJGL has always hung even when trying out simple tutorials.

John
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #4 on: 16. December 2007, 06:04:44 pm »

Rite think it happens when i remove a Group from a "layer" and add it to the next closest, the shape3D attached to the Group is also changed for a more detailed 1 between removing and adding. Don't think it's actually anything todo with object coming close to the view, just looks that way because this is when object is moved.
Don't know why HUD makes it crash tho, have removed all other branchgraphs except 1 and HUD and it still crashes.

By "layer" you mean RenderPass, I suspect, right?

Could you please setup a small testcase? I would really like to fix this bug. But I never get this kind of behavior when I try to reproduce it.

Marvin
Logged
badboyboogey
Enjoying the stay
*
Offline Offline

Posts: 40



View Profile
« Reply #5 on: 16. December 2007, 07:31:47 pm »

Have done a test case but not that small lol, Ive tried to consolidate evrything i was doing into one class file.. i couldn't replicate the problem at first evrything worked ok!!!.... then i decided to add a texture << there we go something todo with multipass and textures.

Code:
import java.util.Enumeration;
import java.util.Hashtable;
import net.jtank.input.*;
import org.openmali.vecmath2.*;
import org.xith3d.base.Xith3DEnvironment;
import org.xith3d.loaders.texture.*;
import org.xith3d.loop.*;
import org.xith3d.render.*;
import org.xith3d.render.config.*;
import org.xith3d.scenegraph.*;
import org.xith3d.scenegraph.primitives.*;
import org.xith3d.ui.hud.HUD;
import org.xith3d.ui.hud.listeners.ButtonListener;
import org.xith3d.ui.hud.widgets.Button;

public class RenderpassTestCase extends InputAdapterRenderLoop implements ButtonListener{
    private Xith3DEnvironment env=null;
    private Tuple3f eyePos=new Vector3f(0.0f,0.0f,0.0f);
    private Tuple3f viewFocus = new Vector3f( 0.0f, 0.0f, -1.0f );
    private Tuple3f vecUp = new Vector3f( 0.0f, 1.0f, 0.0f );
    private Canvas3D canvas=null;
   
    private Hashtable<String,Body> bodies=new Hashtable<String,Body>();
    private GeomObject sun1=null;
    private GeomObject planet1=null;
   
    private GalaxyLayer galLayer=null;
    private ScaledLayer layer4=null;
    private ScaledLayer layer3=null;
    private ScaledLayer layer2=null;
    private ScaledLayer layer1=null;
   
    private HUD testHud=null;
   
    private Point3f userPos=new Point3f(0.0f,0.0f,14959800000.0f);
    /** Creates a new instance of StarEngine */
    public RenderpassTestCase() {
        super(128f);
        env = new Xith3DEnvironment( this );
        canvas=Canvas3DFactory.createWindowed(OpenGLLayer.JOGL_SWING, 800, 600, "Stars");
//        canvas=Canvas3DFactory.createWindowed(OpenGLLayer.JOGL_AWT, 800, 600, "Stars");
        canvas.setBackgroundColor(new Colorf(0.0f,0.0f,0.0f));
        this.getInputManager().registerKeyboardAndMouse( canvas );
        env.addCanvas( canvas );
        env.getView().lookAt( eyePos, viewFocus, vecUp );
        env.getView().setFrontClipDistance(0.1f);
        env.getView().setBackClipDistance(30000.0f);
        TextureLoader.getInstance().addTextureStreamLocator(new TextureStreamLocatorFile( "D:\\Java\\XithStars\\images\\") );
       
       
        galLayer=new GalaxyLayer(100000);
       
        layer4=new ScaledLayer(0.00000001f);
       
        createDefaultDistant();
        layer3=new ScaledLayer(0.00001f);
        layer2=new ScaledLayer(0.001f);
        layer1=new ScaledLayer(1.0f);
       
//        testHud=new HUD(canvas,new Tuple2f(800.0f,600.0f),this.getOperationScheduler(),this);
       
        env.addPerspectiveBranch(galLayer);
        env.addPerspectiveBranch(layer4);
        env.addPerspectiveBranch(layer3);
        env.addPerspectiveBranch(layer2);
        env.addPerspectiveBranch(layer1);
//        env.addHUD(testHud,this.getInputManager());
        this.begin();
    }
    public void createDefaultDistant(){
       
        // create sun
        sun1=new GeomObject(700000000.0f);
        // new Body(<name>, <orbit time millis>, <orbit distance metres>, <spin time millis>, <parent body>, <geometry Group to represent this body>)
        // Note sun has no parent body so set to null
        // Note also GeomObject's are not added, they are added by engine when it has sorted which renderpass to add them to.
        Body sunBody=new Body("Sol",1,0.0f,1000,null,sun1);
        bodies.put("SUN1",sunBody);
       
        // create planet 1
        planet1=new GeomObject(7000000.0f);
        // new Body(<name>, <orbit time millis>, <orbit distance metres>, <spin time millis>, <parent body>, <geometry Group to represent this body>)
        bodies.put("PLANET1",new Body("Planet1",60000,14959800000.0f,100000,sunBody,planet1));
    }
   
    // String name = user name of Group for debugging purposes
    // GeomObject tg = the Group to be moved
    // int lvl = the lvl of layer/renderpass to move the Group to.
    public void moveToView(String name,GeomObject tg, int lvl) {
        System.out.println("Moving "+name+" to view "+lvl);
        Group g=(Group)tg.getParent();
        if(g!=null)g.removeChild(tg);
        if(lvl==4){
//            tg.setCurrLvl(3);
            layer4.addChild(tg);
        } else if(lvl==3){
//            tg.setCurrLvl(2);
            layer3.addChild(tg);
        } else if(lvl==2){
//            tg.setCurrLvl(1);
            layer2.addChild(tg);
        } else if(lvl==1){
//            tg.setCurrLvl(0);
            layer1.addChild(tg);
        }
    }
    public void onKeyReleased(KeyReleasedEvent e) {
        switch (e.getKeyCode()) {
            case KeyCode.VK_ESCAPE:
                this.end();
                break;
        }
    }
    protected void onFPSCountIntervalHit(float fps) {
        super.onFPSCountIntervalHit( fps );
        canvas.setTitle( "RenderpassTestCase, FPS: " + (int)fps );
    }
    protected void prepareNextFrame(long gameTime, long frameTime, TimingMode tm) {
        super.prepareNextFrame( gameTime, frameTime, TimingMode.MILLISECONDS );
//        userz-=0.1;
        long time=System.currentTimeMillis();
        Enumeration e=bodies.elements();
        while(e.hasMoreElements()){
            Body b=(Body)e.nextElement();
            b.update(time,userPos);
            Point3f p=new Point3f((float)b.getX(),0.0f,(float)b.getZ());
            float dist=userPos.distance(p);
//            System.out.println(b.getName()+" Dist= "+dist);
            if(dist<=30000.0f && b.getCurrView()!=1){
                moveToView(b.getName(),b.getGeomObject(),1);
                b.setCurrView(1);
            }else if(dist<=100000.0f && b.getCurrView()!=2){
                moveToView(b.getName(),b.getGeomObject(),2);
                b.setCurrView(2);
            }else if(dist<=100000000.0f && b.getCurrView()!=3){
                moveToView(b.getName(),b.getGeomObject(),3);
                b.setCurrView(3);
            }else if(dist>100000000.0f && b.getCurrView()!=4){
                moveToView(b.getName(),b.getGeomObject(),4);
                b.setCurrView(4);
            }
        }
        env.getView().lookAt( eyePos, planet1.getPosition(), vecUp );
    }
   
    public void onButtonClicked(Button button, Object object) {
        if(button.getUserObject().equals("EXIT_BUTTON"))this.end();
    }
    public static void main(String[] args) {
        new RenderpassTestCase();
    }
    class GeomObject extends TransformGroup{
        private TransformGroup spinTrans=null;
        private Shape3D geom[]=new Shape3D[4];
        private int currLvl=-1;
        /**
         * Creates a new instance of GeomObject
         */
        public GeomObject(float radius) {
            super();
            spinTrans=new TransformGroup();
            Texture tex = TextureLoader.getInstance().getTexture( "space\\anims\\sun1\\sphMap001.jpg" );
            GeoSphere l3 = new GeoSphere( radius,6,tex);
            Appearance app3 = l3.getAppearance();
            app3.setMaterial( new Material( Colorf.ORANGE, Colorf.YELLOW,Colorf.WHITE, Colorf.RED,0.8f, Material.AMBIENT, true, false ) );
            l3.setAppearance( app3 );
            spinTrans.addChild(l3);
            super.addChild(spinTrans);
        }
        public void incSpin(float amount){
            Transform3D t1=new Transform3D();
            Transform3D t2=new Transform3D();
            t1.rotY(amount);
            spinTrans.getTransform(t2);
            t2.mul(t1);
            spinTrans.setTransform(t2);
        }
    }
    public class Body {
        private String name="UNKNOWN";
        private long orbPeriod=0;
        private long revPeriod=0;
        private double orbInc=0.0f;
        private float revInc=0.0f;
        private float orbDist=0.0f;
        private Body par=null;
        private GeomObject obj=null;
        private long lasttime=0;
        private double x=0.0f;
        private double z=0.0f;
        private double px=0.0f;
        private double pz=0.0f;
        private int currView=0;
       
        /** Creates a new instance of Body */
        public Body(String name,long orbitPeriod,float orbDistance,long spinTime,Body parent,GeomObject object) {
            this.name=name;
            orbPeriod=orbitPeriod;
            orbDist=orbDistance;
            revPeriod=spinTime;
            par=parent;
            obj=object;
            orbInc=(double)(Math.PI*2.0f)/orbPeriod;
            revInc=(float)(Math.PI*2.0f)/revPeriod;
            System.out.println(name+" orbInc="+orbInc+" , revInc="+revInc);
        }
        public String getName(){
            return name;
        }
        public int getCurrView(){
            return currView;
        }
        public void setCurrView(int cv){
            currView=cv;
        }
        public GeomObject getGeomObject(){
            return obj;
        }
        public double getX(){
            return x;
        }
        public double getZ(){
            return z;
        }
        public void update(long time,Point3f userPos){
            long upTime=time-lasttime;
            lasttime=time;
            /// do orbit rotation
            if(par!=null){
                px=par.getX();
                pz=par.getZ();
            }
            x=(Math.sin(time*orbInc)*orbDist)+px;
            z=(Math.cos(time*orbInc)*orbDist)+pz;
//        System.out.println(name+" x="+x+" , z="+z+" : SysTime="+time);
            Transform3D t3d=new Transform3D(new Vector3f((float)x-userPos.getX(),0.0f-userPos.getY(),(float)z-userPos.getZ()));
            obj.setTransform(t3d);
            // do spin rotation
            obj.incSpin((float)upTime*revInc);
        }
    }
    public class RenderLayer extends BranchGroup{
        private TransformGroup scaleTrans=null;
        /** Creates a new instance of RenderLayer */
        public RenderLayer(float scale) {
            super();
            scaleTrans=new TransformGroup();
            Transform3D t3d=new Transform3D();
            t3d.setScale(scale);
            scaleTrans.setTransform(t3d);
            super.addChild(scaleTrans);
        }
        public void addChild(Node n){
            scaleTrans.addChild(n);
        }
        public void removeChild(Node n){
            scaleTrans.removeChild(n);
        }
    }
    public class ScaledLayer extends RenderLayer{
        public ScaledLayer(float scale) {
            super(scale);
        }
    }
    public class GalaxyLayer extends RenderLayer{
        private Points pa=null;
        public GalaxyLayer(int numStars) {
            super(1.0f);
            float x,y,z;
            Vector3f pnts[]=new Vector3f[numStars];
            for(int i=0;i<=numStars-1;i++){
                x=(float)Math.random()*200.0f;
                y=(float)Math.random()*200.0f;
                z=(float)Math.random()*200.0f;
                pnts[i]=new Vector3f(x-100.0f,y-100.0f,z-100.0f);
            }
            pa=new Points(pnts,1.0f,true,new Colorf(1f,1f,1f));
            this.addChild(pa);
        }
    }
}

have fun!
John
« Last Edit: 16. December 2007, 08:44:16 pm by Marvin Fröhlich » Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #6 on: 16. December 2007, 10:28:48 pm »

Hmm.. strange behaivor. Looks like the values, you're using are simple too high for OpenGL. I will do the Foreground/Background to RenderPass port soon. Then you can use a CameraMode.FIXED_POSITION RenderPass for the galaxy etc. And don't have to use extremely high distance values to simulate infinity.

I want to finish the resource cleanup-fix first, which I am currently working on. Till then here are are few tips, how you should use Xith3D better:

  • Use addFPSListener( new CanvasFPSListener( canvas ) ) instead of hooking the onFPSCountIntervalHIT() event.
  • Use the detach() method of a Node instead of "if ( node.getParent() != null ) node.getParent().removeChild( node ). And you don't need to cast GroupNode to Group.
  • Use ResourceLocator for locating resources and use the createAndAddTSL() method of ResourceLocator to create a new TextureStreamLocator. And use relative paths.
  • Never use a full path for the getTexture() method of TextureLoader, but add an appropriate TextureStreamLocator and use simple names only.
  • Never use Backslashes ("\\") in path names, but slashes ("/") only. This is perfectly platform independent and is much simpler to write and read.
  • Stick to float. Never use double, if not urgently necessary. Avoids a lot of casts and is faster.
  • Use OpenMaLi's FastMath class instead of Sun's Math and Random classes. It is faster and avoids even more casts. FastMath also has some convenient constant like TWO_PI or PI_HALF, which avoids computation overhead.
  • Use Xith's timing. You used your own System.currentTimeMillis() timing, which is not a good idea. You can simply convert the gameTime (absolute time, the game is running) and frameTime (delta time of the last frame) to a second by using the TimingMode instance "timingMode.getSecondsAsFloat( gameTime )".
  • Never pass any fake-TimingMode value to the super call of methods like prepareNextFrame(). This would cause unexpected behavior.
  • Try to avoid GC-overhead. e.g. Never create instances, that don't need to be created. Most methods also take plain floats instead of objects like Point3f or Vector3f. Using Iterators or Enumerations causes additional unnecessary GC.
  • Avoid compiler warnings. e.g. Use the @Override annotation and use generics, which also avoids casts.
  • Share NodeComponents over equal objects. So, if you attach equal Materials, XXXAttributes, etc. to an Appearance, simply use the same Material, etc. instance to attach to that appearance. If the whole Appearance is equal, share it. This will lead to much faster rendering.
  • Try not to use terms like "Body" for your classes, since this classname is already in use for a physical Body in xith.
  • Use geometry optimization for static shapes. The galaxy for example will never change. So you can use "pa.getGeometry().setOptimization( Optimization.USE_DISPLAY_LISTS );" to render them in an optimized way.

And you should use only 10000 stars. Looks much better Wink.

Marvin
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic