Lags appearing once at game startup


After having loaded all the necessary assets, when my game starts, the screen is black (sometimes showing the hud), and stays that way for a while…the engine is doing something but what ?? the more I add thing in the scenegraph, the longer it takes to process “something”

also if I turn the camera to some objects, the game freezes for one or two seconds, then it goes to normal, it does that only once,so no big deal, but not a great user experience

I guess it has something to do with octree/bsp/data caching somethign… ???
I cant find what is going wrong as there is no profiler in jmonkey ide like in netbeans

any advice?


Is probably a huge indicator that it’s “something” that has to do with how many objects are on your scene graph.

The slow camera movement suggests maybe too many objects in the scene.

But it’s tough to guess what’s wrong without a crystal ball.

1 Like

The game freezes because it’s loading assets,probably it’s the same reason because moving the camera to an object that you haven’t watch yet freezes too.

yeah, I wish I could do a profiling but…
but it cannot be a “too many objects” issue, since it just freezes once and then everything runs smothly

it’s like the objects entering in the frustum for the first time were initialized/processed somehow

does’nt make any sens, I load my assets before it happens and after all assets are loaded, the game freezes (also I log everything, so it happens once the whole game is setup/loaded)
so unless the engine doesn’t really load the object and postpone it until the object gets in the frustum…and I dont want that to happen, no commercial game do that

If the lag only occurs when object are in the frustrum then a possible source is the models are high in triangles or vertices.

no… if it was the case, I would have a lower FPS everytime I look at the object

IT ONLY HAPPEN ONCE, but for a noticable amount of time

I optimized some things at startup
I also found that an appstate was loading my hud xml so it explained the huge freeze on startup

but I still have the object apearing lag wich I really cant explain

We can only guess the problem if you don’t post any code. And even make a guess is quite hard since you didn’t even say which type of game you are developing (voxel based maybe?) nor if you are using any shader, control, physics engine, lod […]

My crystal ball says texture loading in a non gpu nice format and with mipmap generation enabled.

I just thought there was some octree/camera preprocessing on startup

code is copyrighted, assets too, so please understand it

I tracked the problem and it seems the first time viewports/scenes/objects are rendered, it is somehow slow, then it goes away, I have no idea why

also it would be ten times easier for me if I could profile it, but since that option has been removed from netbeans fork…

I also have to use my crystal ball

gpu nice format ? with caviar and a nice bottle of wine ? all my textures are power of two

When you face those type of problem the first thing to do is try to isolate them, so it would be a good idea write a simple test case that you can share here with only the part that doesn’t work, so people can help you.
Maybe you are just doing something wrong but without seeing the code it’s quite hard to understand what.

It’s a little funny how random the answers are with only one actually helpful one.

When you load an object, the textures are in system memory… in whatever format they were loaded. When the object is displayed for the first time, it has to transfer those textures to GPU memory and potentially generate mipmaps. This can take a while if your textures are large or there are a lot of them.

Some formats are already in a GPU friendly format or already have mipmaps generated… in that case it’s only the cost of the memory copy.

There is a way to preload these things into the GPU at the time you choose instead of at random runtime… but if you have a lot of these really large textures then ultimately it may not help as they could get shifted in and out I guess based on how much GPU memory is actually available.

Edit: note that some of the answers are partially right about triangles since those buffers have to be transferred also… but usually that’s not a cause of lag unless there are a lot of them. (which is why the good paging systems only add one mesh at a time per frame and stuff to keep from breaking frame as you walk around… but they also share a common set of textures)

The freez can be also caused by the garbage collector with a “memory leak” you can use VisualVM to see the heap usage.

In the case the OP describes it is extremely unlikely to be GC. For one, it is view dependent and clears up after. GC issues would be the exact opposite… they would get worse over time and not better.

OP exactly 100% describes what exactly precisely happens when a large object with a big mip-mapped texture enters the field of view for the first time. So my bet is on that.

read above, I said I was trying to track the problem

tell me about it, actually I was hoping you come in an give me some hint ha ha ha
I also think it is the textures since the problem grew as I used better resolution textures

how do you preload textures in gpu ? mine are 1024x1024x32 , how do I create/setup mipmaps ?

edit : I found this :


You mean the Java profiler? It’s weird because when I wanted it, I just ticked the box and got the plugin installed without issue. What version of the SDK are you running?