NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.

To learn about what's going on, see About the Archive Site.

Re: Exception in java3d

Hi Russell,

This may be a VisAD bug or may be a Java3D bug, but if you
are willing to experiment perhaps we can fix it.

The experiments all involve changes in
visad/java3d/RendererJ3D.java. First could you please try
changing RendererJ3D.clearBranch() from (please excuse all
the old comments):

  public void clearBranch() {
    if (branches == null) return;
    synchronized (branches[currentIndex]) {
      if (branchNonEmpty[currentIndex]) {
// System.out.println("branch " + currentIndex + " not empty, clearBranch");

/* WLH 1 April 99 - doesn't help memory */
        flush(branches[currentIndex]);
        Enumeration ch = branches[currentIndex].getAllChildren();
        while(ch.hasMoreElements()) {
          BranchGroup b = (BranchGroup) ch.nextElement();
          b.detach();
        }
/*
        for (int m=0; m<branches[currentIndex].numChildren(); m++) {
          branches[currentIndex].removeChild(m);
        }
*/
      }
    }
    branchNonEmpty[currentIndex] = false;
  }

to:

  public void clearBranch() {
    if (branches == null) return;
    synchronized (this) {
      if (branchNonEmpty[currentIndex]) {
// System.out.println("branch " + currentIndex + " not empty, clearBranch");

/* WLH 1 April 99 - doesn't help memory */
        flush(branches[currentIndex]);
        Enumeration ch = branches[currentIndex].getAllChildren();
        while(ch.hasMoreElements()) {
          BranchGroup b = (BranchGroup) ch.nextElement();
          b.detach();
        }
/*
        for (int m=0; m<branches[currentIndex].numChildren(); m++) {
          branches[currentIndex].removeChild(m);
        }
*/
      }
      branchNonEmpty[currentIndex] = false;
    }
  }

That is, move "branchNonEmpty[currentIndex] = false" inside
the synchronized block, and synchronize on "this" rather than
"branches[currentIndex]". If this fixes the problem, please
let me know, and you're done.

If that doesn't fix it, then it may be a Java3D bug that we
can fix with a little defensive code. The lowest  level VisAD
code in your Exception stack is line 264 of RendererJ3D.java,
in the getBranch() method:

  public BranchGroup getBranch() {
    synchronized (this) {
      if (branches != null && branchNonEmpty[currentIndex]) {
        return (BranchGroup) branches[currentIndex].getChild(0); // line 264
      }
      else {
        return null;
      }
    }
  }

Would you please try changing this to:

  public BranchGroup getBranch() {
    synchronized (this) {
      if (branches != null && branchNonEmpty[currentIndex] &&
          branches[currentIndex].numChildren() > 0) {
        return (BranchGroup) branches[currentIndex].getChild(0);
      }
      else {
        return null;
      }
    }
  }

If that still gives the Exception, then please try:

  public BranchGroup getBranch() {
    synchronized (this) {
      if (branches != null && branchNonEmpty[currentIndex] &&
          branches[currentIndex].numChildren() > 0) {
        try {
          return (BranchGroup) branches[currentIndex].getChild(0);
        }
        catch (java.lang.ArrayIndexOutOfBoundsException e) {
          return null;
        }
      }
      else {
        return null;
      }
    }
  }

Let us know how this works out, and thanks for your help on this.

Cheers,
Bill

On Thu, 10 Jul 2003, Russell Steicke wrote:

> Hello All,
>
> I can consistently get this exception in an application by changing the
> order in which I add data to the display.  Is this familiar to anyone?
> How do I go about tracking this one down, given that there's none of my
> own code in the stack trace?
>
> (A search of the email archives didn't turn up the same stack trace.)
>
>
> java.lang.ArrayIndexOutOfBoundsException: 0 >= 0
>         at java.util.Vector.elementAt(Vector.java:427)
>         at javax.media.j3d.GroupRetained.getChild(GroupRetained.java:410)
>         at javax.media.j3d.Group.getChild(Group.java:219)
>         at visad.java3d.RendererJ3D.getBranch(RendererJ3D.java:264)
>         at visad.bom.ImageRendererJ3D.doTransform(ImageRendererJ3D.java:363)
>         at visad.java3d.RendererJ3D.doAction(RendererJ3D.java:181)
>         at visad.DisplayImpl.doAction(DisplayImpl.java:1559)
>         at visad.ActionImpl.run(ActionImpl.java:353)
>         at visad.util.ThreadPool$ThreadMinnow.run(ThreadPool.java:95)
>
>
> Thanks
> Russell
>
>
> --
> Russell Steicke
>
> -- Fortune says:
> Two percent of zero is almost nothing.
>
>


  • 2003 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the visad archives: