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

2013/6/14

Greenfoot.start() issue (bug?)

danpost danpost

2013/6/14

#
I have been experiencing an issue whereby if I use 'Greenfoot.start();' to automatically start my scenario, when I reset the scenario, after going to a different world, the world will not completely initialize; or freeze upon completion of instantiation (like it gets caught in an infinite loop). Maybe someone on the Greenfoot team could look into this. Or at least tell me what is wrong with the following. Using two World sub-classes with the following code:
import greenfoot.*;
import java.awt.Color;

public class Main extends World
{
    public Main()
    {
        super(400, 600, 1);
        GreenfootImage text = new GreenfootImage("Click mouse\nto go to\nthe next world", 64, Color.black, Color.white);
        GreenfootImage bg = getBackground();
        bg.drawImage(text, (bg.getWidth()-text.getWidth())/2, (bg.getHeight()-text.getHeight())/2);
        Greenfoot.start();
    }
    
    public void act()
    {
        if (Greenfoot.mouseClicked(null)) Greenfoot.setWorld(new Second());
    }
}
and
import greenfoot.*;
import java.awt.Color;

public class Second extends World
{
    private static int count;
    
    public Second()
    {
        super(400, 600, 1);
        count++;
        GreenfootImage text = new GreenfootImage("Click mouse\nto restart\nthis world ("+count+")", 64, Color.black, Color.white);
        GreenfootImage bg = getBackground();
        bg.drawImage(text, (bg.getWidth()-text.getWidth())/2, (bg.getHeight()-text.getHeight())/2);
    }
    
    public void act()
    {
        if (Greenfoot.mouseClicked(null)) Greenfoot.setWorld(new Second());
    }
}
Run and click the window once or more. Then click the 'Reset' button to reproduce problem.
davmac davmac

2013/6/16

#
Hi danpost, I've been able to reproduce this (though not easily - it took quite a few tries), so I'll look into it. I think you've encountered a Greenfoot bug. Thanks.
davmac davmac

2013/6/19

#
I've created a ticket in the bug database: http://bugs.bluej.org/greenfoot/ticket/393
You need to login to post a reply.