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

2016/5/2

Out Of Memory error on compile

trimil trimil

2016/5/2

#
In the game I am working on, when I compile my program, it comes up with this in the Terminal Window:
java.lang.OutOfMemoryError: Java heap space
	at java.awt.image.DataBufferInt.<init>(DataBufferInt.java:75)
	at java.awt.image.Raster.createPackedRaster(Raster.java:467)
	at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1032)
	at java.awt.GraphicsConfiguration.createCompatibleImage(GraphicsConfiguration.java:186)
	at greenfoot.util.GraphicsUtilities.createCompatibleTranslucentImage(GraphicsUtilities.java:189)
	at greenfoot.GreenfootImage.<init>(GreenfootImage.java:140)
	at Scroll.setDirection(Scroll.java:43)
	at Scroll.setActorAt(Scroll.java:107)
	at Level.<init>(Level.java:28)
	at Levels.<init>(Levels.java:27)
	at Start.<init>(Start.java:23)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
	at greenfoot.core.Simulation.newInstance(Simulation.java:607)
	at greenfoot.platforms.ide.WorldHandlerDelegateIDE$4.run(WorldHandlerDelegateIDE.java:441)
	at greenfoot.core.Simulation.runQueuedTasks(Simulation.java:494)
	at greenfoot.core.Simulation.maybePause(Simulation.java:299)
	at greenfoot.core.Simulation.runContent(Simulation.java:212)
	at greenfoot.core.Simulation.run(Simulation.java:205)
When I restart Greenfoot, although, this problem does not happen until I compile it again. Diagram: Start Greenfoot ---> World is created ---> Compile ---> World throws an exception In the list of methods, the last method in a class I can change is the SetDirection() method in Danpost's Scroll class. I will soon be uploading this scenario.
trimil trimil

2016/5/2

#
danpost danpost

2016/5/3

#
I think the problem is that you have too many large images in memory at one time. It just might be because you are creating all twenty level worlds when you create the buttons in the Levels class. Since the LevelButton objects are to create a Level world be begin with, maybe you should drop the World (or Level) parameter for new LevelButton objects and just have the button automatically create a new Level world when clicked. That should save a lot of heap space.
trimil trimil

2016/5/3

#
Thanks for the solution. In the future, I am going to have each level be a different class, so instead of passing the world as a parameter I am passing the class.
danpost danpost

2016/5/3

#
trimil wrote...
Thanks for the solution. In the future, I am going to have each level be a different class, so instead of passing the world as a parameter I am passing the class.
You could just pass an int value (to represent what level to go to) and use a switch statement (in the class of the button) to create what level is required when the button is clicked.
trimil trimil

2016/5/3

#
Nah, I like using the reflect classes.
You need to login to post a reply.