Code that is not actually written is being exexuted

I tried the System.out.println() thing. It gets printed and the other code is executed. I don’t get what the command line thing should do, since the problem is in my code, not in some library. I also edited the code in the github repo and added the problematic line as a comment, since I remember it by hearth

Yes, well your code is ALSO in a .jar file.

…but not going to tell us which file. Good luck with your game.

No, i don’t extend any geometry or node. Only a mesh class, so thst could not be the problem

I wrote it some replies ago. It is in the Chunk.load() method inside the mygame.world package.
It was also in WorldProvider.update() but I completely rewrote that method

    public void load() {
        if (!loaded && !toBeUpdated /* Reference.app.getCamera().contains(node.getWorldBound()) == FrustumIntersect.Inside || Reference.app.getCamera().contains(node.getWorldBound()) == FrustumIntersect.Interstects*/) {
            loaded = true;
            node.attachChild(chunkGeom);
            Reference.terrainNode.attachChild(node);
        }
    }

Change it to:

    public void load() {
        System.out.println("isLoaded:" + loaded + "  toBeUpdated:" + toBeUpdated + "  Will run the if:" + (!loaded && !toBeUpdated));
        if (!loaded && !toBeUpdated /* Reference.app.getCamera().contains(node.getWorldBound()) == FrustumIntersect.Inside || Reference.app.getCamera().contains(node.getWorldBound()) == FrustumIntersect.Interstects*/) {
            loaded = true;
            node.attachChild(chunkGeom);
            Reference.terrainNode.attachChild(node);
        }
    }

To me, I think maybe you don’t understand the condition that makes that if run. Because I think what you probably really mean is if(!loaded || toBeUpdated)

Edit: but I don’t know your code’s intent… I’m only guessing because the double negative feels weird. But I bet if you print out the booleans you’ll see that there is no magic. Either you don’t see a print out (your running different code) or you’ll see where your bug is.

Edit 2: also put a println inside the if. Maybe it’s being run when it’s supposed to and your problem is somewhere else completely.

I can assure you that the line will be printed and the boolean checking is fine. The problem is in that camera.contains(), since the problem appeared when I added it.
I also repeat that the code was also in WorldProvider.update method but I rewrote that method from scratch and the new version is being correctly executed with all the other changes to that class. That’s what made me exclude the WorldProvider class rather than the Chunk class. Another thing is that if the commented clause in Chunk.load is uncommented and changed it does get executed with the change (es. Changing FrustumIntersect.Inside with Outside) but once uncommented again the change does not apply

You are mistaken… about something.

There is no magic. Java code becomes byte code in a .class file. That is all that’s run. There is no magic other code running.

Edit: to further prove it, you can disassemble the Chunk.class file and nowhere in there will you see a call to camera.contains()… because it’s not being called by that code.

Tomorrow I’ll try the disassembly

Change it to this:

    public void load() {
        boolean fullConditional = !loaded && !toBeUpdated;
        boolean blockRan = false;
        if (!loaded && !toBeUpdated /* Reference.app.getCamera().contains(node.getWorldBound()) == FrustumIntersect.Inside || Reference.app.getCamera().contains(node.getWorldBound()) == FrustumIntersect.Interstects*/) {
            System.out.println("running block");
            blockRan = true;
            loaded = true;
            node.attachChild(chunkGeom);
            Reference.terrainNode.attachChild(node);
        }
        if( fullConditional != blockRan ) {
            throw new RuntimeException("Paul was wrong and I was right: Java is magic and there be dragons here.");
        }
    }

…and then never see that exception but see printlns.

So @EmaMaker, you are stating that Camera.contains method is executed in the load() method even thou you commented it, right?

A way to check if that is the case:
eg:

  1. put a breakpoint at start of load method.
  2. Start debugging
  3. After the breakpoint hits the load method, now put another breakpoint inside Camera.contains method
  4. Now Step over (F8 in netbeans) until you reach the end of load method or hit the breakpoint in Camera.contains

Result: Did you reach end of load method without hitting the breakpoint?
Then Camera.contains is not being executed.

Regarding checking the bytecode:
Simply run “javap -c youclassfile.class”

Then you can post the result for the load method.

I would like to know how you came to the conclusion that code not written is being executed. If it was just your assumption then the problem might be somewhere else.

I have checked your code and unless I’m wrong your code is thread unsafe.

  • your WorldProvider.preload()
    • thread T1 for chunkManager
    • another thread T2 for unloader
  • JME thread T0 calls your synchronized void update()
  • Thread T0 adds items to ArrayList loaded, Thread T2 iterates over the same list. The access and adding are not synchronized!
    -Thread T1 initialized Chunk[][][] chunks array, Thread T0 accesses this array, once again the access is not synchronized!

In the update method you are silently catching NullPointers!

public synchronized void update(float tpf) {
...
 try {
        chunks[i][j][k].load();
        if (!loaded.contains(chunks[i][j][k])) {
                loaded.add(chunks[i][j][k]);
    }
 
    } 
   catch (NullPointerException e) {
  }
...

You are getting these NullPointers because your preload method preloads the chunks in a different thread! Also, in a thread unsafe way.

1 Like

When you use live debug breakpoints it also lists the methods that were called previous to it - a.k.a the stacktrace. thats the simplest way to find out what called a method when it was called.