Author Topic: ArrayIndexOutOfBoundsException when loading from InputStream  (Read 9323 times)

Offline mahermeg17

  • byte
  • *
  • Posts: 3
    • View Profile
Hi,
I'm using the same *.obj file once from the server as an InputStream  and once as a local file packaged into the apk
I get ArrayIndexOutOfBoundsException only when using InputStream.

Help plz.

// Create and set 3D Object from local file works fine
objet3d = Object3D.mergeAll(Loader.loadOBJ(getResources().openRawResource(R.raw.scan_resul), null, 1f));


// Create and set 3D Object from input stream generates ArrayIndexOutOfBoundsException
InputStream ip = new ByteArrayInputStream(previewData.data);
                try {
                        objet3d = Object3D.mergeAll(Loader.loadOBJ(ip, null, 1f));
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }


java.lang.ArrayIndexOutOfBoundsException: length=2608; index=2608
                                                                         at com.threed.jpct.Loader.createOBJObject(Loader.java:662)
                                                                         at com.threed.jpct.Loader.loadOBJ(Loader.java:526)
                                                                         at com.threed.jpct.Loader.loadOBJ(Loader.java:229)
                                                                         at com.akka.AirCobotMQTT.activity.Visualisation3DReleaseActivity$MyRenderer.onSurfaceChanged(Visualisation3DReleaseActivity.java:411)
                                                                         at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1511)
                                                                         at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1239)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: ArrayIndexOutOfBoundsException when loading from InputStream
« Reply #1 on: June 01, 2017, 01:49:47 pm »
That's strange. As far as loading goes, there should be no difference between the two ways. Are you sure that previewData.data really is an exact representation of the actual file's content?

Does this happen for any file or for just one in particular?

Offline mahermeg17

  • byte
  • *
  • Posts: 3
    • View Profile
Re: ArrayIndexOutOfBoundsException when loading from InputStream
« Reply #2 on: June 01, 2017, 03:09:12 pm »
yes they are the some .
I tried more than one .obj file and get the some exception.

Offline mahermeg17

  • byte
  • *
  • Posts: 3
    • View Profile
Re: ArrayIndexOutOfBoundsException when loading from InputStream
« Reply #3 on: June 01, 2017, 04:08:53 pm »
In fact the first issue happens because I use the inputstream wich made from a byte[] passed by an Intent
when I save it as file on the phone storage and load it again, it's loaded successfully.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: ArrayIndexOutOfBoundsException when loading from InputStream
« Reply #4 on: June 02, 2017, 08:40:42 am »
Can you provide me with a simple example (code and model) that shows the problem? I can't reproduce this.