Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (116)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [SOLVED] Random Sprites Showing  (Read 695 times)
0 Members and 1 Guest are viewing this topic.
Offline Gibbo3771
« Posted 2014-02-18 16:29:04 »

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.

"This code works flawlessly first time and exactly how I wanted it"
Said no programmer ever
Offline trollwarrior1
« Reply #1 - Posted 2014-02-18 19:01:01 »

100% bug in your code.
Offline Troubleshoots

JGO Knight


Medals: 36
Exp: 7-9 months


Damn maths.


« Reply #2 - Posted 2014-02-18 19:01:46 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
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

Why are all OpenGL tutorials written in Brainf**k?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline trollwarrior1
« Reply #3 - Posted 2014-02-18 19:31:59 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
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.
Offline Gibbo3771
« Reply #4 - Posted 2014-02-19 06:11:25 »

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 code works flawlessly first time and exactly how I wanted it"
Said no programmer ever
Offline trollwarrior1
« Reply #5 - Posted 2014-02-19 06:37:01 »

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..
Offline DazKins
« Reply #6 - Posted 2014-02-19 12:06:49 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
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

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

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
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())
    }
}

DazKins

Check out my Dev Blog: http://dazkins.tumblr.com
Offline matheus23

JGO Kernel


Medals: 107
Projects: 3


You think about my Avatar right now!


« Reply #7 - Posted 2014-02-19 12:41:09 »

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

That was intentional, I think.

It's because the OP never instantiated the code variable, too Wink

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline Gibbo3771
« Reply #8 - Posted 2014-02-19 13:16:19 »

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:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
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:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
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.

"This code works flawlessly first time and exactly how I wanted it"
Said no programmer ever
Offline Gibbo3771
« Reply #9 - Posted 2014-02-19 13:37:25 »

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

http://stackoverflow.com/questions/20758218/application-loading-the-wrong-textures-on-opening-again

"This code works flawlessly first time and exactly how I wanted it"
Said no programmer ever
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

radar3301 (12 views)
2014-09-21 23:33:17

BurntPizza (30 views)
2014-09-21 02:42:18

BurntPizza (20 views)
2014-09-21 01:30:30

moogie (20 views)
2014-09-21 00:26:15

UprightPath (28 views)
2014-09-20 20:14:06

BurntPizza (32 views)
2014-09-19 03:14:18

Dwinin (48 views)
2014-09-12 09:08:26

Norakomi (74 views)
2014-09-10 13:57:51

TehJavaDev (102 views)
2014-09-10 06:39:09

Tekkerue (50 views)
2014-09-09 02:24:56
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!