Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
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]Crash on Slick util Texture drawing  (Read 3510 times)
0 Members and 1 Guest are viewing this topic.
Offline EmanP

Junior Member


Projects: 2
Exp: 3 years


Satisfaction never guaranteed.


« Posted 2013-04-21 02:37:52 »

Making my sequel to my game, now with 1 player! big issues though. Cry
To be frank, I have no idea what is going on.
I start my game all hunky dory, 160 FPS.
Afterwards, it studders and goes down to a lowly 5-15 FPS.
In those frame hogging moments, some textures are replaced with others.
Then it chrashes. This is my code for the main class.
http://pastebin.java-gaming.org/3b53079405f
 down is my error log from JVM.
http://pastebin.java-gaming.org/b5309804f58

Signed- EmanP
Offline HeroesGraveDev

JGO Kernel


Medals: 260
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #1 - Posted 2013-04-21 02:48:33 »

1. Display.sync() needs to be called each frame, and not at the start.
2. Using an empty try-catch to 'avoid' null-pointers is bad.
3. You are calling updateFPS several times a frame.
4. Your are updating in the draw method? Please separate logic and rendering.
6. PLEASE USE OOP!!

Other than that, I can't help you.

Offline EmanP

Junior Member


Projects: 2
Exp: 3 years


Satisfaction never guaranteed.


« Reply #2 - Posted 2013-04-21 02:56:24 »

1) thanks, no wonder.
2) True, need to clean up after debugging
3) I am notorious for leaving behind tutorials from youtbubers in my code, without cleaning it up afterwards. In result that whole FPS thing is more of a leftover thing.
4) The draw method should be renamed update(), granted.
5) Did you skip this?
6) I do, this is only 1/15 classes I have.

I feel ashamed for having messy coding now :'( (no good for the client anyway.)
I'll re-upload a cleaner version, and simply wait for replies, if my problem isn't already fixed.

Signed- EmanP
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline HeroesGraveDev

JGO Kernel


Medals: 260
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #3 - Posted 2013-04-21 03:00:43 »

I did have a point 5, but I removed it since it was a part of point 6.
All you code is being called from the main() method. You shouldn't really be doing that as it makes it harder to follow stack traces (in case you cut out some lines). Not to mention that you should be using more OOP.

Quote
4) The draw method should be renamed update(), granted.
NO! I said separate logic and rendering.

Btw, it's spelt crash, not chrash.

Offline EmanP

Junior Member


Projects: 2
Exp: 3 years


Satisfaction never guaranteed.


« Reply #4 - Posted 2013-04-21 03:02:20 »

XD ok, fine, more work on cleaning.. got it.

Signed- EmanP
Offline davidc

Senior Member


Medals: 5
Projects: 2



« Reply #5 - Posted 2013-04-21 03:26:02 »

2) True, need to clean up after debugging

I would recommend developing better habits from the beginning, especially since you can do a better job with less effort and fewer lines of code. The idea is to catch exceptions as late as possible by using throws instead of catch. Let them propagate up until either a) you can do something to recover from the error or b) can't throw it any further.

Whatever you do, never just let your code carry on running. You'll just get more errors later on, usually in the form of an avalanche of NullPointerExceptions which make debugging even more difficult
Offline EmanP

Junior Member


Projects: 2
Exp: 3 years


Satisfaction never guaranteed.


« Reply #6 - Posted 2013-04-21 03:36:48 »

Never let your code carry on running? Isn't that the point of stress testing? If my code didn't need to carry on running, It wouldn't be a game. Problem is there are no Exceptions, but rather Java Virtual Machine crashes. which doesn't pinpoint exactly where the fault was caused.  Sad

Signed- EmanP
Offline HeroesGraveDev

JGO Kernel


Medals: 260
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #7 - Posted 2013-04-21 03:40:04 »

There are no exceptions because you silenced them all with your empty catch blocks.

Whenever you have a try-catch, make sure you always put the stack trace somewhere, whether you log it or just print it out.
And if you have a try-catch for a RuntimeException, you are likely to be doing something wrong (unless you're using I/O).

Offline davidc

Senior Member


Medals: 5
Projects: 2



« Reply #8 - Posted 2013-04-21 03:58:15 »

Never let your code carry on running? Isn't that the point of stress testing? If my code didn't need to carry on running, It wouldn't be a game. Problem is there are no Exceptions, but rather Java Virtual Machine crashes. which doesn't pinpoint exactly where the fault was caused.  Sad

Line 492 achieves nothing but turning off an exception. That's like turning off a fire alarm and praying that the fire doesn't spread. Even if you were to put a printStackTrace or something similar in there, it's still no better than turning off the fire alarm and writing "there's a fire" on a post-it note and walking away. At some point in time the program will fail spectacularly. You've just delayed the inevitable.

If your program starts to fail, you want it to stop so you can see what is causing the failure. Even in stress testing, you want to know why your program reached it's limit. Only then can you decide if it's a problem you can deal with.
Offline EmanP

Junior Member


Projects: 2
Exp: 3 years


Satisfaction never guaranteed.


« Reply #9 - Posted 2013-04-21 04:07:27 »

All too true, removed that exception, as it was no longer needed, added printstacktraces to all exceptions I did need. I will finish up, and upload the new version.

Signed- EmanP
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline matheus23

JGO Kernel


Medals: 108
Projects: 3


You think about my Avatar right now!


« Reply #10 - Posted 2013-04-21 08:34:30 »

Quote
4) The draw method should be renamed update(), granted.
NO! I said separate logic and rendering.

Oh well... separating logic and rendering is even much more than only making two methods for it. It's certainly helping, just like every other kind of structuring code and abstracting stuff away and putting stuff in methods, but it's not what all those people saying 'separate logic and rendering!' say.

[excursion]
What those people are talking about is that logic is working without rendering. This means, you could simply remove the rendering step and let the updating to what it is supposed to. This also means, that no LWJGL (or any rendering-relevant code or lib) is used during the updating.

This comes in incredibly helpful if you want to network your game. That's what the MVC patterns were made for. It's awesome'er than I thought Wink
[/excursion]

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline EmanP

Junior Member


Projects: 2
Exp: 3 years


Satisfaction never guaranteed.


« Reply #11 - Posted 2013-04-21 13:31:13 »

EDIT:
 Added render conservation system, not rendering if texture is outside the screen (still doesn't solve lag),
 Removed much not needed code,
 Separated drawing from updating gameobjects,
New code here:
 http://pastebin.java-gaming.org/530909f4850
Crash is still the same.
 

Signed- EmanP
Offline HeroesGraveDev

JGO Kernel


Medals: 260
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #12 - Posted 2013-04-21 18:46:09 »

What exceptions are you getting now?
(If you get any)

Try cutting down on the amount of stars and asteroids etc. and see if that helps.


@matheus23: For me at least, separating logic and rendering methods seems to separate logic and rendering completely. I assumed it would be the case for everyone. (Now I'm wondering how you could possibly mix logic and rendering when they happen in different methods)

Offline EmanP

Junior Member


Projects: 2
Exp: 3 years


Satisfaction never guaranteed.


« Reply #13 - Posted 2013-04-21 19:02:04 »

No exceptions, simply java crashing. A quote from the JVM error log
1  
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows

While stress testing, I tested prior to this post, removing entities like meteors, stars, the planet, and removing any one of them still lead to a crash. I suspect it is slick util, as the player's texture will always switch to a weapon texture, just before crashing. Clueless

Signed- EmanP
Offline HeroesGraveDev

JGO Kernel


Medals: 260
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #14 - Posted 2013-04-21 19:04:18 »

What happens when you comment out the rendering code (glBegin-glEnd)?

Offline matheus23

JGO Kernel


Medals: 108
Projects: 3


You think about my Avatar right now!


« Reply #15 - Posted 2013-04-21 19:08:07 »

@matheus23: For me at least, separating logic and rendering methods seems to separate logic and rendering completely. I assumed it would be the case for everyone. (Now I'm wondering how you could possibly mix logic and rendering when they happen in different methods)

Its already this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
public class Entity {
    protected final Sprite sprite;
    protected final Vector2f pos;
    protected final Vector2f velocity;
 
    public Entity(Sprite sprite) {
        this.sprite = sprite;
        // ...
       // do stuff with pos and velocity
   }
   
    public void update() {
        pos.add(velocity);
    }
   
    public void render(SpriteBatch batch) {
        sprite.draw(batch);
    }
}


Does this code run without LibGDX? Nope. We need a Sprite in the constructor. We cannot let it run without having LibGDX / A sprite.

The 'correct' way:
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  
// Horrible code formatting. Formatted for low LOC
// The model:
public class Entity { protected final Vector2f pos, velocity; /* more stuff */ }
// The controller:
public class EntityController {
    protected final Entity player;
    protected boolean isMoving;
    // ...
   public void update(Input input) {
        applyInput(player);
    }

    public boolean isMoving() { return isMoving; }
}
// The view:
public class EntityView {
    protected final Sprite playerMoving;
    protected final Sprite playerStanding;

    public void render(EntityController contr, SpriteBatch batch) {
        Vector2f entityPos = contr.getEntity().getPos();
        if (contr.isMoving()) {
            playerMoving.draw(batch, entityPos.x, entityPos.y);
        } else {
            playerStanding.draw(batch, entityPos.x, entityPos.y);
        }
    }
}


People argue a lot about how MVC for games should look like... This is one possibility for separating logic and rendering.

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline EmanP

Junior Member


Projects: 2
Exp: 3 years


Satisfaction never guaranteed.


« Reply #16 - Posted 2013-04-21 19:10:45 »

stress testing now.

Signed- EmanP
Offline EmanP

Junior Member


Projects: 2
Exp: 3 years


Satisfaction never guaranteed.


« Reply #17 - Posted 2013-04-21 19:28:38 »

What happens when you comment out the rendering code (glBegin-glEnd)?
The game ran, it stopped, no error message, huge lag, no JVM crash log. Eclipse thought the game was still running, had to stop it on eclipse.

Signed- EmanP
Offline HeroesGraveDev

JGO Kernel


Medals: 260
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #18 - Posted 2013-04-21 19:33:53 »

Use jvisualvm to find the bottleneck.

It should be part of the JDK.

Offline EmanP

Junior Member


Projects: 2
Exp: 3 years


Satisfaction never guaranteed.


« Reply #19 - Posted 2013-04-21 19:35:06 »

Use jvisualvm to find the bottleneck.

It should be part of the JDK.

jvisualvm?

Signed- EmanP
Offline HeroesGraveDev

JGO Kernel


Medals: 260
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #20 - Posted 2013-04-21 19:40:01 »

Found some new stuff:

1. Use a normal ArrayList. For iterating, create one copy, and iterate over that. Any adds/removals should be done to the original list
2. You are loading textures EVERY FRAME! I'm not entirely sure how SlickUtil works, but maybe you should save the textures somewhere.

To lauch jvisualvm (Windows) Alt-R, type in jvisualvm, press enter.
Find you application, double click, look at the graphs etc. do some sampling/profiling. Find wheter it's CPU or RAM usage that's causing the problem.

Offline EmanP

Junior Member


Projects: 2
Exp: 3 years


Satisfaction never guaranteed.


« Reply #21 - Posted 2013-04-21 19:52:46 »

Found some new stuff:
1. Use a normal ArrayList. For iterating, create one copy, and iterate over that. Any adds/removals should be done to the original list
2. You are loading textures EVERY FRAME! I'm not entirely sure how SlickUtil works, but maybe you should save the textures somewhere.
To lauch jvisualvm (Windows) Alt-R, type in jvisualvm, press enter.
Find you application, double click, look at the graphs etc. do some sampling/profiling. Find wheter it's CPU or RAM usage that's causing the problem.
1) A normal arraylist gives me a ConcurrentModificationException. I read that I can't catch it, because catching it is only for debugging, and shouldn't be part of the final code.
2) I am saving the textures in the objects' classes..? the only time I am loading textures is in the creation of new objects, or while evolving a star(nebula-star-pulsar-etc..)
3) I don't think jvisualvm works with windows XP 

I'll try stress testing without stars evolving.

Signed- EmanP
Offline HeroesGraveDev

JGO Kernel


Medals: 260
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #22 - Posted 2013-04-21 20:02:00 »


1) A normal arraylist gives me a ConcurrentModificationException. I read that I can't catch it, because catching it is only for debugging, and shouldn't be part of the final code.
2) I am saving the textures in the objects' classes..? the only time I am loading textures is in the creation of new objects, or while evolving a star(nebula-star-pulsar-etc..)
3) I don't think jvisualvm works with windows XP  

I'll try stress testing without stars evolving.

1.

Change
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
private static void update()
   {
      if(!player.dead)
      {
         for(SpaceObject so : objects)
         {
            if(so.dead)
            {
               so = null;
               objects.remove(so);
            }
            else
            {
               if(!so.equals(player))
                  so.update();
            }
         }
         player.update();
      }
   }

to:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
private static void update()
   {
      if(!player.dead)
      {
         ArrayList<SpaceObject> copyOfObjects = new ArrayList<SpaceObject>(objects);
         for(SpaceObject so : copyOfObjects)
         {
            if(so.dead)
            {
               so = null;
               objects.remove(so);
            }
            else
            {
               if(!so.equals(player))
                  so.update();
            }
         }
         player.update();
      }
   }


Then you can use a normal arraylist.

2. You evolve all stars every frame. Didn't see the random.nextInt().

But still, you need to save the textures somewhere, you're loading the same texture over and over again each time you call loadTexture().

3. Okay, nm.

Offline EmanP

Junior Member


Projects: 2
Exp: 3 years


Satisfaction never guaranteed.


« Reply #23 - Posted 2013-04-21 20:11:26 »

2. You evolve all stars every frame. Didn't see the random.nextInt().
But still, you need to save the textures somewhere, you're loading the same texture over and over again each time you call loadTexture().
Just finished stress testing, frames still dropped, but at exponentially slower rates than before Shocked. I think my issue has been solved, I all need is to implement the changes Cheesy. I will use the Array List, and maybe make an enum of textures, or simply define all the possible textures in the class, not just the default. So many months of development went down the drain after only ~11 days of programming Cry. I'll write in the needed code, stress test, and tell you the results.

Signed- EmanP
Offline davidc

Senior Member


Medals: 5
Projects: 2



« Reply #24 - Posted 2013-04-22 04:42:09 »


1) A normal arraylist gives me a ConcurrentModificationException. I read that I can't catch it, because catching it is only for debugging, and shouldn't be part of the final code.

I'm not sure I get what you're saying. Catching is not for debugging. Catching is for trying to recover from or do something useful with an error. If you can't recover from the error, don't catch it. If you want to debug potential errors, set your debugger to break on exceptions.

As for the ArrayList problem, use an iterator to traverse a collection if you think you might want to remove something from the collection. I've mentioned it before here with an example of how it's done.
Offline EmanP

Junior Member


Projects: 2
Exp: 3 years


Satisfaction never guaranteed.


« Reply #25 - Posted 2013-04-22 17:01:44 »

As for the ArrayList problem, use an iterator to traverse a collection if you think you might want to remove something from the collection. I've mentioned it before here with an example of how it's done.
Ok, but no need, I got it figured out now, thanks.

Signed- EmanP
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.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (19 views)
2014-09-24 16:12:06

Grunnt (44 views)
2014-09-23 14:38:19

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

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

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

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

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

BurntPizza (54 views)
2014-09-19 03:14:18
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!