Bug 866 - Frequent IndexOutOfBoundsException in jogamp.opengl.egl.EGLGraphicsConfigurationFactory
Summary: Frequent IndexOutOfBoundsException in jogamp.opengl.egl.EGLGraphicsConfigurat...
Status: RESOLVED FIXED
Alias: None
Product: Jogl
Classification: JogAmp
Component: embedded (show other bugs)
Version: 2
Hardware: embedded_arm other
: --- major
Assignee: Sven Gothel
URL:
Depends on:
Blocks:
 
Reported: 2013-10-23 11:13 CEST by Brice Figureau
Modified: 2013-10-23 16:58 CEST (History)
0 users

See Also:
Type: ---
SCM Refs:
1f8a46cf71d5ecd9b8d649ccb09ccf986c48b960
Workaround: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Brice Figureau 2013-10-23 11:13:33 CEST
In android, with jogl 2.0.2, we get a relatively large number of this exception:



If you look at the jogamp.opengl.egl.EGLGraphicsConfigurationFactory.eglChooseConfig code, you'll find this:



> java.lang.RuntimeException: java.lang.IndexOutOfBoundsException: Invalid index 24, size is 24
>  at jogamp.newt.c.a(SourceFile:220)
>  at jogamp.newt.c.a(SourceFile:135)
>  at jogamp.newt.f.runOnEDTIfAvail(SourceFile:207)
>  at jogamp.newt.v.runOnEDTIfAvail(SourceFile:1670)
>  at jogamp.newt.v.setVisible(SourceFile:834)
>  at jogamp.newt.v.setVisible(SourceFile:839)
>  at com.jogamp.newt.b.a.setVisible(SourceFile:410)
>  at com.daysofwonder.tt.android.NewtBaseActivity.resumePlay(SourceFile:418)
>  at com.daysofwonder.tt.android.NewtBaseActivity.onWindowFocusChanged(SourceFile:145)
>  at com.android.internal.policy.impl.PhoneWindow$DecorView.onWindowFocusChanged(PhoneWindow.java:2451)
>  at android.view.View.dispatchWindowFocusChanged(View.java:7433)
>  at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:930)
>  at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:2934)
>  at android.os.Handler.dispatchMessage(Handler.java:99)
>  at android.os.Looper.loop(Looper.java:137)
>  at android.app.ActivityThread.main(ActivityThread.java:5039)
>  at java.lang.reflect.Method.invokeNative(Native Method)
>  at java.lang.reflect.Method.invoke(Method.java:511)
>  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
>  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
>  at dalvik.system.NativeStart.main(Native Method)
> Caused by: java.lang.IndexOutOfBoundsException: Invalid index 24, size is 24
>  at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
>  at java.util.ArrayList.remove(ArrayList.java:399)
>  at jogamp.opengl.egl.EGLGraphicsConfigurationFactory.eglChooseConfig(SourceFile:421)
>  at jogamp.opengl.egl.EGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(SourceFile:251)
>  at jogamp.newt.driver.android.WindowDriver.createNativeImpl(SourceFile:345)
>  at jogamp.newt.v.createNative(SourceFile:313)
>  at jogamp.newt.v.setVisibleActionImpl(SourceFile:776)
>  at jogamp.newt.J.run(SourceFile:826)
>  at com.jogamp.common.util.M.run(SourceFile:112)
>  at jogamp.newt.e.run(SourceFile:331)

If you look at the code in jogamp.opengl.egl.EGLGraphicsConfigurationFactory.eglChooseConfig, you'll find this:

>            List<GLCapabilitiesImmutable> removedCaps = new ArrayList<GLCapabilitiesImmutable>();
>            for(int i=0; i<availableCaps.size(); ) {
>                final GLCapabilitiesImmutable aCap = availableCaps.get(i);
>                if(aCap.getVisualID(VIDType.NATIVE) != nativeVisualID) {
>                    if(DEBUG) { System.err.println("Remove["+i+"] (mismatch VisualID): "+aCap); }
>                    removedCaps.add(availableCaps.remove(i));
>                } if( 0 == aCap.getDepthBits() && 0 < capsChosen.getDepthBits() ) {
>                    // Hack for HiSilicon/Vivante/Immersion.16 Renderer ..
>                    if(DEBUG) { System.err.println("Remove["+i+"] (mismatch depth-bits): "+aCap); }
>                    removedCaps.add(availableCaps.remove(i));
>                } else {
>                    i++;
>                }
>            }


Notice that there is no "else" before the second if statement, which means that it is possible to remove twice the same element from the array leading to this exception.

Unfortunately this happens a lot of time on some devices, when the application is paused/resumed. We weren't able to reproduce the issue on our own devices, but our crash reporter logged this one (or a variant) quite a lot.

We probably can send a Pull Request since this is a trivial fix.
Comment 1 Sven Gothel 2013-10-23 16:58:53 CEST
Add missing 'else' in branch

Thank you!