Results 1 to 5 of 5
- 11-07-2010, 03:31 PM #1
Member
- Join Date
- Sep 2010
- Location
- Qc
- Posts
- 31
- Rep Power
- 0
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:
At "HERE 2", everything is EMPTY. Like, gone!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
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() { } ...
I hope it's clear.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"); during.close(); idz++; // 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; this.childrenList.addAll(splitNode(t)); t.putLeafsLimits(t.parent); 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; break; } } } } if (toDelete!=null){ this.childrenList.remove(toDelete); toDelete = null; } } this.idT++; ////////////////////////////////////////////////////// // ---------------> 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"); } after.close(); }
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. :(
- 11-07-2010, 04:15 PM #2
Senior Member
- Join Date
- Dec 2009
- Posts
- 104
- Rep Power
- 0
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
-
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.
- 11-08-2010, 01:09 AM #4
Member
- Join Date
- Sep 2010
- Location
- Qc
- Posts
- 31
- Rep Power
- 0
@coltragon
During my testing I went as far as trying it with the same result.
@Fubarable
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?
EDIT:
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.
- 11-08-2010, 03:03 AM #5
Member
- Join Date
- Sep 2010
- Location
- Qc
- Posts
- 31
- Rep Power
- 0
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.
jMonkeyEngine.org | Groups | Troubleshooting – General | Forum | Not jME3 related, but I need pointer here. Something going out of scope?
Similar Threads
-
GUI help. Don t understand
By s0meb0dy in forum AWT / SwingReplies: 2Last Post: 10-27-2010, 09:40 PM -
Trying to understand
By ladykrimson in forum New To JavaReplies: 20Last Post: 10-12-2010, 11:10 PM -
About Trouble shoot in java
By senthil in forum New To JavaReplies: 3Last Post: 08-31-2009, 06:35 PM -
I don´t understand
By Manikyr in forum New To JavaReplies: 6Last Post: 02-22-2009, 11:22 PM -
Errors I don't understand
By MattyB in forum New To JavaReplies: 4Last Post: 04-01-2008, 11:55 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks