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

2013/8/15

Breakpoints broken?

SPower SPower

2013/8/15

#
Hi all, I'm working on a script 'engine' (if you wanna call it that way) for one of my new 2 games coming up. Only, to debug something I need to use breakpoints. So I created some breakpoints, but the game stopped at another line of code than I told it to. It does te same every time.
davmac davmac

2013/8/15

#
That's a bit vague...
SPower SPower

2013/8/15

#
Well: - I set some breakpoints. - The game did stop indeed - But it wouldn't stop at the lines the breakpoints were at, but at some other line. The other line seems to depend on where the breakpoint originally was, because sometimes it doesn't show the debugger at all (I think that means that it's stopped at some code in the greenfoot or java package)
davmac davmac

2013/8/15

#
ok, but I mean, what is your code, where do you set the breakpoint, and where does it actually stop?
SPower SPower

2013/8/15

#
Well, it happens with all of the classes, so shall I send you the whole project? If you email me (svnigte@gmail.com), I'll respond and give the source code.
davmac davmac

2013/8/15

#
Could you just produce a small example and post the code here? Thanks. Also, is there some pattern to where you set the breakpoint and where the game stops? I.e. is it always two lines afterwards or something like that?
SPower SPower

2013/8/16

#
Sure, this the beginning of a class:
import greenfoot.*;
import java.io.*;

/**
 * All rights reserved.
 * @author Sven van Nigtevecht
 * @version 1.0
 */
public class ScriptReader
{
    private static final String FOLDER = "scripts/";
    private static final String COMMENT_SIGN = "//";
    
    private ScriptReader() {}
    
    public static void runScript(String file)
    {
        String l = "";
        try {
            Class cls = Class.forName("ScriptReader");
            InputStream is = cls.getClassLoader().getResourceAsStream(FOLDER+file);
            BufferedReader r = new BufferedReader(new InputStreamReader(is));
I put a breakpoint at the line which starts with 'InputStream is', and it stopped in this class:
import greenfoot.*;

/**
 * @author Sven van Nigtevecht
 * @version 1.0
 */
public class Player extends ScrollActor implements Glower
{
    private static final int MOVE_AMOUNT = 5;
    private static final GreenfootImage flashLightOffImage = new GreenfootImage(1,1);
    private GreenfootImage beam = new GreenfootImage("beam.png");
    
    private boolean flashlightOn;
    
    public void act()
    {
        MouseInfo m = Greenfoot.getMouseInfo();
        ScrollWorld w = getWorld();
at the line which says 'MouseInfo m' I can't seem to find a pattern, since when I put a breakpoint on other lines the game just stops and doesn't show the debugger, instead of showing some code where it stops.
davmac davmac

2013/8/16

#
Sorry, I meant a small self-contained example - one that I can try myself. This sounds very strange. Does it happen in other projects or just one? Can you give a self-contained example?
SPower SPower

2013/8/16

#
Well, I don't know exactly what you mean by 'self-contained example', but how would I make something like that? And something I just noticed, it only seems to happen with breakpoints in my class 'ScriptReader'. Shall I give you all of the code then?
davmac davmac

2013/8/16

#
Hmm, maybe just send the whole scenario (to support@greenfoot.org) with some instructions on how to reproduce it (i.e. what line to put the breakpoint on and what to do then). Thanks.
davmac davmac

2013/8/16

#
(by self-contained example I mean an example that is complete, that doesn't need other code to try out. When looking at programming problems or bug reports people will often talk about a "small self-contained example" or SSCE - because if you have a small example, it's usually much easier to track down an issue).
davmac davmac

2013/8/16

#
Ok, I have your example. It looks like the breakpoints don't work properly when the code is being run from the world's "started" method. Here's an SSCE:
public class TestWorld extends World
{
   public TestWorld()
    {    
        super(600, 400, 1); 
    }
    
    public void started()
    {
        System.out.println("Started!"); // SET BREAKPOINT HERE
    }
}
davmac davmac

2013/8/16

#
I think it's related to this existing bug: http://bugs.bluej.org/greenfoot/ticket/370
SPower SPower

2013/8/16

#
Thanks for looking at it! I really appreciate it, and am happy that it wasn't my fault!
You need to login to post a reply.