Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  How to avoid StackOverflowError ?  (Read 1644 times)
0 Members and 1 Guest are viewing this topic.
Offline Bombadil

Senior Member





« Posted 2004-04-15 04:47:58 »

I've got a method which calls itself recursively. For a few thousand iterations it works fine but then it throws an java.lang.StackOverflowError ; it's with Java 1.4.2_04-b05 and no special Java command switches on a Win2000 box.
How could I increase that stack size?

Also, when the error is being thrown, my try-catch(Throwable th) block won't print an error stack, despite of my line th.printStackTrace(). For other errors this works. Looks like the stack's so full that the error stack can't be pushed on it...
However then I've to guess the code line where exactly the StackOverflowError occurs. Is there a way to always get a full printStackTrace() ?
Offline Herkules

Senior Member




Friendly fire isn't friendly!


« Reply #1 - Posted 2004-04-15 09:42:18 »

maybe -Xss<size>

But you should think about such deep recursions....

HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #2 - Posted 2004-04-15 10:11:20 »

You can often "simulate" recursion with partially-recursive code.

One trick is to "checkpoint" the results, so that you recurse in "chunks" and your stack never gets too big.

If you have pseudo-code you could post, we could possibly suggest some other tricks (there's others too)?

malloc will be first against the wall when the revolution comes...
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Bombadil

Senior Member





« Reply #3 - Posted 2004-04-15 10:19:40 »

The -Xss<size> switch doesn't help unfortunately.

I'd happily use another way instead of recursion, but I can't think of one. I've described what I basically try to do (finding all polygons in a smooth group) here: http://www.java-gaming.org/cgi-bin/JGNetForums/YaBB.cgi?board=xith3d;action=display;num=1080400827;start=7#7
... however since it's not a pure Xith question I thought let's ask here, too. :-)
Offline Bombadil

Senior Member





« Reply #4 - Posted 2004-04-15 10:34:46 »

+
Quote
You can often "simulate" recursion with partially-recursive code.

One trick is to "checkpoint" the results, so that you recurse in "chunks" and your stack never gets too big.

If you have pseudo-code you could post, we could possibly suggest some other tricks (there's others too)?

The checkpoint sounds well. Still I'm unsure how I could use it with my problem, but I'll think about it... :-)

The task is to find for a 3d modell all adjacent polygons with a soft angle (between their normal vectors) and setting them to the same smooth-group. The pseudo code looks like this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
main {
  List polygonlist;
  int  current_smoothgroup_number;
  for (each polygon in polygonlist) {
    if (polygon's smoothgroup_number isn't set) {
      set polygon's smoothgroup_number to current_smoothgroup_number;
      call find_neighbours(polygon);
      current_smoothgroup_number++;
    }
  }
}

find_neighbours(polygon) {
  get all neighbour polygons;
  for (each neighbour_polygon) {
    if (   neighbour_polygon'
s smoothgroup_number isn't set
        && angle of normal vectors between polygon and neighbour_polygon < crease_angle) {
      set neighbour_polygon'
s smoothgroup_number to current_smoothgroup_number;
      call find_neighbours(neighbour_polygon); // Recursion! :-)
   }
  }    
}


Now imagine a sphere with several thousands polygons which all have soft edges...
Offline Mark Thornton

Senior Member





« Reply #5 - Posted 2004-04-15 10:48:12 »

One problem here is that the recursion depth can be as deep as the number of polygons (or worse if there is an bug).

An iterative form like this would be better
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
find_neighbours(polygon) {
   List work = new LinkedList();
   work.add(polygon);
   while (!work.isEmpty()) {
      Polygon p = (Polygon)work.remove(0);
      for (neighbours_of(p)) {
         if (   neighbour_polygon's smoothgroup_number isn't set
           && angle of normal vectors between polygon and    neighbour_polygon < crease_angle) {
      set neighbour_polygon's smoothgroup_number to current_smoothgroup_number;
      work.add(neighbour_polygon);
          }      }
   }
}
Offline Bombadil

Senior Member





« Reply #6 - Posted 2004-04-15 12:04:23 »

Well, Mark, that's smart. :-)  Iterative has been the keyword. Haven't been able to see the wood for the trees... although Blablah gave a good hint with the "checkpoint" idea.

Many thanks you all. There's a lot we can learn here in the forum due to you good people.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (19 views)
2014-09-24 16:12:06

Grunnt (44 views)
2014-09-23 14:38:19

radar3301 (27 views)
2014-09-21 23:33:17

BurntPizza (63 views)
2014-09-21 02:42:18

BurntPizza (32 views)
2014-09-21 01:30:30

moogie (40 views)
2014-09-21 00:26:15

UprightPath (50 views)
2014-09-20 20:14:06

BurntPizza (54 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!