internaut/ogles_gpgpu

Race condition in example OGVideoProcDroid

ruslo opened this issue · 0 comments

ruslo commented

Two threads can simultaneously read/modify imgData variable. This may lead to synchronization errors. I can reproduce such error by adding delay to the update method: https://github.com/ruslo/ogles_gpgpu/commit/efed7c73d234f2814092e34e478d270a40b7c36f

logcat:

I/CamActivity(22340): zeroerror
D/AndroidRuntime(22340): Shutting down VM
W/dalvikvm(22340): threadid=1: thread exiting with uncaught exception (group=0x41620d58)
E/mm-camera(  272): invalid stats mask. Return back
E/AndroidRuntime(22340): FATAL EXCEPTION: main
E/AndroidRuntime(22340): Process: ogles_gpgpu.examples.ogvideoprocdroid, PID: 22340
E/AndroidRuntime(22340): java.lang.NullPointerException
E/AndroidRuntime(22340):    at ogles_gpgpu.examples.ogvideoprocdroid.CamActivity$CPUImgProcThread.update(CamActivity.java:595)
E/AndroidRuntime(22340):    at ogles_gpgpu.examples.ogvideoprocdroid.CamActivity.onFrameAvailable(CamActivity.java:305)
E/AndroidRuntime(22340):    at android.graphics.SurfaceTexture$EventHandler.handleMessage(SurfaceTexture.java:296)
E/AndroidRuntime(22340):    at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime(22340):    at android.os.Looper.loop(Looper.java:136)
E/AndroidRuntime(22340):    at android.app.ActivityThread.main(ActivityThread.java:5095)
E/AndroidRuntime(22340):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(22340):    at java.lang.reflect.Method.invoke(Method.java:515)
E/AndroidRuntime(22340):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
E/AndroidRuntime(22340):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
E/AndroidRuntime(22340):    at dalvik.system.NativeStart.main(Native Method)

Error doesn't occurs after synchronization code added: https://github.com/ruslo/ogles_gpgpu/commit/28e45d17cabce711ed461aa77b375af8e064ca6c (fix will look different after this change).