java.lang.IllegalStateException: Scene graph is not properly updated for rendering.
Is what I get.
It does not show what file is causing it but it does say:
Make sure scene graph state was not changed after
rootNode.updateGeometricState() call.
In order to have done that I must have overriden some SimpleAppllication methods right?
I have not.
All iv overriden is
simpleUpdate
simpleInitApp()
and destroy()
I do have a zombie brain that updates each .1 seconds.
It changes the rotation of the zombie that its attached to, aswell as walkdirection etc.
If this is the problem causing this error, then how do I make sure it does not run after rootNode.updateGeometricState and whatnot?
How do I know when Im allowed to update locations when using extra threads?
Rofl, I saw this coming when you had a “hanging” thread when the application quit… Addez+Threads = Doom xD
You are accessing the scene graph from another thread. You are not thinking about the consequences of multithreading. I suggest you read our wiki doc on the subject, it shows a nice to handle way to do multithreading.
https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:multithreading
Rofl, I saw this coming when you had a “hanging” thread when the application quit.. Addez+Threads = Doom
I see you have great faith in me :P
So I read that page a couple of times and my conclusion is that:
1) I do not HAVE to use java.util.concurrent to solve my problem, all it does is improve code design and speed on dualcore computer
2) For every variable that I wish to edit I must have a cloned copy that gets updated by the main app loop and another copy that the main app can read from and set the real value to be the clones value.
For example, if I got the position of a character, then in order to change it, I must have 1 variable:
playerPosition
and then when the simpleUpdate runs, it does:
player.setLocalTranslation(playerPosition) ?
And in order to get a value I must have the same variable:
playerPosition
and in main app loop it does:
playerPosition = player.getLocalTranslation().clone();
Am I correct or have I missunderstood the concept?
Just do it like this when you want to move an object from another thread:
[snippet id=“10”]
What your thread does is not “improving code design”, its the exact opposite. As said, you don’t seem to be aware of the implications of threading, read more about it and try to understand that you cant just access any data from any thread.
Yes that was what I ment, that the multitasking they suggested is improving the code design appearance.
But as for getting values, then its just do .clone() right?
So if I get this right, to update my CharacterPhysicNode body I do:
body = ??
Im not completly sure how to do it…
Is it that when the method call is run in a class, then Im allowed to modify any variable?
Im really confused about this, is there any other page to read from?
I have been working with multi threading in python before, but then I used locks that unlocked when the variable was not in use…
No clone() doesn’t have to do anything with threading. And no, you cant just lock the variable, its not good threading anyway going and setting values that are used in one thread in another one just like that, even if they have a mutex per instance. Just apply the rotation/location at the right moment using the queue. I suggest you do not use threads at all except for situations where operations cause long lags and then use the method explained in the linked document. This will keep you from doing bad things threading wise.
Okej.
So I have this zombie that needs pathfinding. The process does not take long but lets assume it does.
If I were to calculate its new walkDirection, I’d use a method called getWalkDirection()
And that method should use a outside queue thread thingy.
If I do so, would it not lag my game still because the consol cant move on to the next line until the method has returned a value?
So I would not actually gain anything from that type of threading?
Or should I do in the simpleUpdate:
for(for all zombies){
zombie.update();
}
Would that not lag?
no it wont lag at all,
- you ignore thread creation/destruction time, synchronizing, etc = 50-200 java commands.
- so dont use threads for simple tasks (0.001sec duration). Use it only for tasks that take a lot of time, e.g loading models (it can take 3 min).
- Most important : premature optimisation is the root of all evil.
- Also: dont try to do ZOMG OMG L33t H@xx Code. start simple and then refactor, its better to have a “meh game” than a “no game”. Because a “meh game” gives you motivation to continue.
Hehe thanks
Ill try that
avoid threads unless absolutely necessary. Usually there is a work around
W8!
My zombies must wait at some points.
How do I fix that?
I want them to wait 2 seconds. Had a simple method for that, now i must do a complex workaround
counter = 0;
update(float tpf) {
counter += tpf;
if(counter >= 2){
counter = 0;
moveZombie();
}
}
or use the native secondCounter instance variable.
seconds = 0;
update(float tpf){
if(secondCounter == 1)
seconds++;
if(seconds >= 2)
seconds = 0;
moveZombie()
}
you wanted something like that? (technically you should probably use something like FastMath.Abs(1 - secondCounter) < 0.01 for checking for float equality)
//pseudocode
Class Timer
{
float totalTime = 0 ;
simpleUpdate(tpf)
{
totalTime+=tpf;
if (totalTime > 2)
{
Tada();
totalTime=0;
}
}
Tada()
{
//override me.
}
}
You can create a class that acts as a timer with this code and create annonymousClasses from it to do minor tasks.
Maybe jme has already this timer class inside. Anyone know its name ?
Thanks
I made a ThreadManager that includes the method wait()
It runs all the time tho simulates a thread.
Thanks alot for the effort tralala
Man, pathfinding is the exact example I posted -.-