This site requires JavaScript, please enable it in your browser!
Greenfoot back
Super_Hippo
Super_Hippo wrote ...

2014/11/10

Increasing java heap space

Super_Hippo Super_Hippo

2014/11/10

#
Hi, I am creating a game like True Color. So I need an actor and its image is showing an arc which is increasing to fill until it is like a circle at the end. I found methods of increasing arcs like in the object "Graphics", but I don't know how to use it in a GreenfootImage. I also found this scenario which has a nice way of creating arcs. Doesn't work for me though, because they have to be a full circle at the end. Well, I found out how to make the arc. It was easier than I thought. I am saving 360 images for each color so it will change the image when filling the arc. I am saving the images so I don't have to create such an image every act-cycle. This is working as it should. The problem is, that when I compile the scenario a few times, it crashes and a "java heap space" error pops up. I found this post related to the problem saying that I have to change the "greenfoot.defs" file located in ".../Greenfoot/lib". I find the file, I can open it, I find the line (which is a bit different to the one showed in the post), can change it, but I can't save it. It asks to overwrite the file, I click OK and then it shows me an error message with "access denied" (or something like that probably, just trying to translate it to English). The folder is write-protected/read-only, so that maybe prevent me from saving there. If I remove the marker in the write-protected box, I can do that with administrator rights. But if I open the properties of the folder again, it still says that it is write-protected, so nothing changed and I still can't save it. Does someone can tell me how I can change the greenfoot.defs file?
davmac davmac

2014/11/10

#
Save it somewhere else, then use Windows Explorer to copy the modified file over the original.
danpost danpost

2014/11/10

#
I came up with this for a full circle:
import greenfoot.*;

public class Arc extends Actor
{
    GreenfootImage full = new GreenfootImage(100, 100);
    GreenfootImage half = new GreenfootImage(100, 50);
    int angle;
        
    public Arc()
    {
        full.fillOval(0, 0, 99, 99);
        half.drawImage(full, 0, -50);
        updateImage();
    }

    public void act()
    {
        if (Greenfoot.isKeyDown("space"))
        {
            angle = (angle+1)%360;
            updateImage();
        }
    }
    
    private void updateImage()
    {
        GreenfootImage img = new GreenfootImage(100, 100);
        GreenfootImage arc = new GreenfootImage(half);
        img.drawImage(arc, 0, 50);
        img.rotate(angle%180);
        GreenfootImage interimArc = new GreenfootImage(100, 50);
        interimArc.drawImage(img, 0, 0);
        img.clear();
        img.drawImage(interimArc, 0, 0);
        if (angle >= 180)
        {
            img.drawImage(half, 0, 50);
            setRotation(180);
        }
        else setRotation(0);
        setImage(img);
    }
}
Maybe you can edit it for your needs.
Super_Hippo Super_Hippo

2014/11/12

#
Thank you davmac, I can change it like this. But now, I have another question: In the other post, it was said that the default value is 64mb and with adding -Xmx256M, it would be increased to 256mb. What I experience is, that even if I change it to 2024mb, it is still worse than the default one. At 4048, it seems to be quite similar to the default one. I also don't think that I can increase it to infinity. Is the default one really (still) 64mb? Well done, danpost! You always have a different approach of doing similar things without producing much code (and sometimes not easy to understand). The problem about that is, that the pixels at the edge of the circle change due to the rotation. Oh, and I actually don't have a fully filled circle, only like a bar (or however this would be called). Btw, my version is:
  • create a colored circle
  • create a small white circle
  • according to the state of the bar (so how far it should be filled), save the following points
    • middle (always)
    • top
    • left
    • bottom
    • right
    • current "position" (always)
  • fill the polygon of this points in white
So it looks a bit like this: http://oi57.tinypic.com/29wolg6.jpg The points are a bit more outside, so the bar is not visible where it shouldn't be. When the (here red) polygon is filled with white, only the bar is visible.
davmac davmac

2014/11/12

#
Is the default one really (still) 64mb?
No, that changed in some Java version quite a while back. The default is now dependent on how much system RAM you actually have. Google it if you want specifics.
dangjavageek dangjavageek

2014/11/12

#
determined at run time as davmac suggests, you can run this on your machine to get an idea: Java 6 -> java -XX:+PrintFlagsFinal -version | grep HeapSize uintx ErgoHeapSizeLimit = 0 {product} uintx InitialHeapSize = 0 {product} uintx LargePageHeapSizeThreshold = 134217728 {product} uintx MaxHeapSize = 132120576 {product} Java 7 -> java -XX:+PrintFlagsFinal -version | grep HeapSize uintx ErgoHeapSizeLimit = 0 {product} uintx HeapSizePerGCThread = 87241520 {product} uintx InitialHeapSize := 268435456 {product} uintx LargePageHeapSizeThreshold = 134217728 {product} uintx MaxHeapSize := 4294967296 {product} Java 8 -> java -XX:+PrintFlagsFinal -version | grep HeapSize uintx ErgoHeapSizeLimit = 0 {product} uintx HeapSizePerGCThread = 87241520 {product} uintx InitialHeapSize := 268435456 {product} uintx LargePageHeapSizeThreshold = 134217728 {product} uintx MaxHeapSize := 4294967296 {product}
Super_Hippo Super_Hippo

2014/11/12

#
I just found out that I can change it as a parameter in the java control panel. Testing out dang's suggestion (which took me some time to figure out how to see so many lines without having the top lines removed already), it doesn't seem to change anything though. Actually I don't really know what all of these things mean. (Initial- and max heap size is something I can understand, but I have no idea about the rest.) It is at over 3gb, so actually it should be fine I think.
Super_Hippo Super_Hippo

2015/1/23

#
Could it be that you changed something related to the java heap space in 2.4.1 update? Of course the line was defaulted again with the update, so my game didn't load again in Greenfoot, so I wanted to change this "Xmx" value to something higher again. (bluej.vm.args=-Xincgc -Dawt.useSystemAAFontSettings=on -Xmx1207M) Any value equal to or higher than 1207M creates an error when launching Greenfoot and it doesn't launch. ("Greenfoot was unable to create a virtual machine (VM) to execute scenarios. Often this is caused by overly restrictive firewall setting. Please see for more information.") The possible 1206M are much less than it was with 2.4.0. There I could open my True Color game. Now with the highest "XmX" it is only loaded like 30%. I hoped I could change this heap size with a CFF explorer. There I changed the value of SizeOfStackReserve, SizeofStackCommit, SizeOfHeapReserve and SizeOfHeapCommit to something high, but it didn't change anything. (Not that I would understand what those values represent, but it looked like they had something to do with it...) How is it possible to increase it to where it was with 2.4.0? (Btw, I found in the Explorer in the configuration files that the "assemblyIdentity version" is 2.4.0.0, it probably should be 2.4.1.0, shouldn't it?
davmac davmac

2015/1/23

#
Could it be that you changed something related to the java heap space in 2.4.1 update?
We did not. However, the bundled Java version is different between Greenfoot 2.4.0 and Greenfoot 2.4.1, and this might account for the change. If you want to run Greenfoot with an arbitrary Java version, you can download the version for "Windows, without bundled JDK". Note that you will need to have installed a JDK separately.
(Btw, I found in the Explorer in the configuration files that the "assemblyIdentity version" is 2.4.0.0, it probably should be 2.4.1.0, shouldn't it?
Yes, it looks like the team member who built the release forgot to update the version in the build manifest. However, this should not have any affect on Greenfoot's operation.
Super_Hippo Super_Hippo

2015/1/24

#
Thank you, this helped! Now I can open my game in Greenfoot again once before it crashes.
You need to login to post a reply.