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

2012/4/16

Music playing

Gazzzah Gazzzah

2012/4/16

#
I have a game that I've written up. It's a work in progress and it's getting pretty big. I frequently have to restart Greenfoot due to Java's 'out of memory' deal. I am planning on implementing an in game music player that plays a set list of songs in a shuffled order and can be turned off. I haven't written any form of music player yet but I'm concerned about the performance and memory issues associated with this. Are there any tips or references you can give me regarding music playing in game and how to do so EFFICIENTLY (maybe a certain format or a certain way of going about it) That would be greatly appreciated. Thanks
nccb nccb

2012/4/16

#
You shouldn't really get out of memory errors. This could either be a problem with Greenfoot/JDK, or an issue with the way you've programmed your scenario (e.g. keeping too many songs in memory). Could you share your scenario (probably without music tracks) or say a bit more about when the out of memory problems occur?
Gazzzah Gazzzah

2012/4/16

#
The out of memory problems occur usually after several compiles (I suspect mainly after editing my world class). I have put a lot of effort into graphics and sounds which I think is the main thing chewing up resources. If I post it so you can see it do you need the source code. I'm a bit hesitant about posting that as of yet.
Gazzzah Gazzzah

2012/4/16

#
This is one of the errors I get after compiling (sometimes) java.lang.OutOfMemoryError: Java heap space at java.awt.image.DataBufferInt.<init>(DataBufferInt.java:41) at java.awt.image.Raster.createPackedRaster(Raster.java:458) at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1015) at java.awt.GraphicsConfiguration.createCompatibleImage(GraphicsConfiguration.java:163) at greenfoot.util.GraphicsUtilities.toCompatibleTranslucentImage(GraphicsUtilities.java:285) at greenfoot.util.GraphicsUtilities.loadCompatibleTranslucentImage(GraphicsUtilities.java:227) at greenfoot.GreenfootImage.loadURL(GreenfootImage.java:260) at greenfoot.GreenfootImage.loadFile(GreenfootImage.java:287) at greenfoot.GreenfootImage.<init>(GreenfootImage.java:109) at greenfoot.World.setBackground(World.java:195) at gameScreen.removeButtons(gameScreen.java:625) at gameScreen.addMainMenu(gameScreen.java:607) at gameScreen.<init>(gameScreen.java:144) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at greenfoot.core.Simulation.newInstance(Simulation.java:520) at greenfoot.platforms.ide.WorldHandlerDelegateIDE$3.run(WorldHandlerDelegateIDE.java:406) at greenfoot.core.Simulation.runQueuedTasks(Simulation.java:411) at greenfoot.core.Simulation.maybePause(Simulation.java:269) at greenfoot.core.Simulation.runContent(Simulation.java:201) at greenfoot.core.Simulation.run(Simulation.java:194)
nccb nccb

2012/4/16

#
That message is the world background tipping the memory use over the edge. But of course, it may be something else that is actually consuming the memory. There did used to be a JDK bug that would sometimes incorrectly retain the memory, but if you're doing a lot with images and sounds, that might be a likely candidate. If you're not happy about publishing the source code, you can alternatively email it to nccb@greenfoot.org so I can take a look to try to help.
Gazzzah Gazzzah

2012/4/16

#
Alright, I emailed it to you.
nccb nccb

2012/4/16

#
I gave it a try, and I was able to reproduce the error if I reset a few times quite quickly. Your scenario is using quite a few images, but the problem is being exacerbated by some caching that Greenfoot is doing, which prevents garbage collection from clearing up the old images. We've added a fix to Greenfoot 2.2.0 (which should be out in the next few weeks) that should help alleviate the problem.
Gazzzah Gazzzah

2012/4/16

#
Yay! Sounds good! Looking forward to it!
Gazzzah Gazzzah

2012/4/17

#
I've written in a music player, it's working fine. A lot better than expected
You need to login to post a reply.