Author Topic: problems with gears example  (Read 11603 times)

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: problems with gears example
« Reply #15 on: December 17, 2008, 01:35:03 pm »
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")

Offline Veko

  • byte
  • *
  • Posts: 18
    • View Profile
Re: problems with gears example
« Reply #16 on: December 17, 2008, 01:46:04 pm »
wow, sweet man :D
will test this asap

*edit* very nice, that should be stickied up :D + big thanks for the fast support
« Last Edit: December 17, 2008, 02:17:30 pm by Veko »

Offline fireside

  • double
  • *****
  • Posts: 607
    • View Profile
Re: problems with gears example
« Reply #17 on: December 17, 2008, 05:12:11 pm »
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<-

Offline Veko

  • byte
  • *
  • Posts: 18
    • View Profile
Re: problems with gears example
« Reply #18 on: January 24, 2009, 02:14:32 am »
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

Code: [Select]
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)

Code: [Select]
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:

Code: [Select]
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 :)

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: problems with gears example
« Reply #19 on: January 24, 2009, 03:35:47 am »
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.
« Last Edit: January 24, 2009, 04:14:51 am by paulscode »

Offline Veko

  • byte
  • *
  • Posts: 18
    • View Profile
Re: problems with gears example
« Reply #20 on: January 24, 2009, 01:08:28 pm »
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:

Code: [Select]
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:

Code: [Select]
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)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: problems with gears example
« Reply #21 on: January 24, 2009, 01:13:42 pm »
Are you sure that glFont has actually been initialized?

Offline Veko

  • byte
  • *
  • Posts: 18
    • View Profile
Re: problems with gears example
« Reply #22 on: January 24, 2009, 03:26:59 pm »
ok silly me, you're right I forgot to initialize :D
can someone also point me in the right direction for bitmapFonts ?