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

2018/1/29

Heap space after a few level restarts

1
2
3
Paul12345 Paul12345

2018/1/30

#
I have a method that adds objects every 600 acts if 1 object of that typed is removed from the world (to make them respawn). And if i have 2 objects from that class and i remove one when that one respawns it also adds another one on top of that which wasn't removed . But even if i don't add those objects on the world i still get memory error.
danpost danpost

2018/1/30

#
Is the first world a menu type world? What are Elev, Viata0, Viata1 and Viata2 for?
Paul12345 Paul12345

2018/1/30

#
Nivel0 is momentarily a test world just to see if the objects act accordingly. Elev is my main character and Viata0, 1 and 2 are the character lives, that i display on screen. Each of them have a static boolean to know if they are 'empty' lives or not.
danpost danpost

2018/1/30

#
If the first world is a game world, then the Nivel worlds should not be subclasses of it.
Paul12345 Paul12345

2018/1/30

#
Sorry if i explained wrong . LumeScrolling is the class in which i call the scrolling ,set the background and add my main character and lives on screen. Nivel0 and Nivel1 are subclasses in which i add the the level objects (like platforms and enemies).
danpost danpost

2018/1/30

#
I will presume that the code in Nivel1 is pretty much the same as Nivel0. How big are the images of your actors and do any of them spawn other actors?
Paul12345 Paul12345

2018/1/30

#
So i tried making the level reset itself without adding anything to it not even the main actor and the lives and i get no error. Then i started introducing 1 object and with some objects i don't get any memory errors and with some i get (even if i have just that object in the world). I get memory errors even if i have just a box on the level (in which i have no static variables).
Paul12345 Paul12345

2018/1/30

#
danpost wrote...
I will presume that the code in Nivel1 is pretty much the same as Nivel0. How big are the images of your actors and do any of them spawn other actors?
they do spawn actors. The images of the actors are pretty small 40 x 40 pixels is the main actor and the biggest image is for my enemies which are 62 x38
danpost danpost

2018/1/30

#
Paul12345 wrote...
I get memory errors even if i have just a box on the level
What code do you have in its class?
danpost danpost

2018/1/30

#
Paul12345 wrote...
they do spawn actors.
How often are they spawned?
Paul12345 Paul12345

2018/1/30

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Platforma here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Cutie extends Actor
{
    /**
     * Act - do whatever the Platforma wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    private final int gr=1;
    int acceleratieg = 0;
    private int s=LumeScrolling.getRez();
    private int viteza;
    public Cutie()
    {
        this(300,40);
    }
    
    public Cutie(int lungime , int inaltime)
    {
        s=LumeScrolling.getRez();
        GreenfootImage image = getImage();
        image.scale(lungime*s/3,inaltime*s/3);
        setImage(image);
    }
    
    public void act() 
    {
        // Add your action code here.
        viteza =Elev.getViteza();//Getting speed from the main actor
        Gravitatie();
        VerifMiscare();
    }
    
     public void Gravitatie()//Falling
    {
      setLocation(getX(),getY()+acceleratieg);
      if(VerifJos())
      {
          acceleratieg=0;
          while(VerifJos())
          {
              setLocation(getX(),getY()-1);  
          }
              setLocation(getX(),getY()+1); 
       }
      else 
      {
         

            acceleratieg+=gr;
          
      }
    }
    
    public void VerifMiscare()//Checking if it is pushed
    {
        int latime = getImage().getWidth();
        int inaltime = getImage().getHeight();
        if((getOneObjectAtOffset(latime /4 +8*s/3 ,inaltime /-4 ,Elev.class)!=null||getOneObjectAtOffset(latime /4 +8*s/3 ,inaltime /4 ,Elev.class)!=null)
        &&!BlocajStanga())
            setLocation(getX()-viteza,getY());
        if((getOneObjectAtOffset(latime /-4 -8*s/3 ,inaltime /-4 ,Elev.class)!=null||getOneObjectAtOffset(latime /-4 -8*s/3,inaltime /4 ,Elev.class)!=null)
        &&!BlocajDreapta())
            setLocation(getX()+viteza,getY());
    }
    
    public boolean VerifJos()//Checking under for objects
    {
        boolean ok=false;
        if(getY()>getWorld().getHeight()-65*s/3)
            ok=true;
        int latime = getImage().getWidth();
        int inaltime = getImage().getHeight();
        if(getOneObjectAtOffset(latime /2 ,inaltime /2 ,Platforma.class)!=null||getOneObjectAtOffset(latime /-2 ,inaltime /2 ,Platforma.class)!=null
        ||getOneObjectAtOffset(latime /2 ,inaltime /2 ,Cutie.class)!=null||getOneObjectAtOffset(latime /-2 ,inaltime /2 ,Cutie.class)!=null
        ||getOneObjectAtOffset(latime /4 ,inaltime /2 ,AI.class)!=null||getOneObjectAtOffset(latime /-4 ,inaltime /2 ,AI.class)!=null)
            ok=true;
        return ok;
    }
    
    public boolean BlocajStanga()//Checking left for objects
    {
        boolean ok=false;
        int latime = getImage().getWidth();
        int inaltime = getImage().getHeight();
        if(getOneObjectAtOffset(latime /-2 -1 ,inaltime /-4 ,Platforma.class)!=null||getOneObjectAtOffset(latime /-2  -2,inaltime /4 ,Platforma.class)!=null
        ||getOneObjectAtOffset(latime /-2 -3*s/3,inaltime /-4 ,Cutie.class)!=null||getOneObjectAtOffset(latime /-2 -3*s/3,inaltime /4 ,Cutie.class)!=null
        ||getOneObjectAtOffset(latime /-2 +8*s/3 ,inaltime /-4 ,AI.class)!=null||getOneObjectAtOffset(latime /-2 +8*s/3,inaltime /4 ,AI.class)!=null)
            ok=true;
        return ok;
    }
    
     public boolean BlocajDreapta()//Checking right for objects
    {
        boolean ok=false;
        int latime = getImage().getWidth();
        int inaltime = getImage().getHeight();
        if(getOneObjectAtOffset(latime /2 +1 ,inaltime /4 ,Platforma.class)!=null||getOneObjectAtOffset(latime /2  +1,inaltime /-4 ,Platforma.class)!=null
        ||getOneObjectAtOffset(latime /2 +2 ,inaltime /4 ,Cutie.class)!=null||getOneObjectAtOffset(latime /2 +2,inaltime /-4 ,Cutie.class)!=null
        ||getOneObjectAtOffset(latime /2 -8*s/3,inaltime /4 ,AI.class)!=null||getOneObjectAtOffset(latime /2 -8*s/3,inaltime /-4 ,AI.class)!=null)
            ok=true;
        return ok;
    }
}
Paul12345 Paul12345

2018/1/30

#
danpost wrote...
Paul12345 wrote...
they do spawn actors.
How often are they spawned?
Most of them only once in the constructor but the ones that respawn , they do it after 600 'acts' (at greenfoot speed 49).
danpost danpost

2018/1/30

#
Still nothing jumping out as being a cause. Is it still happening on the same line?
Paul12345 Paul12345

2018/1/30

#
danpost wrote...
Still nothing jumping out as being a cause. Is it still happening on the same line?
The memory error still points to LumeScrolling
 setBackground(bg);
Paul12345 Paul12345

2018/1/30

#
I literally can't seem to figure out half of my actors work fine and half cause it to run out of memory.
There are more replies on the next page.
1
2
3