(solved :) ) weird loading behavior after using BatchNode

I am using BatchNode and it works fine except the more models I have the more the loading time takes. The strange behavior is that when looking at the console, I see the children attach to the BatchNode, then detach, then attach , then detach… etc for quite some time (2 mins or so) before the model finally loads up.



Why is that happening?



[java]

Mar 22, 2012 9:59:41 AM com.jme3.scene.Node attachChild

INFO: Child (Fiducial_3759) attached to this node (null)

Mar 22, 2012 9:59:41 AM com.jme3.scene.Node attachChild

INFO: Child (Fiducial_3760) attached to this node (null)

Mar 22, 2012 9:59:41 AM com.jme3.scene.Node attachChild

INFO: Child (Fiducial_3761) attached to this node (null)

Mar 22, 2012 9:59:41 AM com.jme3.scene.Node attachChild

INFO: Child (Fiducial_3762) attached to this node (null)







ar 22, 2012 9:59:42 AM com.jme3.scene.Node detachChildAt

INFO: null (Node): Child removed.

Mar 22, 2012 9:59:42 AM com.jme3.scene.Node detachChildAt

INFO: null (Node): Child removed.

Mar 22, 2012 9:59:42 AM com.jme3.scene.Node detachChildAt

INFO: null (Node): Child removed.

Mar 22, 2012 9:59:42 AM com.jme3.scene.Node detachChildAt

INFO: null (Node): Child removed.

Mar 22, 2012 9:59:42 AM com.jme3.scene.Node detachChildAt

INFO: null (Node): Child removed.

Mar 22, 2012 9:59:42 AM com.jme3.scene.Node detachChildAt

INFO: null (Node): Child removed.

Mar 22, 2012 9:59:42 AM com.jme3.scene.Node detachChildAt

INFO: null (Node): Child removed.









ld (batch-batch2010) attached to this node (batch)

Mar 22, 2012 10:00:50 AM com.jme3.scene.Node attachChild

INFO: Child (batch-batch2011) attached to this node (batch)

Mar 22, 2012 10:00:50 AM com.jme3.scene.Node attachChild

INFO: Child (batch-batch2012) attached to this node (batch)

Mar 22, 2012 10:00:50 AM com.jme3.scene.Node attachChild

INFO: Child (batch-batch2013) attached to this node (batch)

Mar 22, 2012 10:00:50 AM com.jme3.scene.Node attachChild

INFO: Child (batch-batch2014) attached to this node (batch)

Mar 22, 2012 10:00:50 AM com.jme3.scene.Node attachChild

INFO: Child (batch-batch2015) attached to this node (batch)

Mar 22, 2012 10:00:50 AM com.jme3.scene.Node attachChild

INFO: Child (batch-batch2016) attached to this node (batch)

Mar 22, 2012 10:00:50 AM com.jme3.scene.Node attachChild

INFO: Child (batch-batch2017) attached to this node (batch)

Mar 22, 2012 10:00:50 AM com.jme3.scene.Node attachChild

INFO: Child (batch-batch2018) attached to this node (batch)

Mar 22, 2012 10:00:50 AM com.jme3.scene.Node attachChild

INFO: Child (batch-batch2019) attached to this node (batch)

Mar 22, 2012 10:00:50 AM com.jme3.scene.Node attachChild

INFO: Child (batch-batch2020) attached to this node (batch)

Mar 22, 2012 10:00:50 AM com.jme3.scene.Node attachChild

INFO: Child (batch-batch2021) attached to this node (batch)

Mar 22, 2012 10:00:50 AM com.jme3.scene.Node attachChild

INFO: Child (batch-batch2022) attached to this node (batch)

Mar 22, 2012 10:00:50 AM com.jme3.scene.Node attachChild

INFO: Child (batch-batch2023) attached to this node (batch)

Mar 22, 2012 10:00:50 AM com.jme3.scene.Node attachChild

INFO: Child (batch-batch2024) attached to this node (batch)

Mar 22, 2012 10:00:50 AM com.jme3.scene.Node attachChild

INFO: Child (batch-batch2025) attached to this node (batch)

Mar 22, 2012 10:00:50 AM com.jme3.scene.Node attachChild

INFO: Child (batch-batch2026) attached to this node (batch)

Mar 22, 2012 10:00:50 AM com.jme3.scene.Node attachChild

INFO: Child (batch-batch2027) attached to this node (batch)

Mar 22, 2012 10:00:50 AM com.jme3.scene.Node attachChild

INFO: Child (batch-batch2028) attached to this node (batch)

Mar 22, 2012 10:00:50 AM com.jme3.scene.Node attachChild

INFO: Child (batch-batch2029) attached to this node (batch)

Mar 22, 2012 10:00:50 AM com.jme3.scene.Node attachChild

INFO: Child (batch-batch2030) attached to this node (batch)

Mar 22, 2012 10:00:50 AM com.jme3.scene.Node attachChild

INFO: Child (batch-batch2031) attached to this node (batch)

Mar 22, 2012 10:00:50 AM com.jme3.scene.Node attachChild

INFO: Child (batch-batch2032) attached to this node (batch)

Mar 22, 2012 10:00:50 AM com.jme3.scene.Node attachChild

INFO: Child (batch-batch2033) attached to this node (batch)

Mar 22, 2012 10:00:50 AM com.jme3.scene.Node attachChild

INFO: Child (batch-batch2034) attached to this node (batch)

Mar 22, 2012 10:00:50 AM com.jme3.scene.Node attachChild

INFO: Child (batch-batch2035) attached to this node (batch)

Mar 22, 2012 10:00:50 AM com.jme3.scene.Node attachChild

INFO: Child (batch-batch2036) attached to this node (batch)

Mar 22, 2012 10:00:50 AM com.jme3.scene.Node attachChild

INFO: Child (batch-batch2037) attached to this node (batch)

Mar 22, 2012 10:00:50 AM com.jme3.scene.Node attachChild

INFO: Child (batch-batch2038) attached to this node (batch)

Mar 22, 2012 10:00:50 AM com.jme3.scene.Node attachChild

INFO: Child (batch-batch2039) attached to this node (batch)













INFO: Child (BitmapFont) attached to this node (null)

Mar 22, 2012 10:00:50 AM com.jme3.scene.Node attachChild

INFO: Child (null) attached to this node (Gui Node)

Mar 22, 2012 10:00:51 AM com.jme3.material.MaterialDef <init>

INFO: Loaded material definition: Fade

Mar 22, 2012 10:00:51 AM com.jme3.renderer.lwjgl.LwjglRenderer updateUniformLocation

INFO: Uniform g_CameraPosition is not declared in shader [ShaderSource[name=Common/MatDefs/Light/Lighting.vert, defines, type=Vertex], ShaderSource[name=Common/MatDefs/Light/Lighting.frag, defines, type=Fragment]].

Timer AppState Initialized



[/java]

First of all disable logging, it will probably make the process 1000% faster. Then read the javadoc of the BatchNode, what it does is normal.

I read it , but I didn’t know it’s normal to repeat the attach/detach more than 10 times.



Also, another issue you brought up is logging, I use:



[java]java.util.logging.Logger.getLogger("").setLevel(Level.WARNING);[/java] and somehow it still shows everything in my console.

looks like logging is working fine its just that code:



[java]Mar 22, 2012 3:35:54 PM com.jme3.scene.Node attachChild

INFO: Child (batch-batch2040) attached to this node (batch)

Mar 22, 2012 3:35:54 PM com.jme3.scene.Node attachChild

INFO: Child (batch-batch2041) attached to this node (batch)

Mar 22, 2012 3:35:54 PM com.jme3.scene.Node attachChild

INFO: Child (batch-batch2042) attached to this node (batch)

Mar 22, 2012 3:35:54 PM com.jme3.scene.Node attachChild

INFO: Child (batch-batch2043) attached to this node (batch)

Mar 22, 2012 3:35:54 PM com.jme3.scene.Node attachChild

INFO: Child (batch-batch2044) attached to this node (batch)

Mar 22, 2012 3:35:54 PM com.jme3.scene.Node attachChild

INFO: Child (batch-batch2045) attached to this node (batch)

Mar 22, 2012 3:35:54 PM com.jme3.scene.Node attachChild

INFO: Child (batch-batch2046) attached to this node (batch)

Mar 22, 2012 3:35:54 PM com.jme3.scene.BatchNode doBatch

INFO: Batched 2,048 geometries in 2,047 batches.[/java]



does anyone know where can I disable this prints?

No logging at all =



Logger.getLogger("").setLevel(Level.OFF);

Logger.getLogger(“com.jme3.scene.Node”).setLevel(Level.WARNING);

I tried this:

[java] Logger.getLogger(myGame.class .getName()).setLevel(Level.OFF);[/java]



and it doesn’t work.



What do I pass in getLogger? both fields u guys passed aren’t accepted.

@madjack said:
No logging at all =

Logger.getLogger("").setLevel(Level.OFF);

I have double checked this and it works (no logging at all!!!). @madjack is right.

This is the way that logging works (I'm not 100% sure... be aware ;)) :
Logger.getLogger(your.class.name).setLevel(Level.OFF); will disable logging for your class only. Loggers in others classes will continue logging information. If you want to disable logging for all the classes within a package use: Logger.getLogger(package).setLevel(Level.OFF);. Using "" will disable logging for all the classes ("" is the root or something like that). I repeat, i'm not 100% sure about that.

Try it using BatchNode

you never read documentations?




Find or create a logger for a named subsystem. If a logger has already been created with the given name it is returned. Otherwise a new logger is created.
If a new logger is created its log level will be configured based on the LogManager configuration and it will configured to also send logging output to its parent's handlers. It will be registered in the LogManager global namespace.
Note: The LogManager may only retain a weak reference to the newly created Logger. It is important to understand that a previously created Logger with the given name may be garbage collected at any time if there is no strong reference to the Logger. In particular, this means that two back-to-back calls like getLogger("MyLogger").log(...) may use different Logger objects named "MyLogger" if there is no strong reference to the Logger named "MyLogger" elsewhere in the program.


edit: it was not to you homsi.

edit2: ahh sorry i got idea, but nvm
at all [java]Logger.getLogger("").setLevel(Level.OFF);[/java]
should work for everything, got no idea why not for this. maybe becouse you do it "after" this actions are done.
1 Like

@oxplay2 I feel bad dumb lol like u said


maybe becouse you do it “after” this actions are done


thats what happens when u write Spaghetti code ;)

Guys can batchNode handle more than 10,000 objects? It works PERFECTLY for me with around 3-4000 objects but when I try using it wth more than 10k , it keeps attaching/detaching indefinitely. I turned off logging as @normen recomended and it def speeds up the process but it still hangs with these large batchings :S

Well batching is a long process, i recommend batching once all of the objects are added to the batchNode.

also it can be wise to split your scene is several batch nodes.

1 Like

I had like 50.000 objects with 200 fps, so it depends. But batchng 10.000 objects like this is suboptimal anyway.

1 Like

I see your points but for testing purposes , if I batch at once 32,000 objects. I get an error at the batch() function



[java]Mar 28, 2012 12:35:01 PM com.jme3.app.Application handleError

SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]

java.lang.OutOfMemoryError: Direct buffer memory

at java.nio.Bits.reserveMemory(Bits.java:633)

at java.nio.DirectByteBuffer.<init>(DirectByteBuffer.java:98)

at java.nio.ByteBuffer.allocateDirect(ByteBuffer.java:288)

at com.jme3.util.BufferUtils.createIntBuffer(BufferUtils.java:846)

at com.jme3.scene.VertexBuffer.createBuffer(VertexBuffer.java:867)

at com.jme3.scene.BatchNode.mergeGeometries(BatchNode.java:442)

at com.jme3.scene.BatchNode.doBatch(BatchNode.java:202)

at com.jme3.scene.BatchNode.batch(BatchNode.java:175)[/java]



does that make I MUST separate this batch node into multiple batch nodes?

No that means your memory settings are not good.

sorry my question was unclear. I know that I am out of java memory and I need to increase that from the project settings. but my question was if that’s because of my code (where I need to optimize the use of BatchNodes into multiple ones rather that one BIG batch Nodes) or completely unrelated?



Is having a Big BatchNode really really bad :)?

@nightwolf911 said:
is having a Big BatchNode really really bad :)?


Depends on how many objects... With 32 000... Think about it. Batched or not, they still take some memory.

Actually that’s the main problem with the BatchNode right now, it basically doubles the memory usage for a scene, because underlying meshes are not disposed.

Though this is a known issues and we have plans to resolve it.



If your objects are static maybe you should use GeometryBatchFactory.



About the number of geometries in a BatchNode it really depends, and the right number may be hard to find. But it will only affect performance and not memory usage.

You have to understand that it creates a big geometry that is the merge of the sub geoms.

When a sub geom is moved ( transformed to be thorough) the mesh of the batch geometry is updated (position, normal, and tangent (if any) buffer updating). So the smaller the geom the faster will be the buffer updating.

So you have to find the right value between the object count of the scene and the vertex count for each batch geometry.

2 Likes

Thanks for the great thorough explanation… unfortunately my nodes are not static so I can’t use geometryBatchFactory.


About the number of geometries in a BatchNode it really depends, and the right number may be hard to find. But it will only affect performance and not memory usage.



I ran the jConsole and the Resource Monitor and my app thread is not taking more than 500MB and I have allocated 1 GB so it's strange.

.
So you have to find the right value between the object count of the scene and the vertex count for each batch geometry

1- I'm going to write a small code that divides the 32000 objects among 3 or 4 batch nodes and see if that will (although I doubt it will help after your post and the vertex count on each object is high).


2- recommend any other solution?