[SOLVED] Random Sprites Showing

Eh I have literally NO IDEA wtf is going on here but the only thing I have changed is moved from BitmapFont images to the GDX FreeType generator.

This only happens when I run it on Android and only after it has been run once and then quit or you die and it returns to menu.

Basically all my menu button drawables get replaced with the BitmapFont sheet, in game the sprites are random, my rocks are my character (at different frames), the BitmapFont sheet or just a black or red box.

What the hell is going on?

[SOLUTION]

Dispose of your shit! Always dispose of textures and reload them upon bringing the application to the front.

100% bug in your code.


public class User {

    private Code code;

    public static Code getCode() {
        return code;
    }

    public static void main(String[] args) {
        User gibbo3771 = new User();
        System.out.println(gibbo3771.getCode().toString())
    }
}

I get a nullpointerexception. :emo:

Sorry, you can’t run that code. It would give no field found error, because you cannot access non-static field from static methods.

I will post some code if I can narrow it down but it works fine on desktop, it only occurs on android if you hit the back key and go back on. As if I just loads random sprites from ram.

I have no idea where this could be occurring, I can’t dump 1000s of line of code Lol, I’ll try and get more detail when I’m home and screen shots.

This might be due to wrong texture/vertex buffer being bound.
I had kinda same problem. After I would hit start game button, 1 frame would display random textures, which looked really annoying. The problem was that when I would hit the button, I would create new texture, which would automatically be bound, causing my to render from wrong texture for 1 frame. Or something like that…

Ontop of what trollwarrior suggested, you never actually instantiate the code variable, it should look more like this:


public class User {

    private Code code = new Code();

    public static Code getCode() {
        return code;
    }

    public static void main(String[] args) {
        User gibbo3771 = new User();
        System.out.println(gibbo3771.getCode().toString())
    }
}

That was intentional, I think.

It’s because the OP never instantiated the code variable, too :wink:

Hm I think I have found the problem but not in code.

This only happens if the app is sent to the background on the main menu, this does not happen on the game screen it simply pauses.

If I terminate the game using the task manager and open it back up, it loads fine. So it seems that upon bringing the app back to the front, it is as if it gets the images stored in memory mixed up, if that is possible.

Here is my MainMenu class:

public class MainMenuScreen implements Screen {

	public UIManager uiManager;

	public MainMenuScreen() {
		uiManager = new UIManager();
		uiManager.initMain();
		
		Gdx.input.setInputProcessor(uiManager);
		Gdx.input.setCursorCatched(false);
		Gdx.input.setCatchBackKey(true);
		Gdx.input.setCatchMenuKey(true);
	}

	@Override
	public void render(float delta) {
		Gdx.gl.glClearColor(0, 0, 0, 1);
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

		uiManager.act(delta);
		uiManager.draw();
//		Table.drawDebug(uiManager);

	}

Here is my UIManager thing, basically just the Scene2D stage:

public class UIManager extends Stage {

	/** Camera */
	public OrthographicCamera cam;

	/** Skin */
	public Skin skin;

	/** Main table */
	public Table table;

	public UIManager() {

		cam = new OrthographicCamera(640, 480);
		cam.setToOrtho(false);
		setCamera(cam);

		skin = new Skin();
		table = new Table(skin);
		table.debug();

		if (Gdx.app.getType() == ApplicationType.Desktop) {
			AssetLoader.BUTTON_UP.setSize(256, 128);
			AssetLoader.BUTTON_DOWN.setSize(256, 128);
		}

		skin.add("buttondown", AssetLoader.BUTTON_DOWN);
		skin.add("buttonup", AssetLoader.BUTTON_UP);

	}

	public void initMain() {

		TextButtonStyle style = new TextButtonStyle();
		style.font = Gdx.app.getType() == ApplicationType.Desktop ? AssetLoader
				.fontGenerator("data/font/pricedown.ttf", 40) : AssetLoader
				.fontGenerator("data/font/pricedown.ttf", 64);
		style.down = skin.getDrawable("buttondown");
		style.up = skin.getDrawable("buttonup");
		style.unpressedOffsetX = -2;
		style.unpressedOffsetY = 2;

		LabelStyle labelStyle = new LabelStyle();
		if (Gdx.app.getType() == ApplicationType.Desktop) {
			labelStyle.font = AssetLoader.fontGenerator(
					"data/font/pricedown.ttf", 48);
		} else {
			labelStyle.font = AssetLoader.fontGenerator(
					"data/font/pricedown.ttf", 156);
		}

		Label heading = new Label("Falling Rocks", labelStyle);
		TextButton play = new TextButton("PLAY", style);
		TextButton highscores = new TextButton("HIGHSCORES", style);
		TextButton exit = new TextButton("EXIT", style);

		play.addListener(new ClickListener() {
			@Override
			public void clicked(InputEvent event, float x, float y) {
				super.clicked(event, x, y);
				((Game) Gdx.app.getApplicationListener())
						.setScreen(new GameScreen());
			}
		});

		highscores.addListener(new ClickListener() {
			@Override
			public void clicked(InputEvent event, float x, float y) {

			}
		});

		exit.addListener(new ClickListener() {
			@Override
			public void clicked(InputEvent event, float x, float y) {
				Gdx.app.exit();
			}
		});

		table.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
		table.setFillParent(true);

		table.add(heading).row();
		table.add(play).row();
		table.add(highscores).row();
		table.add(exit);
		addActor(table);

	}

}

I ran some tests, basically printing out the button textures and fonts to the console and the memory ID does not change.

Hm, found a stack overflow question with the exact same problem I am having.