Results 1 to 5 of 5
  1. #1
    MadJack is offline Member
    Join Date
    Sep 2010
    Rep Power

    Default About to shoot myself. I don't understand!

    I don't think tiredness has anything to do with what's going on, but I guess at this point anything is possible.

    I'm almost done working on my Octree but for some freaking reason there's something weird going on...

    The problematic part follows in an instant. Let me explain what happens.

    In the code pasted below, fillTree is used to fill leaves of the tree. Each leaf has three sets of coordinates. If the sun's coordinates fit inside that leaf, it goes in there. If not, we iterate to the next leaf, until the whole 300,000 to 500,000 stars are done. But that's not important.

    What is important here is that I tried to debug the problem. Look at "at HERE" below. The FileWriter here does its thing and write over 4000 files. Each time we found a leaf to put the sun, it writes a file. I know it should do more, but that's the really my problem. At any rate, it might be related, but I don't think so.

    The part that is in those files look like this:
    Java Code:
    The followings should be filled.
    Leaf: GalaxyOctree.TreeNode@58f39b3a
    Entered suns: 501
    Top Right: (181.87805, 0.0, 171.81053)
    Middle   : (90.939026, -11.448937, 85.905266)
    Bott Left: (0.0, -22.897875, 0.0)
    Parent: GalaxyOctree.TreeNode@5975d6ab
    At "HERE 2", everything is EMPTY. Like, gone!

    Here's what that part looks like:
    Java Code:
    The following should be entirely filled.
    Leaf: GalaxyOctree.TreeNode@199836ed
    Top Right: (0.0, 0.0, 0.0)
    Middle   : (0.0, 0.0, 0.0)
    Bott Left: (0.0, 0.0, 0.0)
    Parent: GalaxyOctree.TreeNode@5caf993e
    Has: 0

    The question is WHY!?

    I could understand if I'd try to print outside of the method; that, somehow, things had gone out of scope, but childrenList is declared at the top of the class like so:

    Java Code:
    public class OctreeList extends TreeNode {
        private List<TreeNode> childrenList = new LinkedList();
        private TreeNode baseNode = new TreeNode();
        private int counter;
        public int numLeafs;
        public int idT = 0;
        public OctreeList() {

    Java Code:
        public void fillTree(Global g, ArrayList<Star> nodeStars) throws GameExceptions, IOException {
            int idz = 0;
            for (Star s : nodeStars) {
                TreeNode toDelete =  null;
                Vector3f xyz = s.getXYZ();
                for (TreeNode t : this.childrenList) {
                    if (t.isLeaf) {
                        if (xyz.x <= t.topRightCorner.x &&
                            xyz.x >= t.botLeftCorner.x &&
                            xyz.y <= t.topRightCorner.y &&
                            xyz.y >= t.botLeftCorner.y &&
                            xyz.z <= t.topRightCorner.z &&
                            xyz.z >= t.botLeftCorner.z) {
                            insertSun(t, s);
                            // ---------------> HERE <--------------
                            BufferedWriter during = new BufferedWriter(new FileWriter("./test/" + "leafs_during"+idT+idz+".txt"));
                            during.write("The followings should be filled.\n");
                            during.write("Leaf: "+t+"\n");
                            during.write("Entered suns: "+t.starsCount+"\n\n");
                            during.write("Top Right: "+t.topRightCorner+"\n");
                            during.write("Middle   : "+t.middle+"\n");
                            during.write("Bott Left: "+t.botLeftCorner+"\n");
                            during.write("Parent: "+t.parent+"\n");
                            // If FULL, split here
                            if (t.starsCount>t.g.getMaxStarsOnScreen()) {
                                System.out.println("Splitting "+t+"");
                                System.out.println("Has: "+t.starsCount+" stars");
                                // Split this leaf
                                t.isLeaf = false;
                                t.isRoot = true;
                                t.lastRoot = true;
                                t.parent.lastRoot = false;
                                toDelete = t;
                                this.numLeafs = this.childrenList.size();
                                // Use t to fill the children we just made
                                this.refill(t, t.nodeStars);
                                t.nodeStars = null;
                                t.starsCount = 0;
                if (toDelete!=null){
                    toDelete = null;
            // ---------------> HERE 2 <--------------
            BufferedWriter after = new BufferedWriter(new FileWriter("./" + "leafs_after.txt"));
            for (int i=0,j=this.childrenList.size();i<j;i++) {
                after.write("The following should be entirely filled.\n");
                after.write("Leaf: "+this.childrenList.get(i)+"\n");
                after.write("Top Right: "+this.childrenList.get(i).topRightCorner+"\n");
                after.write("Middle   : "+this.childrenList.get(i).middle+"\n");
                after.write("Bott Left: "+this.childrenList.get(i).botLeftCorner+"\n");
                after.write("Parent: "+this.childrenList.get(i).parent+"\n");
                after.write("Has: "+this.childrenList.get(i).starsCount+"\n\n");
    I hope it's clear.

    I've been trying to figure out why everything seemed to go to hell in the last several hours and I can't find why. I'm at the end of my rope here. :(

  2. #2
    coltragon is offline Senior Member
    Join Date
    Dec 2009
    Rep Power


    Ehm i don't know for sure but you can always try. But maybe you should try declaring childrenlist as a static?
    Beginner in Java Programming, Please don't trust my anwsers blind please :D

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power


    Quote Originally Posted by coltragon View Post
    Ehm i don't know for sure but you can always try. But maybe you should try declaring childrenlist as a static?
    To the original poster, please do not do coltragon's suggestion as while it's well intended it's just wrong since each instance will share the same childrenlist which completely ruins its ability to work as a viable tree.

    Myself, I may need more code and a more detailed explanation of the problem to understand what's going on (though others smarter than I may understand the problem with what you've described above). Also I'm wondering why you create a whole bunch of files inside of the loop rather than simply creating your two files once before the loops and then adding lines to these files from inside of the loop.
    Last edited by Fubarable; 11-07-2010 at 04:45 PM.

  4. #4
    MadJack is offline Member
    Join Date
    Sep 2010
    Rep Power


    During my testing I went as far as trying it with the same result.

    The file writing parts are that way because I was already using a similar loop elsewhere and simply pasted it and changed variable names. Faster that way.

    To explain fully...

    The class into which those lines of code are is called OctreeList. It's a wrapper class for Octree.

    I did that wrapper because in the old octree implementation I was getting a BufferOverflowError. Recursivity was too deep so I devised that wrapper to fix it.

    What it does is:

    In "main", an OctreeList is instantiated.
    ->OctreeList creates the root node of the Octree then 8 children.
    ->Then it starts filling the Octree with stars.
    ->childrenList holds only the octree leaves.
    ->If a leaf (a child in a node that doesn't have children) has more than x stars (the max that can be displayed on the screen), I split it in 8, take its stars and redistribute them among those 8 children, finally turn that previous leaf into a root node.
    ->Remove that new root node from childrenList.
    ->childrenList holds ONLY leafs so I don't need to recurse. I only have to walk the linked list, filling as I go along.

    Would you need all the code in the class?

    Forgot to add that at one point I thought some threading was going on with the manipulation of the lists and that things were going south so I tested using synchronized but got the same result.
    Last edited by MadJack; 11-08-2010 at 01:14 AM.

  5. #5
    MadJack is offline Member
    Join Date
    Sep 2010
    Rep Power


    Just so you know I have cross-posted the problem on jME3's forums since that's the 3D engine I use.

    I preferred asking here first since it's not (at least I really do hope so) directly a problem with the engine itself, but rather with Java. Either me or the JVM. Most likely me. &#124; Groups &#124; Troubleshooting – General &#124; Forum &#124; Not jME3 related, but I need pointer here. Something going out of scope?

Similar Threads

  1. GUI help. Don t understand
    By s0meb0dy in forum AWT / Swing
    Replies: 2
    Last Post: 10-27-2010, 09:40 PM
  2. Trying to understand
    By ladykrimson in forum New To Java
    Replies: 20
    Last Post: 10-12-2010, 11:10 PM
  3. About Trouble shoot in java
    By senthil in forum New To Java
    Replies: 3
    Last Post: 08-31-2009, 06:35 PM
  4. I dont understand
    By Manikyr in forum New To Java
    Replies: 6
    Last Post: 02-22-2009, 11:22 PM
  5. Errors I don't understand
    By MattyB in forum New To Java
    Replies: 4
    Last Post: 04-01-2008, 11:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts