problems with gears example

Started by Veko, December 16, 2008, 08:10:38 PM

Previous topic - Next topic

paulscode

I finished a working example of state switching with jPCT.  It's very basic, but it proves the concept works.

Demo Applet  (Source Code)

The applet has three states:
Loading State  (Loads everything and displays messages)
Gear State      (Gears demo, press "ESC" to exit)
Exit State       (Says "Goodbye")

Veko

#16
wow, sweet man :D
will test this asap

*edit* very nice, that should be stickied up :D + big thanks for the fast support

fireside

I'm going to look at that source too.  Not to belabor a point, but a wiki would be really nice for these things, better than stickies because they tend to get messy. 
click here->Fireside 7 Games<-

Veko

ok I'm back with a new question. I'm still using this system for my applet and now I'm trying to implement FengGUI.
I've gotten so far as

private org.fenggui.Display display;
...

this.display = new Display(new AWTGLCanvasBinding((AWTGLCanvas)m_Canvas));

Window window = FengGUI.createWindow(display, true, false, false, true);
window.setTitle("my window");
window.setPosition(new Point(50,200));
window.getContentContainer().setLayoutManager(new RowLayout(false));
window.getContentContainer().getAppearance().setPadding(new Spacing(10, 10));


after that I tried adding stuff (but here I stumbled upon the null pointer exception)

final ToggableGroup<String> toggableGroup = new ToggableGroup<String>();
RadioButton<String> radioButtonCoffee = new RadioButton<String>("coffee", toggableGroup, "coffee");
RadioButton<String> radioButtonTea = new RadioButton<String>("tea", toggableGroup, "tea");
radioButtonTea.setSelected(true);

Container container = new Container(new RowLayout(true));
container.addWidget(radioButtonCoffee);
container.addWidget(radioButtonTea);
window.getContentContainer().addWidget(container);


but why I try to add stuff to the window (like radio buttons etc.) I get a null pointer exception. I've been reading up about common null pointer exceptions with FengGUI, but I haven't found a solution yet

here's the exception:

Exception in thread "Thread-21" java.lang.NullPointerException
at org.lwjgl.opengl.GL11.glGenTextures(GL11.java:1348)
at org.fenggui.render.lwjgl.LWJGLTexture.createTextureID(Unknown Source)
at org.fenggui.render.lwjgl.LWJGLTexture.createTexture(Unknown Source)
at org.fenggui.render.lwjgl.AWTGLCanvasBinding.getTexture(Unknown Source)
at org.fenggui.theme.DefaultTheme.setUp(Unknown Source)
at org.fenggui.theme.StandardTheme.setUp(Unknown Source)
at org.fenggui.StandardWidget.setupTheme(Unknown Source)
at org.fenggui.RadioButton.<init>(Unknown Source)
at facebookgame.IngameState.buildGUI(IngameState.java:417)
at facebookgame.IngameState.enter(IngameState.java:105)
at facebookgame.MainApp.switchState(MainApp.java:136)
at facebookgame.MainApp.stateEvent(MainApp.java:148)
at facebookgame.LoadingState.tick(LoadingState.java:75)
at facebookgame.MainApp.run(MainApp.java:87)
at java.lang.Thread.run(Unknown Source)


also, I have no idea where to put the display.display()

hopefully you guys can help me as good as before :)

paulscode

#19
From the stack trace, this looks like it might be a thread synchronization problem.  Are you creating the window on a different thread than the one MainApp.run() method is running from?  If so, this could cause a problem if the loading state finishes and tries to switch to the ingame state before the window has been fully instantiated.  You could try synchronizing on an Object instance every time the window and its components are accessed or changed.

Oh, and about where to put the display.display().  I am not familiar with fenggui myself - what does the display() method do?  If it updates the contents of the canvas, for example, a good place for it might be in either the state's tick() or paint() method.

--EDIT--
Another place I thought of to check for thread synchronization problems is when calling the MainApp.stateEvent() method.  If you are using the same setup as in the example I posted above, make sure this method is being called from the same thread that the State.tick() method is being called from (i.e. the MainApp.run() thread).  From the stack trace, I can see that it is, so this is not causing your current problem.

--EDIT #2--
One more potential problem I just thought of is the fact that paint() always runs on a different thread than tick(), so it might be a good idea to use a synchronized interface to a "safeToPaint" boolean.  Set the boolean to false when the state is initializing or shutting down, to avoid null pointer exceptions.  I hadn't considered this when I created the above example applet.  Again, this doesn't appear to be related to your current problem, though.

Veko

I've set aside the FengGUI for a moment (think its to overkill for what I want, I just want some simple text in a custom font on my screen)

so now I'm looking into the whole blitting thingie and stumbled on this topic
http://www.jpct.net/forum2/index.php/topic,1074.0.html

this looks very promising, but when I try to do:

private GLFONT glfont;
...
m_Buffer.update();

glfont.blitString(m_Buffer, "this is a blitted text", 10, 10, 1, Color.ORANGE);

m_Buffer.displayGLOnly();
       
m_Canvas.repaint();


I'm getting null pointer exception:

Exception in thread "AWT-EventQueue-2" java.lang.NullPointerException
at facebookgame.IngameState.paint(IngameState.java:218)
at facebookgame.MainApp.paint(MainApp.java:58)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.seqPaintDirtyRegions(Unknown Source)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

EgonOlsen

Are you sure that glFont has actually been initialized?

Veko

ok silly me, you're right I forgot to initialize :D
can someone also point me in the right direction for bitmapFonts ?