Reputation: 1
public class SplashScreen extends AbstractScreen {
private float countDown;
private final GameManager gameManager;
boolean updating = false;
public SplashScreen(Main main) {
super(main);
gameManager = GameManager.get();
Label loading = new Label("Loading", new Label.LabelStyle(new BitmapFont(), Color.BLACK));
Table table = new Table();
table.setFillParent(true);
table.center();
table.add(loading).expand();
stage.addActor(table);
countDown = 0.5f;
}
@Override
public void show() {
super.show();
main.loadManager();
}
@Override
public void render(float delta) {
super.render(delta);
if (updating) throw new IllegalStateException();
updating = true;
countDown -= delta;
if (countDown < 0.0f && gameManager.assetManager.update()) {
main.onLoadManager();
ScreenManager.get().showScreen(ScreenManager.ScreenEnum.MAIN_MENU);
}
updating = false;
}
}
This code causes an error because render() is called twice almost simultaneously.
Exception in thread "main" java.lang.IllegalStateException
at avseygames.convey.screens.SplashScreen.render(SplashScreen.java:51)
at com.badlogic.gdx.Game.render(Game.java:48)
at avseygames.convey.Main.render(Main.java:41)
at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Graphics.renderWindow(Lwjgl3Graphics.java:103)
at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Graphics.access$000(Lwjgl3Graphics.java:45)
at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Graphics$1.invoke(Lwjgl3Graphics.java:80)
at org.lwjgl.glfw.GLFWFramebufferSizeCallbackI.callback(GLFWFramebufferSizeCallbackI.java:44)
at org.lwjgl.system.JNI.invokePPV(Native Method)
at org.lwjgl.glfw.GLFW.glfwSetWindowMonitor(GLFW.java:3017)
at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Graphics.setFullscreenMode(Lwjgl3Graphics.java:446)
at avseygames.convey.manage.GameManager.setScreenSize(GameManager.java:78)
at avseygames.convey.Main.onLoadManager(Main.java:28)
at avseygames.convey.screens.SplashScreen.render(SplashScreen.java:56)
at com.badlogic.gdx.Game.render(Game.java:48)
at avseygames.convey.Main.render(Main.java:41)
at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Window.update(Lwjgl3Window.java:387)
at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application.loop(Lwjgl3Application.java:193)
at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application.<init>(Lwjgl3Application.java:167)
at avseygames.convey.DesktopLauncher.main(DesktopLauncher.java:15)
FAILURE: Build failed with an exception.
This is just a demonstration of a bug, if you comment out "update", the creation of a new screen is done twice. How to prevent double rendering?
I tried removing the AssetManager, but that's obviously not the point. In any case new Screen is created twice.
Upvotes: 0
Views: 41
Reputation: 1
As a temporary solution in the "render" method
if (updating) throw new IllegalStateException();
I replaced it with
if (updating) return;
Upvotes: 0