Problem with FPSCounter

Im trying to make a FPS window to my game but im getting a NullPointerException
Do you guys know why
The is the same from BSPTest


    private BranchGroup createHUD(ExtXith3DEnvironment env, RenderPassConfigProvider passConfig, Canvas3D canvas, Xith3DDemoFolder demoFolder) throws Exception
    {
        BranchGroup hudBranch = new BranchGroup();
        
        HUD hud = new HUD(canvas, 800, 600, this);
        
        Image crosshair = new Image(hud.getSizeOfPixels(32, 32), "src/Textures/CrosshairWhite.png", true);
        hud.addWidget(crosshair, (hud.getResolution().x - crosshair.getWidth()) / 2f, (hud.getResolution().y - crosshair.getHeight()) / 2f);

        FPSCounter fpsCounter = new FPSCounter(100, 30, "src/Textures/YellowBorder.png");
        fpsCounter.setFontColor( new Color3f(0.12f, 1.0f, 0.18f) );
        this.addFPSListener(fpsCounter);
        hud.addWidget(fpsCounter, 650, 520);        
        
        hudBranch.addChild(hud);
        
        env.addBranchGraph( hudBranch );        
        env.addRenderPass( new RenderPass(hudBranch, passConfig) );
        
        return( hudBranch );
    }

Whe i try to run i get this error


Exception in thread "main" java.lang.NullPointerException
        at org.xith3d.ui.hud.utils.WidgetTheme.<init>(WidgetTheme.java:473)
        at org.xith3d.ui.hud.utils.WidgetTheme.<init>(WidgetTheme.java:500)
        at org.xith3d.ui.hud.HUD.getTheme(HUD.java:172)
        at org.xith3d.ui.hud.widgets.Label.<init>(Label.java:639)
        at org.xith3d.ui.hud.widgets.Label.<init>(Label.java:657)
        at org.xith3d.ui.hud.widgets.FPSCounter.<init>(FPSCounter.java:160)
        at org.xith3d.ui.hud.widgets.FPSCounter.<init>(FPSCounter.java:221)
        at org.xith3d.ui.hud.widgets.FPSCounter.<init>(FPSCounter.java:281)
        at Project.game.createHUD(game.java:122)
        at Project.game.<init>(game.java:152)
        at Project.game.main(game.java:174)

I tryied to run the BSPTest and it runs well but it dosent appear the FPS window

There’s a commented line:


//createHUD(env, new RenderPassConfig(RenderPassConfig.PARALLEL_PROJECTION), canvas, demoFolder);

Uncomment it and the FPS window (and the crosshair) will appear. You’ll have to use it the same or a similar way. Please tell me, if it worked for you.

Marvin

The line is already uncommented but in the BSPTest i get the same error that i get on my code

The NullPointerException on new FPSCOunter

Hmm… I doublechecked the thing… No NullPointerException ??? Did you do a fresh CVS checkout? Maybe you last checked out while I was currently checking in.

I´ll check my CVS again and reply if it has worked


Exception in thread "main" java.lang.NullPointerException
        at org.xith3d.ui.hud.utils.WidgetTheme.<init>(WidgetTheme.java:473)
        at org.xith3d.ui.hud.utils.WidgetTheme.<init>(WidgetTheme.java:500)
        at org.xith3d.ui.hud.HUD.getTheme(HUD.java:172)
        at org.xith3d.ui.hud.widgets.Label.<init>(Label.java:639)
        at org.xith3d.ui.hud.widgets.Label.<init>(Label.java:657)
        at org.xith3d.ui.hud.widgets.FPSCounter.<init>(FPSCounter.java:160)
        at org.xith3d.ui.hud.widgets.FPSCounter.<init>(FPSCounter.java:221)
        at org.xith3d.ui.hud.widgets.FPSCounter.<init>(FPSCounter.java:281)
        at javaapplication31.BSPLoaderTest.createHUD(BSPLoaderTest.java:217)
        at javaapplication31.BSPLoaderTest.<init>(BSPLoaderTest.java:248)
        at javaapplication31.BSPLoaderTest.main(BSPLoaderTest.java:276)
BUILD SUCCESSFUL (total time: 8 seconds)


I´ve downloaded de CVS again and still get the NullPointerException on this line of the createHud method
FPSCounter fpsCounter = new FPSCounter(100, 30, “YellowBorder.png”);


    private BranchGroup createHUD(ExtXith3DEnvironment env, RenderPassConfigProvider passConfig, Canvas3D canvas, Xith3DDemoFolder demoFolder) throws Exception
    {
        TextureLoader.getInstance().addTextureStreamLocator(new TextureStreamLocatorFile(demoFolder.hud()));
        
        BranchGroup hudBranch = new BranchGroup();
        
        HUD hud = new HUD(canvas, 800, 600, this);
        
        Image crosshair = new Image(hud.getSizeOfPixels(64, 64), "CrosshairWhite.png", true);
        hud.addWidget(crosshair, (hud.getResolution().x - crosshair.getWidth()) / 2f, (hud.getResolution().y - crosshair.getHeight()) / 2f);
        
        FPSCounter fpsCounter = new FPSCounter(100, 30, "YellowBorder.png");
        fpsCounter.setFontColor( new Color3f(0.12f, 1.0f, 0.18f) );
        this.addFPSListener(fpsCounter);
        hud.addWidget(fpsCounter, 650, 520);
        
        hudBranch.addChild(hud);
        
        env.addBranchGraph( hudBranch );        
        env.addRenderPass( new RenderPass(hudBranch, passConfig) );
        
        return( hudBranch );
    }

Have any ideas why?
When you run this test with the uncommented line and you the the FPS window ?

Seems like the GTK theme file is missing. Please check, if the file org.xith3d.ui.hud.resources.themes.GTK.xwt exists in your source tree. If it doesn’t, this is your error and please check, why your eclipse (or what ever you’re using) doesn’t checkout this file. If it does exist, please dig into the code (org.xith3d.ui.hud.util.WidgetTheme, line #500). This is where the error occurrs. Maybe I’m using getResourceAsStream in a wrong way.

Anyway the line


HUD.class.getResourceAsStream("resources/themes/" + name + ".xwt")

returns null. Please check why. It doesn’t on my system.

Marvin

Thanks Marvin,
The problem was that when i compiled the cvs it was not adding themes/GTK.xwt to the jar file or to class folder (Maybe a problem with Netbeans) so i added it manually and it worked

Good to know :).