Hello Guest

[SOLVED] Only one pixel of texture when trying to draw textured quad !

  • 20 Replies
  • 21834 Views
*

Offline quew8

  • *****
  • 569
  • Because Square Eyes Look More Real
Re: Only one pixel of texture when trying to draw textured quad !
« Reply #15 on: May 29, 2013, 16:43:34 »
Presumably in one of your implementations of GameComponent -I guess the start button- the updateComponent() method removes all the entries from the ArrayList of components because you are no longer on the menu so they aren't there anymore. Am I right? You cannot do this. You are iterating over the list (a for-each loop creates an Iterator object in the background) so the ArrayList will not let you modify it. If you could then the Iterator might try to access an element that no longer exists or has been moved etc... So it can't be done.

The easiest solution (IMO) is to use a message queue which at its simplest is an ArrayList of runnable objects. When you want something to be done but cannot do it at the current time, because you are in an iteration loop or the wrong thread etc, you add a message to the queue containing the code you want done. At a convenient time you run the code in each message then clear the queue.

Code: [Select]

//Add this in the field declarations of Window.
public static final ArrayList<Runnable> messageQueue = new ArrayList<>();

//...

//Modifying onTick()

public void onTick() {
    for (GameComponent g : windowComponents) {
        g.updateComponent();
    }
   
    for(Runnable r: messageQueue) {
        r.run();
    }
    messageQueue.clear();

}

//An example of clearing the components from a component class.
@Override
public void updateComponent() {
    Window.messageQueue.add(
        new Runnable() {
            @Override
            public void run() {
                //Whatever you do to remove components.
            }
        }
    );
}


This is a very simple, naive implementation. It should work for what you have described but I would advise refining it if you ever want to use it for anything else. But the concept is there.

A little advice - when you have an exception and you don't know why. Just google the name of the exception - you will get the javadoc for it which will most likely tell you the most likely causes for it.

A little more advice - When people give you advice, take it - you are still not using the code blocks for this site and it makes your code very hard to read.

*

Offline Yuri6037

  • ***
  • 104
  • Check out our website : http://www.sldt-team.net !
    • SLDT
Re: Only one pixel of texture when trying to draw textured quad !
« Reply #16 on: May 30, 2013, 07:24:39 »
Thanks i will test this code !
Simple question how can i do for the onExit() void because the crashes arrive in this void !
And in effect normaly a window should remove and add components while the game is running !

*

Offline Yuri6037

  • ***
  • 104
  • Check out our website : http://www.sldt-team.net !
    • SLDT
Re: Only one pixel of texture when trying to draw textured quad !
« Reply #17 on: May 30, 2013, 07:48:17 »
Oh Thank you very much i can now create the launcher for LWJGL !
The game is perfect now 1000 FPS !

*

Offline quew8

  • *****
  • 569
  • Because Square Eyes Look More Real
Re: Only one pixel of texture when trying to draw textured quad !
« Reply #18 on: May 30, 2013, 10:27:58 »
For onExit(), exactly the same approach:

Code: [Select]
public void onExit() {
    messageQueue.add(new Runnable() {
        @Override
        public void run() {
            windowComponents.clear(); //This does not have to be synchronized, you aren't in separate threads.
        }
    });
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); // You only need to clear the screen once.
                                                                                                         //(removed the first glClear)
}

That you had to ask makes me think you don't understand the reason for the exception and how the solution works though. Read up on ConcurrentModificationException.

*

Offline Yuri6037

  • ***
  • 104
  • Check out our website : http://www.sldt-team.net !
    • SLDT
Re: Only one pixel of texture when trying to draw textured quad !
« Reply #19 on: June 05, 2013, 10:51:26 »
Oh thanks completly ! You make my game working properly ! Now normaly Windows XP can play at the game !

*

Offline Yuri6037

  • ***
  • 104
  • Check out our website : http://www.sldt-team.net !
    • SLDT
Re: Only one pixel of texture when trying to draw textured quad !
« Reply #20 on: June 05, 2013, 12:18:51 »
Thanks for all ! But now i can't finish the launcher : I'm getting this windows Error : "Could not find the main class C:\*************\.brickBroken\app\slick.jar. Program will exit." while trying to launch game by process builder !
Here is my java code :
processCommands represent an array list that is used by the process builder to launch game.

        processCommands.add("javaw");
        processCommands.add("-Xms512m");
        processCommands.add("-Xmx1024m");
        processCommands.add("-cp");
        processCommands.add(Util.getWorkingDirectory() + File.separator + "app" + File.separator + "slick-util.jar");
        processCommands.add(Util.getWorkingDirectory() + File.separator + "app" + File.separator + "slick.jar");
        processCommands.add(Util.getWorkingDirectory() + File.separator + "app" + File.separator + "lwjgl_util.jar");
        processCommands.add(Util.getWorkingDirectory() + File.separator + "app" + File.separator + "lwjgl.jar");
        processCommands.add(Util.getWorkingDirectory() + File.separator + "app" + File.separator + "luaj-jse.jar");
        processCommands.add(Util.getWorkingDirectory() + File.separator + "app" + File.separator + "luaj-jme.jar");
        processCommands.add(Util.getWorkingDirectory() + File.separator + "app" + File.separator + "jinput.jar");
        processCommands.add(Util.getWorkingDirectory() + File.separator + "app" + File.separator + "ibxm.jar");
        processCommands.add(Util.getWorkingDirectory() + File.separator + "app" + File.separator + "brickBroken.jar");
        processCommands.add("-Djava.library.path=" + Util.getWorkingDirectory() + File.separator + "app" + File.separator + "system" + File.separator);

        processCommands.add("fr.brickbroken.client.BrickBroken");

Can you help me ?