[resolved] ERROR: ArrayIndexOutOfBoundsException from "world.renderScene(fb)"

Started by cefengxu, October 21, 2015, 10:54:10 AM

Previous topic - Next topic

cefengxu

Dear master:

i have got a problem and i still could not fix it :

Purpose : using JPCT to render 3D Model for AR basic on ARToolkit;
Platform: Eclipse , ARToolkit Example: ARNative;
jpct: i using the JPCTdemo (helloworld) to add the jpct's code into my code for rendering a cube on the preview image;

However :
the error will be shown as follown when run the function "renderScene(fb)"

10-21 16:44:00.737: E/AndroidRuntime(20351): FATAL EXCEPTION: GLThread 545
10-21 16:44:00.737: E/AndroidRuntime(20351): Process: org.artoolkit.ar.samples.ARNative, PID: 20351
10-21 16:44:00.737: E/AndroidRuntime(20351): java.lang.ArrayIndexOutOfBoundsException: length=0; index=0
10-21 16:44:00.737: E/AndroidRuntime(20351): at com.threed.jpct.CompiledInstance._fill(CompiledInstance.java:1223)
10-21 16:44:00.737: E/AndroidRuntime(20351): at com.threed.jpct.CompiledInstance.fill(CompiledInstance.java:844)
10-21 16:44:00.737: E/AndroidRuntime(20351): at com.threed.jpct.Object3DCompiler.compile(Object3DCompiler.java:168)
10-21 16:44:00.737: E/AndroidRuntime(20351): at com.threed.jpct.World.compile(World.java:2091)
10-21 16:44:00.737: E/AndroidRuntime(20351): at com.threed.jpct.World.renderScene(World.java:1061)
10-21 16:44:00.737: E/AndroidRuntime(20351): at org.artoolkit.ar.samples.ARNative.Renderer.onDrawFrame(Renderer.java:210)
10-21 16:44:00.737: E/AndroidRuntime(20351): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1522)
10-21 16:44:00.737: E/AndroidRuntime(20351): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1239)

EgonOlsen

Which version of jPCT-AE are you using? Are you adding/removing objects in some thread parallel to the rendering thread? Can you please post the log output that comes before this exception (some 100-200 lines or something).

cefengxu

i have no idea witch version but  i got the jpct on " http://www.jpct.net/download.html " one month ago.

all i did just posted the code from " Helloworld Project "  to my project.  within three function as belown:
- onSurfaceCreated
- onSurfaceChanged
- onDrawFrame

to show a cube on the real-time preview on the phone ( lots of android phone were tried .)
the log you need was show belown:
thanks you again ,EgonOlsen

10-22 10:24:47.643: I/Configuration(25659): Configuration getConfigurationFromSysProp name= persist.sys.font_scale value=
10-22 10:24:47.653: I/Configuration(25659): Configuration getConfigurationFromSysProp name= persist.sys.font_scale value=
10-22 10:24:47.653: I/Configuration(25659): Configuration getConfigurationFromSysProp name= persist.sys.font_scale value=
10-22 10:24:47.653: I/Configuration(25659): Configuration getConfigurationFromSysProp name= persist.sys.font_scale value=
10-22 10:24:47.713: I/AssetHelper(25659): Using cached folder 'Data'.
10-22 10:24:47.723: I/Configuration(25659): Configuration getConfigurationFromSysProp name= persist.sys.font_scale value=
10-22 10:24:47.723: I/Configuration(25659): Configuration getConfigurationFromSysProp name= persist.sys.font_scale value=
10-22 10:24:47.903: I/ARNativeNative(25659): nativeDisplayParametersChanged orientation=1, size=1920x1080@480pi
10-22 10:24:47.923: D/wangcy9(25659): setStatusIcon occur wrong theme!
10-22 10:24:47.963: I/ARNativeNative(25659): nativeCreate
10-22 10:24:47.963: E/ARNativeNative(25659): Marker count = 1
10-22 10:24:47.963: I/ARNativeNative(25659): nativeStart
10-22 10:24:47.963: I/libar(25659): Using default video config.
10-22 10:24:47.973: I/Configuration(25659): Configuration getConfigurationFromSysProp name= persist.sys.font_scale value=
10-22 10:24:47.983: I/Configuration(25659): Configuration getConfigurationFromSysProp name= persist.sys.font_scale value=
10-22 10:24:47.993: I/Configuration(25659): Configuration getConfigurationFromSysProp name= persist.sys.font_scale value=
10-22 10:24:47.993: I/Configuration(25659): Configuration getConfigurationFromSysProp name= persist.sys.font_scale value=
10-22 10:24:48.013: D/OpenGLRenderer(25659): Render dirty regions requested: true
10-22 10:24:48.033: D/ActivityThread(25659): updateParameter() changefont = false; fontpath=/system/fonts/LenovoFont.ttf; titlefontpath=/system/fonts/LenovoFont.ttf
10-22 10:24:48.033: D/FontThemeManager(25659): FontThemeManager createThemeFont typefacetype=0, curfontpath=/system/fonts/LenovoFont.ttf
10-22 10:24:48.043: I/ARNativeNative(25659): nativeStop
10-22 10:24:48.043: I/ARNativeNative(25659): nativeDestroy
10-22 10:24:48.053: I/Configuration(25659): Configuration getConfigurationFromSysProp name= persist.sys.font_scale value=
10-22 10:24:48.153: I/Configuration(25659): Configuration getConfigurationFromSysProp name= persist.sys.font_scale value=
10-22 10:24:48.183: I/ARNativeNative(25659): nativeDisplayParametersChanged orientation=1, size=1920x1080@480pi
10-22 10:24:48.183: D/wangcy9(25659): setStatusIcon occur wrong theme!
10-22 10:24:48.213: I/ARNativeNative(25659): nativeCreate
10-22 10:24:48.213: E/ARNativeNative(25659): Marker count = 1
10-22 10:24:48.223: I/ARNativeNative(25659): nativeStart
10-22 10:24:48.223: I/libar(25659): Using default video config.
10-22 10:24:48.243: I/Configuration(25659): Configuration getConfigurationFromSysProp name= persist.sys.font_scale value=
10-22 10:24:48.243: I/Configuration(25659): Configuration getConfigurationFromSysProp name= persist.sys.font_scale value=
10-22 10:24:48.243: I/Configuration(25659): Configuration getConfigurationFromSysProp name= persist.sys.font_scale value=
10-22 10:24:48.243: I/Configuration(25659): Configuration getConfigurationFromSysProp name= persist.sys.font_scale value=
10-22 10:24:48.273: D/ViewRootImpl(25659): loadSystemProperties PersistDebugEvent: false RoDebugEvent: false
10-22 10:24:48.353: I/Adreno-EGL(25659): <qeglDrvAPI_eglInitialize:379>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_LA.BR.1.1.2_RB1.05.00.02.031.021_msm8916_64_LA.BR.1.1.2_RB1__release_AU ()
10-22 10:24:48.353: I/Adreno-EGL(25659): OpenGL ES Shader Compiler Version: E031.25.03.02
10-22 10:24:48.353: I/Adreno-EGL(25659): Build Date: 03/12/15 Thu
10-22 10:24:48.353: I/Adreno-EGL(25659): Local Branch: mybranch8269035
10-22 10:24:48.353: I/Adreno-EGL(25659): Remote Branch: quic/LA.BR.1.1.2_rb1.13
10-22 10:24:48.353: I/Adreno-EGL(25659): Local Patches: NONE
10-22 10:24:48.353: I/Adreno-EGL(25659): Reconstruct Branch: AU_LINUX_ANDROID_LA.BR.1.1.2_RB1.05.00.02.031.021 +  NOTHING
10-22 10:24:48.353: I/OpenGLRenderer(25659): Initialized EGL, version 1.4
10-22 10:24:48.373: D/OpenGLRenderer(25659): Enabling debug mode 0
10-22 10:24:48.383: I/qdutils(25659): PartialUpdate status: Disabled
10-22 10:24:48.383: I/qdutils(25659): Left Align: 0
10-22 10:24:48.383: I/qdutils(25659): Width Align: 0
10-22 10:24:48.383: I/qdutils(25659): Top Align: 0
10-22 10:24:48.383: I/qdutils(25659): Height Align: 0
10-22 10:24:48.383: I/qdutils(25659): Min ROI Width: 0
10-22 10:24:48.383: I/qdutils(25659): Min ROI Height: 0
10-22 10:24:48.383: I/qdutils(25659): Needs ROI Merge: 0
10-22 10:24:48.383: I/qdutils(25659): Dynamic Fps: Disabled
10-22 10:24:48.383: I/qdutils(25659): Min Panel fps: 0
10-22 10:24:48.383: I/qdutils(25659): Max Panel fps: 0
10-22 10:24:48.483: I/CameraSurface(25659): Opening camera.
10-22 10:24:49.223: I/ARNativeNative(25659): nativeVideoInit
10-22 10:24:49.223: I/ARNativeNative(25659): Video camera 0 (rear), 640x480 format AR_PIXEL_FORMAT_NV21, 460800-byte buffer.
10-22 10:24:49.223: I/libar(25659): cparamSearch beginning search for LENOVO/Lenovo Z90/msm8916, camera 0, aspect ratio 4:3.
10-22 10:24:49.223: E/libar(25659): Error during cparamSearch. Internet connection unavailable.
10-22 10:24:49.223: E/ARNativeNative(25659): Unable to automatically determine camera parameters. Using default.
10-22 10:24:49.223: I/ARNativeNative(25659): *** Camera Parameter resized from 1280, 1024. ***
10-22 10:24:49.223: I/ARNativeNative(25659): *** Camera Parameter ***
10-22 10:24:49.223: I/libar(25659): --------------------------------------
10-22 10:24:49.223: I/libar(25659): SIZE = 640, 480
10-22 10:24:49.223: I/libar(25659): Distortion factor: k1=0.1147807688, k2=-0.5208189487, p1=-0.0002069871, p2=-0.0040593124
10-22 10:24:49.223: I/libar(25659):                   fx=674.171631, fy=633.898071, x0=318.297791, y0=237.900467, s=0.993923
10-22 10:24:49.223: I/libar(25659): 678.29388
10-22 10:24:49.223: I/libar(25659): 0.00000
10-22 10:24:49.223: I/libar(25659): 318.29779
10-22 10:24:49.223: I/libar(25659): 0.00000
10-22 10:24:49.223: I/libar(25659): 0.00000
10-22 10:24:49.223: I/libar(25659): 637.77411
10-22 10:24:49.223: I/libar(25659): 237.90047
10-22 10:24:49.223: I/libar(25659): 0.00000
10-22 10:24:49.223: I/libar(25659): 0.00000
10-22 10:24:49.223: I/libar(25659): 0.00000
10-22 10:24:49.223: I/libar(25659): 1.00000
10-22 10:24:49.223: I/libar(25659): 0.00000
10-22 10:24:49.223: I/libar(25659): --------------------------------------
10-22 10:24:49.263: W/GL2SurfaceView(25659): creating OpenGL ES 2.0 context
10-22 10:24:49.273: D/ViewRootImpl(25659): loadSystemProperties PersistDebugEvent: false RoDebugEvent: false
10-22 10:24:49.283: I/Choreographer(25659): Skipped 59 frames!  The application may be doing too much work on its main thread.
10-22 10:24:49.293: I/ARNativeNative(25659): nativeSurfaceCreated
10-22 10:24:49.303: I/ARNativeNative(25659): nativeSurfaceChanged backingWidth=1920, backingHeight=1080
10-22 10:24:49.323: I/jPCT-AE(25659): GL context is 951340409
10-22 10:24:49.333: E/libEGL(25659): called unimplemented OpenGL ES API
10-22 10:24:49.333: W/Adreno-ES20(25659): <process_gl_state_enables:519>: GL_INVALID_ENUM
10-22 10:24:49.333: I/jPCT-AE(25659): OpenGL vendor:     Qualcomm
10-22 10:24:49.333: I/jPCT-AE(25659): OpenGL renderer:   Adreno (TM) 405
10-22 10:24:49.333: I/jPCT-AE(25659): OpenGL version:    OpenGL ES 3.0 V@100.0 AU@05.00.02.031.021 (GIT@)
10-22 10:24:49.333: I/jPCT-AE(25659): OpenGL renderer initialized (using 0/0 texture stages)
10-22 10:24:49.343: I/jPCT-AE(25659): Adding Lightsource: 0
10-22 10:24:49.353: I/jPCT-AE(25659): Loading Texture...
10-22 10:24:49.353: I/jPCT-AE(25659): Texture loaded...16384 bytes/64*64 pixels!
10-22 10:24:49.363: I/jPCT-AE(25659): Normal vectors calculated in 2ms!
10-22 10:24:49.363: I/jPCT-AE(25659): Memory usage before compacting: 18893 KB used out of 48206 KB. Max. memory available to the VM is 131072 KB.
10-22 10:24:49.403: I/art(25659): Explicit concurrent mark sweep GC freed 5101(407KB) AllocSpace objects, 9(272KB) LOS objects, 64% free, 17MB/49MB, paused 795us total 38.622ms
10-22 10:24:49.403: I/ARNativeNative(25659): nativeVideoFrame !VIDEO
10-22 10:24:49.403: I/ARNativeNative(25659): nativeVideoFrame !VIDEO
10-22 10:24:49.403: I/ARNativeNative(25659): nativeVideoFrame !VIDEO
10-22 10:24:49.433: I/ARNativeNative(25659): nativeVideoFrame !VIDEO
10-22 10:24:49.433: I/ARNativeNative(25659): nativeVideoFrame !VIDEO
10-22 10:24:49.433: I/Timeline(25659): Timeline: Activity_idle id: android.os.BinderProxy@249d44e6 time:31203199
10-22 10:24:49.443: I/Timeline(25659): Timeline: Activity_idle id: android.os.BinderProxy@249d44e6 time:31203200
10-22 10:24:49.453: I/art(25659): Explicit concurrent mark sweep GC freed 776(55KB) AllocSpace objects, 0(0B) LOS objects, 64% free, 17MB/49MB, paused 712us total 29.421ms
10-22 10:24:49.603: I/jPCT-AE(25659): Memory usage after compacting: 18162 KB used out of 50929 KB. Max. memory available to the VM is 131072 KB.
10-22 10:24:49.603: I/ARNativeNative(25659): nativeDrawFrame
10-22 10:24:49.603: I/ARNativeNative(25659): Initialising ARView
10-22 10:24:49.603: I/ARNativeNative(25659): Setting up argl.
10-22 10:24:49.613: I/ARNativeNative(25659): argl setup OK.
10-22 10:24:49.613: I/ARNativeNative(25659): ARView initialised.
10-22 10:24:49.613: E/ARNativeNative(25659): Viewport={0, -180, 1920, 1440}
10-22 10:24:49.613: I/ARNativeNative(25659): after glClear() glError (0x500)
10-22 10:24:49.613: W/Adreno-ES20(25659): <process_gl_state_enables:519>: GL_INVALID_ENUM
10-22 10:24:49.613: W/jPCT-AE(25659): [ 1445480689625 ] - WARNING: State: 0/0/0/0/0/0/0
10-22 10:24:49.653: I/ARNativeNative(25659): nativeVideoFrame
10-22 10:24:49.653: E/AndroidRuntime(25659): FATAL EXCEPTION: GLThread 646
10-22 10:24:49.653: E/AndroidRuntime(25659): Process: org.artoolkit.ar.samples.ARNative, PID: 25659
10-22 10:24:49.653: E/AndroidRuntime(25659): java.lang.ArrayIndexOutOfBoundsException: length=0; index=0
10-22 10:24:49.653: E/AndroidRuntime(25659): at com.threed.jpct.CompiledInstance._fill(CompiledInstance.java:1223)
10-22 10:24:49.653: E/AndroidRuntime(25659): at com.threed.jpct.CompiledInstance.fill(CompiledInstance.java:844)
10-22 10:24:49.653: E/AndroidRuntime(25659): at com.threed.jpct.Object3DCompiler.compile(Object3DCompiler.java:168)
10-22 10:24:49.653: E/AndroidRuntime(25659): at com.threed.jpct.World.compile(World.java:2091)
10-22 10:24:49.653: E/AndroidRuntime(25659): at com.threed.jpct.World.renderScene(World.java:1061)
10-22 10:24:49.653: E/AndroidRuntime(25659): at org.artoolkit.ar.samples.ARNative.Renderer.onDrawFrame(Renderer.java:215)
10-22 10:24:49.653: E/AndroidRuntime(25659): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1522)
10-22 10:24:49.653: E/AndroidRuntime(25659): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1239)
10-22 10:24:49.853: I/CameraSurface(25659): Closing camera.
10-22 10:24:50.053: D/ActivityThread(25659): updateParameter() changefont = false; fontpath=/system/fonts/LenovoFont.ttf; titlefontpath=/system/fonts/LenovoFont.ttf
10-22 10:24:50.053: D/FontThemeManager(25659): FontThemeManager createThemeFont typefacetype=0, curfontpath=/system/fonts/LenovoFont.ttf
10-22 10:24:51.513: I/ARNativeNative(25659): nativeStop
10-22 10:24:51.533: I/ARNativeNative(25659): nativeDestroy

cefengxu

BTW, i post my  " render class  implements Renderer " for you :

public class Renderer implements GLSurfaceView.Renderer {

private  final Context context;
private int program;

private int aPositionLocation;
private int uMatrixLocation;

private final float[] projectionMatrix = new float[16];
private final float[] modelMatrix = new float[16];

public int flag1;
public int flag2;
public int model_index;

private FrameBuffer fb = null;
private World world = null;
private RGBColor back = new RGBColor(100, 100, 150);
private boolean stop = false;
private Light sun = null;
private Camera cam;
private long ticks = 0;

private Model alita = null;
public static Context con;
private Resources res=null;
public static int stat=0;
public static List<String> animations=null;
private Object3D cube = null;

public Renderer(Context context) {
flag1 = 0;
flag2 = 1;
model_index = 0 ;
this.context = context;
Model.context = context;
}

    public void onSurfaceCreated(GL10 unused, EGLConfig config) {               
    ARNativeActivity.nativeSurfaceCreated();
   
   
glClearColor(0.0f,0.0f,0.0f,0.0f);

    }

    private int sub_w;
    private int sub_h;
    public void onSurfaceChanged(GL10 unused, int width, int height) {       
    ARNativeActivity.nativeSurfaceChanged(width, height);
glViewport(0, 0,width, height);
sub_w = width;
sub_h = height;

if (fb != null) {
fb.dispose();
}
fb = new FrameBuffer(unused, width, height);

world = new World();
world.setAmbientLight(20, 20, 20);

sun = new Light(world);
sun.setIntensity(250, 250, 250);


Texture texture = new Texture(BitmapHelper.rescale(BitmapHelper.convert(context.getResources().getDrawable(R.drawable.icon)), 64, 64));
TextureManager.getInstance().addTexture("texture", texture);

cube = Primitives.getCube(50);
cube.calcTextureWrapSpherical();
cube.setTexture("texture");
cube.strip();
cube.build();

world.addObject(cube);

Camera cam = world.getCamera();
cam.moveCamera(Camera.CAMERA_MOVEOUT, 50);
cam.lookAt(cube.getTransformedCenter());

SimpleVector sv = new SimpleVector();
sv.set(cube.getTransformedCenter());
sv.y -= 100;
sv.z -= 100;
sun.setPosition(sv);
MemoryHelper.compact();


    }

    public void onDrawFrame(GL10 unused) {

ARNativeActivity.nativeDrawFrame();

// try {
if (fb != null) {
fb.clear();
world.renderScene(fb);
world.draw(fb);
fb.display();
Logger.log("Drawing thread running!", Logger.MESSAGE);
}


    } 

EgonOlsen

You are mixing OpenGL versions here. You are obviously using a GL 2.0 context:


10-22 10:24:49.263: W/GL2SurfaceView(25659): creating OpenGL ES 2.0 context


...but you are using the 1.x construtor of FrameBuffer:


fb = new FrameBuffer(unused, width, height);


Just naming the context instance "unused" doesn't help here. You have to use the constructor without it.

All this finally leads to


10-22 10:24:49.333: E/libEGL(25659): called unimplemented OpenGL ES API


...and then the actual crash follows.

cefengxu

Thank you so much !!!

but ,as you said ,"You have to use the constructor without it."
actually, i still have no idea how to do ??

i try to use the function [ setEGLContextClientVersion(1)] to  fix it just now but no work~~

EgonOlsen

FrameBuffer has two constructors. One with GL context and one without. For a GL 2.0 compatible buffer instance, use the one without. However, this has to match the requirements of your native components. You can't use 1.x related commands on  2.0 context and vice versa. jPCT-AE will take care of that by itself, but it doesn't know if anything else calls GL commands behind it's back.

cefengxu

got it !~ just using another constructor FrameBuffer(/*unused, */width, height);

however , i got another problem . due to it's a new issue so iwill post new one.

thanks again , i spents 8 hours on line to waiting for you today.

::)