java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 1

1,427 views
Skip to first unread message

Jaime Souza

unread,
Apr 8, 2021, 2:04:11 PM4/8/21
to Jzy3d
Hi everyone,

I am a new user of jzy3d and I am trying to run ScatterDemo.java in Eclipse.

But I always cope with this problem:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 1

Any tips on how to solve it?

Martin Pernollet

unread,
Apr 8, 2021, 2:15:05 PM4/8/21
to jz...@googlegroups.com
May you send us the stacktrace and copy the program you are running ?
Thanks

--
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes "Jzy3d".
Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse jzy3d+un...@googlegroups.com.
Cette discussion peut être lue sur le Web à l'adresse https://groups.google.com/d/msgid/jzy3d/927173e0-dbf6-404d-ba09-7853e23d0c8fn%40googlegroups.com.

mahmoud khaled

unread,
Apr 8, 2021, 2:17:52 PM4/8/21
to jz...@googlegroups.com
Dear 

Jaime Souza

 this error means that your array is empty.







 Make sure to run all dependent classes in the DOC and demos



On Thu, Apr 8, 2021 at 8:44 PM Jaime Souza <jaime....@gmail.com> wrote:
Hi everyone,

I am a new user of jzy3d and I am trying to run ScatterDemo.java in Eclipse.

But I always copy with this problem:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 1

Any tips on how to solve it?

--
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes "Jzy3d".
Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse jzy3d+un...@googlegroups.com.


--
Mahmoud Khalid
090 542 882 16 80

Jaime Souza

unread,
Apr 8, 2021, 2:29:19 PM4/8/21
to Jzy3d
This is code:

package plot3d;

import java.util.Random;

import org.jzy3d.analysis.AbstractAnalysis;
import org.jzy3d.analysis.AnalysisLauncher;
import org.jzy3d.chart.factories.AWTChartComponentFactory;
import org.jzy3d.colors.Color;
import org.jzy3d.maths.Coord3d;
import org.jzy3d.plot3d.primitives.Scatter;
import org.jzy3d.plot3d.rendering.canvas.Quality;


public class Plot3DExample extends AbstractAnalysis{
public static void main(String[] args) throws Exception {
AnalysisLauncher.open(new Plot3DExample());
}
public void init(){
        int size = 500000;
        float x;
        float y;
        float z;
        float a;
        
        Coord3d[] points = new Coord3d[size];
        Color[]   colors = new Color[size];
        
        Random r = new Random();
        r.setSeed(0);
        
        for(int i=0; i<size; i++){
            x = r.nextFloat() - 0.5f;
            y = r.nextFloat() - 0.5f;
            z = r.nextFloat() - 0.5f;
            points[i] = new Coord3d(x, y, z);
            a = 0.25f;
            colors[i] = new Color(x, y, z, a);
        }
        
        Scatter scatter = new Scatter(points, colors);
        chart = AWTChartComponentFactory.chart(Quality.Advanced, "newt");
        chart.getScene().add(scatter);
    }
}


And this is the stacktrace:  


------------------------------------
Rotate     : Left click and drag mouse
Scale      : Roll mouse wheel
Z Shift    : Right click and drag mouse
Animate    : Double left click
Screenshot : Press 's'

------------------------------------
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 1
at jogamp.opengl.windows.wgl.awt.WindowsAWTWGLGraphicsConfigurationFactory.chooseGraphicsConfigurationImpl(WindowsAWTWGLGraphicsConfigurationFactory.java:171)
at com.jogamp.nativewindow.GraphicsConfigurationFactory.chooseGraphicsConfiguration(GraphicsConfigurationFactory.java:424)
at com.jogamp.nativewindow.awt.AWTGraphicsConfiguration.create(AWTGraphicsConfiguration.java:125)
at com.jogamp.newt.awt.NewtCanvasAWT.addNotify(NewtCanvasAWT.java:590)
at java.desktop/java.awt.Container.addNotify(Container.java:2801)
at java.desktop/java.awt.Panel.addNotify(Panel.java:87)
at java.desktop/java.awt.Container.addNotify(Container.java:2801)
at java.desktop/java.awt.Window.addNotify(Window.java:787)
at java.desktop/java.awt.Frame.addNotify(Frame.java:493)
at java.desktop/java.awt.Window.pack(Window.java:825)
at org.jzy3d.bridge.awt.FrameAWT.initialize(FrameAWT.java:39)
at org.jzy3d.bridge.awt.FrameAWT.<init>(FrameAWT.java:21)
at org.jzy3d.chart.factories.AWTChartComponentFactory.newFrameAWT(AWTChartComponentFactory.java:128)
at org.jzy3d.chart.factories.AWTChartComponentFactory.newFrame(AWTChartComponentFactory.java:239)
at org.jzy3d.chart.ChartLauncher.frame(ChartLauncher.java:84)
at org.jzy3d.chart.ChartLauncher.openChart(ChartLauncher.java:41)
at org.jzy3d.chart.ChartLauncher.openChart(ChartLauncher.java:35)
at org.jzy3d.chart.ChartLauncher.openChart(ChartLauncher.java:31)
at org.jzy3d.analysis.AnalysisLauncher.open(AnalysisLauncher.java:25)
at org.jzy3d.analysis.AnalysisLauncher.open(AnalysisLauncher.java:13)
at plot3d.Plot3DExample.main(Plot3DExample.java:16)


I have checked and my arrays are not empty.

Martin Pernollet

unread,
Apr 8, 2021, 2:39:44 PM4/8/21
to jz...@googlegroups.com
This seams related to newt - a JOGL windowing toolkit.

I suggest you switch to version 2.0 of jzy3d (see tutorial folder in the github repo). Then if you still have problem with newt charts then use awt or EmulGL.

The surface and scatter exemple in 2.0 show more conveniently how to use these various windowing toolkits.

Jaime Souza

unread,
Apr 9, 2021, 9:00:23 AM4/9/21
to Jzy3d
Thank you for the answers.

I am already using version 2.0 of jzy3d with the  following dependencies:


 <dependency>
        <groupId>org.jzy3d</groupId>
        <artifactId>jzy3d-native-jogl-awt</artifactId>
        <version>2.0.0-SNAPSHOT</version>
      </dependency>
      <dependency>
        <groupId>org.jzy3d</groupId>
        <artifactId>jzy3d-native-jogl-swing</artifactId>
        <version>2.0.0-SNAPSHOT</version>
      </dependency>
      
      <dependency>
        <groupId>org.jzy3d</groupId>
        <artifactId>jzy3d-native-jogl-swt</artifactId>
        <version>2.0.0-SNAPSHOT</version>
      </dependency>
      <dependency>
        <groupId>org.jzy3d</groupId>
        <artifactId>jzy3d-tester-native</artifactId>
        <version>2.0.0-SNAPSHOT</version>
        <!-- not scoped test to demonstrate DebugGL in src/main/java -->
      </dependency>
      
      <dependency>
        <groupId>org.jzy3d</groupId>
        <artifactId>jzy3d-tester</artifactId>
        <version>2.0.0-SNAPSHOT</version>
        <scope>test</scope>
      </dependency>

      <dependency>
        <groupId>org.jzy3d</groupId>
        <artifactId>jzy3d-emul-gl</artifactId>
        <version>2.0.0-SNAPSHOT</version>
      </dependency>
  

This time, using the scatter exemple in 2.0:

import java.util.Random;

import org.jzy3d.analysis.AWTAbstractAnalysis;
import org.jzy3d.analysis.AnalysisLauncher;
import org.jzy3d.chart.factories.AWTChartFactory;
import org.jzy3d.colors.Color;
import org.jzy3d.maths.Coord3d;
import org.jzy3d.plot3d.primitives.Scatter;
import org.jzy3d.plot3d.rendering.canvas.Quality;


public class App extends AWTAbstractAnalysis {
  public static void main(String[] args) throws Exception {
    AnalysisLauncher.open(new App());
  }

  @Override
  public void init() {
    int size = 500000;
    float x;
    float y;
    float z;
    float a;

    Coord3d[] points = new Coord3d[size];
    Color[] colors = new Color[size];

    Random r = new Random();
    r.setSeed(0);

    for (int i = 0; i < size; i++) {
      x = r.nextFloat() - 0.5f;
      y = r.nextFloat() - 0.5f;
      z = r.nextFloat() - 0.5f;
      points[i] = new Coord3d(x, y, z);
      a = 0.25f;
      colors[i] = new Color(x, y, z, a);
    }

    Scatter scatter = new Scatter(points, colors);

    Quality q = Quality.Advanced;
    // q.setPreserveViewportSize(true);

    chart = new AWTChartFactory().newChart(q);
    chart.getScene().add(scatter);
  }
}


  But the question goes on:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 1
        at jogamp.opengl.windows.wgl.awt.WindowsAWTWGLGraphicsConfigurationFactory.chooseGraphicsConfigurationImpl(WindowsAWTWGLGraphicsConfigurationFactory.java:171)
        at com.jogamp.nativewindow.GraphicsConfigurationFactory.chooseGraphicsConfiguration(GraphicsConfigurationFactory.java:424)  
        at com.jogamp.opengl.awt.GLCanvas.chooseGraphicsConfiguration(GLCanvas.java:1560)
        at com.jogamp.opengl.awt.GLCanvas.addNotify(GLCanvas.java:611)
        at java.desktop/java.awt.Container.addNotify(Container.java:2801)
        at java.desktop/java.awt.Window.addNotify(Window.java:787)
        at java.desktop/java.awt.Frame.addNotify(Frame.java:493)
        at java.desktop/java.awt.Window.pack(Window.java:825)
        at org.jzy3d.bridge.awt.FrameAWT.initialize(FrameAWT.java:42)
        at org.jzy3d.bridge.awt.FrameAWT.<init>(FrameAWT.java:23)
        at org.jzy3d.chart.factories.AWTPainterFactory.newFrame(AWTPainterFactory.java:103)
        at org.jzy3d.chart.Chart.open(Chart.java:263)
        at org.jzy3d.chart.ChartLauncher.openChart(ChartLauncher.java:41)
        at org.jzy3d.chart.ChartLauncher.openChart(ChartLauncher.java:33)
        at org.jzy3d.chart.ChartLauncher.openChart(ChartLauncher.java:28)
        at org.jzy3d.analysis.AnalysisLauncher.open(AnalysisLauncher.java:23)
        at org.jzy3d.analysis.AnalysisLauncher.open(AnalysisLauncher.java:12)
        at com.jaime.App.main(App.java:16)



Martin Pernollet

unread,
Apr 9, 2021, 9:19:47 AM4/9/21
to jz...@googlegroups.com
Thanks for migrating to 2.0.

Your stack trace lead us to a source file in JOGL that may be buggy - or I don't understand! To me line 171 can only fail.

Capture d’écran 2021-04-09 à 15.09.01.png

In order to report this to the JOGL team, could you tell more about your configuration?
- Hardware (CPU, GPU)
- OS type and version
- JDK version

I have two suggestions to avoid this problem
  • force a JOGL graphic configuration as shown here with profile detection.
  • use EmulGL instead of JOGL for rendering. EmulGL is made for more portable charts across computers. 



Jaime Souza

unread,
Apr 9, 2021, 9:48:11 AM4/9/21
to Jzy3d
Martin, thank you for suggestions. 
  • force a JOGL graphic configuration as shown here with profile detection. The question persists.
  • use EmulGL instead of JOGL for rendering. EmulGL is made for more portable charts across computers => It works well.
In order to report this to the JOGL team, could you tell more about your configuration?
- Hardware (CPU, GPU)
Intel(R) Core(TM) i7-8550U CPU  
Intel(R) UHD Graphics 620
Versão do driver: 27.20.100.8681
Data do driver: 05/09/2020
Versão do DirectX: 12 (FL 12.1)
Local físico: Barramento PCI 0, dispositivo 2, função 0

- OS type and version
Edição Windows 10 Home Single Language
Versão 20H2
Instalado em ‎15/‎12/‎2020
Compilação do SO 19042.868
Experiência Windows Feature Experience Pack 120.2212.1070.0

- JDK version
openjdk version "11.0.10" 2021-01-19
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.10+9)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.10+9, mixed mode)
jdk-16

Martin Pernollet

unread,
May 25, 2021, 3:20:03 AM5/25/21
to jz...@googlegroups.com
For information, this bug is monitored in this ticket.

The code for fixing native was on master so it changed. Here is an update on a branch.

Martin

unread,
Nov 5, 2021, 7:58:16 AM11/5/21
to Jzy3d
Hi

I encountered the same on Windows when using a chart with the JDK provided by Eclipse, which is a JDK 17. I ran the project with JDK 8 instead of the default one, then the program can execute.

This allows keeping JOGL for 3D rendering which is faster than EmulGL.

Reply all
Reply to author
Forward
0 new messages