Slick Forums

Discuss the Slick 2D Library
It is currently Thu Apr 17, 2014 9:33 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Fri Nov 11, 2011 2:09 am 
Offline
User avatar

Joined: Mon Jun 20, 2011 4:28 pm
Posts: 71
so there is a memory leak in org.newdawn.slick.opengl.renderer.ImmediateModeOGLRenderer

specifically in glColor4f(float r, float g, float b, float a)

I use g.setColor A LOT, which eventually calls this method
This floods my memory ~ around 1.8MB per second

the Class has a variable for the current Color, which is good: private float[] current = new float[] {1,1,1,1};

However, whenever you call glColor4f(float r, float g, float b, float a), it looks like this

Code:
public void glColor4f(float r, float g, float b, float a) {
    a *= alphaScale;
      
    //current = new float[] {r,g,b,a};
    GL11.glColor4f(r, g, b, a);
    }


So yeah the new keyword causes the leak.

Fix:
Code:
public void glColor4f(float r, float g, float b, float a) {
    a *= alphaScale;
    current[0] = r;
    current[1] = g;
    current[2] = b;
    current[3] = a;
    GL11.glColor4f(r, g, b, a);
    }


how much difference ? much. now my memory doesn't even raise at all when nothing is happening.

Please, who ever has access to SVN, fix this. Having "my own" Slick version isn't cool at all when Slick gets other improvements and I have to manually add them.


Top
 Profile  
 
PostPosted: Fri Nov 11, 2011 8:45 pm 
Offline
Game Developer

Joined: Sun Nov 12, 2006 11:18 pm
Posts: 890
Location: Germany
It's not really a memory leak. It just creates a bunch of arrays that are cleared by the garbage collector the next time it runs.
It just eats up lots of memory for a while if you call it too often :wink:

But of course your fix does make sense and speeds things up so I just committed it to SVN.

Please check and reply if it's working for you.

Cheers,
Tommy

_________________
Right Angle Games | Marte Engine
Back to the past | Star Cleaner | SpiderTrap


Top
 Profile  
 
PostPosted: Sun Nov 13, 2011 10:30 pm 
Offline
User avatar

Joined: Mon Jun 20, 2011 4:28 pm
Posts: 71
Yeah it's as much a memory leak as you can achieve in java... well maybe you can do worse

anyway thanks, works great !


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group