Android Question Null Exception Error on Stopping Camera

swabygw

Active Member
Licensed User
Longtime User
Frequently, when executing the following command to stop the camera:
B4X:
cam.StopVideoRecording (MyTaskIndex)
This error comes up: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Surface android.hardware.camera2.params.OutputConfiguration.getSurface()' on a null object reference

The emulator that I'm using is Android 7.0 API 24. This error doesn't occur on my personal phone, which is an LGE and also Android 7.0. The error also goes away if I clean the project, but comes back after the first (or second) run.

Here's an image of the code and output (line 257 is where the error occurs).

upload_2017-12-13_9-0-8.png


Below is an unfiltered output of logs:

Arming #b911b9e484784d31bced7f508881bcaa
Recording #b911b9e484784d31bced7f508881bcaa
getCameraInfo
getCameraInfo
getCameraInfo
getCameraInfo
getCameraInfo
getCameraInfo
getCameraInfo
getCameraInfo
getCameraInfo
getCameraInfo
Using legacy camera HAL.
CameraService::connect call (PID -1 "b4a.example", camera ID 0) for HAL version default and Camera API version 1
getCameraInfo
getCameraInfo
notifyListener_l(0xabd0cb40), (1, 0, 0), loop setting(0, 0)
notifyListener_l(0xabd0c960), (1, 0, 0), loop setting(0, 0)
notifyListener_l(0xabd0c7e0), (1, 0, 0), loop setting(0, 0)
Opening camera 0
getCameraInfo
getCameraInfo
connectCamera
connectDevice
setCallbacks: 0xab62deb0, 0xab62df00, 0xab62e020, 0xab62e140 (0xab1330a0)
enableMessage: msg_type = 0xc0d
CAMERA_MSG_ERROR
CAMERA_MSG_FOCUS
CAMERA_MSG_ZOOM
CAMERA_MSG_PREVIEW_METADATA
**** Currently enabled messages:
CAMERA_MSG_ERROR
CAMERA_MSG_FOCUS
CAMERA_MSG_ZOOM
CAMERA_MSG_PREVIEW_METADATA
getCameraInfo
getCameraInfo
getCameraInfo
getCameraInfo
getCameraInfo
getCameraInfo
getCameraInfo
getCameraInfo
Do partial code cache collection, code=30KB, data=30KB
After code cache collection, code=29KB, data=29KB
Increasing code cache capacity to 128KB
MediaPlayerService::getOMX
MuxOMX ctor
makeComponentInstance(OMX.google.h264.encoder) in mediacodec process
MediaCodec will operate in async mode
do not know color format 0x7f000789 = 2130708361
setupAVCEncoderParameters with [profile: Baseline] [level: Level41]
[OMX.google.h264.encoder] cannot encode color aspects. Ignoring.
[OMX.google.h264.encoder] cannot encode HDR static metadata. Ignoring.
setupVideoEncoder succeeded
setConfig(50c0030:google.h264.encoder, ConfigPriority(0x6f800002)) ERROR: Undefined(0x80001001)
codec does not support config priority (err -2147483648)
do not know color format 0x7f000789 = 2130708361
setting dataspace: 0x103
requesting color aspects (R:2(Limited), P:4(BT601_6_525), M:3(BT601_6), T:3(SMPTE170M))
Server adjusted notificationFrames from 1024 to 160 for frameCount 2048
Params width 640 height 480 level 41 colorFormat 0
MediaPlayerService::getOMX
MuxOMX ctor
makeComponentInstance(OMX.google.aac.encoder) in mediacodec process
MediaCodec will operate in async mode
setConfig(50c0031:google.aac.encoder, ConfigPriority(0x6f800002)) ERROR: Undefined(0x80001001)
codec does not support config priority (err -2147483648)
AudioFlinger's thread 0xa8e121c0 ready to run
Legacy camera service transitioning to state CONFIGURING
Configure outputs: 2 surfaces configured.
app passed NULL surface
HostConnection::get() New Host Connection established 0xa5d08580, tid 2989
Unrecognized GLES max version string in extensions: ANDROID_EMU_CHECKSUM_HELPER_v1
eglCreateContext: 0xa5d05480: maj 2 min 0 rcv 2
gralloc_alloc: Creating ashmem region of size 1228800
eglMakeCurrent: 0xa5d05480: ver 2 0 (tinfo 0xa5d03430)
eglQueryContext 32c0 EGL_BAD_ATTRIBUTE
tid 2989: eglQueryContext(1716): error 0x3004 (EGL_BAD_ATTRIBUTE)
setParameters
Legacy camera service transitioning to state IDLE
Repeating capture request set.
convertRequestMetadata - control.awbRegions setting is not supported, ignoring value
convertRequestToMetadata - Ignoring android.lens.focusDistance false, only 0.0f is supported
setParameters
=== Value changed: jpeg-quality: 90 -> 85
=== Value changed: jpeg-thumbnail-quality: 90 -> 85
=== Value changed: recording-hint: false -> true
setPreviewWindow: current: 0x0 -> new: 0xab1330b0
doStartPreview
startPreview
Starting camera: 640x480 -> YV12
startDevice
commonStartDevice: Allocated 460800 bytes for 307200 pixels in YV12[640x480] frame
startDeliveringFrames
startWorkerThread
Starting worker thread, oneBurst=false
Starting worker thread, oneBurst=false
limits: 4294967295/0 bytes/us, bit rate: 10012200 bps and the estimated moov size 3193 bytes
Start time offset: 200000 us
MediaCodecSource (video) starting
MediaCodecSource (video) started
Start time offset: 200000 us
MediaCodecSource (audio) starting
onNextFrameAvailable: Adjusting preview windows 0xab1330b0 geometry to 640x480
gralloc_alloc: Creating ashmem region of size 1228800
MediaCodecSource (audio) started
HostConnection::get() New Host Connection established 0xa5d081c0, tid 2946
Unrecognized GLES max version string in extensions: ANDROID_EMU_CHECKSUM_HELPER_v1
HostConnection::get() New Host Connection established 0xab132400, tid 2990
Unrecognized GLES max version string in extensions: ANDROID_EMU_CHECKSUM_HELPER_v1
Legacy camera service transitioning to state CAPTURING
eglMakeCurrent: 0xa5d05480: ver 2 0 (tinfo 0xa5d03430)
gralloc_alloc: Creating ashmem region of size 1228800
HostConnection::get() New Host Connection established 0x94953940, tid 2996
Unrecognized GLES max version string in extensions: ANDROID_EMU_CHECKSUM_HELPER_v1
got buffer with new dataSpace #103
dataspace changed to 0x10c40000 (R:2(Limited), P:4(BT601_6_525), M:3(BT601_6), T:3(SMPTE170M)) (R:2(Limited), S:4(BT601_525), T:3(SMPTE_170M))
eglMakeCurrent: 0xa5d05480: ver 2 0 (tinfo 0xa5d03430)
eglMakeCurrent: 0xa5d05480: ver 2 0 (tinfo 0xa5d03430)
HostConnection::get() New Host Connection established 0xa5d08280, tid 2947
Unrecognized GLES max version string in extensions: ANDROID_EMU_CHECKSUM_HELPER_v1
eglMakeCurrent: 0xa5d05480: ver 2 0 (tinfo 0xa5d03430)
eglMakeCurrent: 0xa5d05480: ver 2 0 (tinfo 0xa5d03430)
eglMakeCurrent: 0xa5d05480: ver 2 0 (tinfo 0xa5d03430)
eglMakeCurrent: 0xa5d05480: ver 2 0 (tinfo 0xa5d03430)
eglMakeCurrent: 0xa5d05480: ver 2 0 (tinfo 0xa5d03430)
eglMakeCurrent: 0xa5d05480: ver 2 0 (tinfo 0xa5d03430)
gralloc_alloc: Creating ashmem region of size 1228800
HostConnection::get() New Host Connection established 0xaae08800, tid 2982
Unrecognized GLES max version string in extensions: ANDROID_EMU_CHECKSUM_HELPER_v1
setStartTimestampUs: 12233
Earliest track starting time: 12233
eglMakeCurrent: 0xa5d05480: ver 2 0 (tinfo 0xa5d03430)
eglMakeCurrent: 0xa5d05480: ver 2 0 (tinfo 0xa5d03430)
eglMakeCurrent: 0xa5d05480: ver 2 0 (tinfo 0xa5d03430)
eglMakeCurrent: 0xa5d05480: ver 2 0 (tinfo 0xa5d03430)
eglMakeCurrent: 0xa5d05480: ver 2 0 (tinfo 0xa5d03430)
eglMakeCurrent: 0xa5d05480: ver 2 0 (tinfo 0xa5d03430)
eglMakeCurrent: 0xa5d05480: ver 2 0 (tinfo 0xa5d03430)
eglMakeCurrent: 0xa5d05480: ver 2 0 (tinfo 0xa5d03430)
eglMakeCurrent: 0xa5d05480: ver 2 0 (tinfo 0xa5d03430)
eglMakeCurrent: 0xa5d05480: ver 2 0 (tinfo 0xa5d03430)
eglMakeCurrent: 0xa5d05480: ver 2 0 (tinfo 0xa5d03430)
eglMakeCurrent: 0xa5d05480: ver 2 0 (tinfo 0xa5d03430)
eglMakeCurrent: 0xa5d05480: ver 2 0 (tinfo 0xa5d03430)
eglMakeCurrent: 0xa5d05480: ver 2 0 (tinfo 0xa5d03430)
eglMakeCurrent: 0xa5d05480: ver 2 0 (tinfo 0xa5d03430)
eglMakeCurrent: 0xa5d05480: ver 2 0 (tinfo 0xa5d03430)
setStartTimestampUs: 24308
eglMakeCurrent: 0xa5d05480: ver 2 0 (tinfo 0xa5d03430)
eglMakeCurrent: 0xa5d05480: ver 2 0 (tinfo 0xa5d03430)
eglMakeCurrent: 0xa5d05480: ver 2 0 (tinfo 0xa5d03430)
eglMakeCurrent: 0xa5d05480: ver 2 0 (tinfo 0xa5d03430)
Stopping #b911b9e484784d31bced7f508881bcaa. Upload will begin shortly.
Stop video recording true
Stop video recording true
Repeating capture request cancelled.
Flushing all pending requests.
cancel failed: no repeating request exists.
Buffer drop error reported for unknown Surface
Legacy camera service transitioning to state IDLE
eglMakeCurrent: 0xa5d05480: ver 2 0 (tinfo 0xa5d03430)
Video track stopping
Video track source stopping
encoder (video) stopping
java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Surface android.hardware.camera2.params.OutputConfiguration.getSurface()' on a null object reference
at android.hardware.camera2.impl.CameraDeviceImpl$CameraDeviceCallbacks.onCaptureErrorLocked(CameraDeviceImpl.java:1891)
at android.hardware.camera2.impl.CameraDeviceImpl$CameraDeviceCallbacks.onDeviceError(CameraDeviceImpl.java:1659)
at android.hardware.camera2.legacy.CameraDeviceUserShim$CameraCallbackThread$CallbackHandler.handleMessage(CameraDeviceUserShim.java:299)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.os.HandlerThread.run(HandlerThread.java:61)
eglMakeCurrent: 0xa5d05480: ver 2 0 (tinfo 0xa5d03430)
Received total/0-length (12/0) buffers and encoded 11 frames. - Video
Dropped back down to Loaded without Executing
[GraphicBufferSource] queueBuffer: BufferQueue has been abandoned
queueBuffer: error queuing buffer to SurfaceTexture, -19
[GraphicBufferSource] dequeueBuffer: BufferQueue has been abandoned
tid 2989: swapBuffers(547): error 0x300d (EGL_BAD_SURFACE)
Surface abandoned, dropping frame.
android.hardware.camera2.legacy.LegacyExceptionUtils$BufferQueueAbandonedException
at android.hardware.camera2.legacy.SurfaceTextureRenderer.swapBuffers(SurfaceTextureRenderer.java:533)
at android.hardware.camera2.legacy.SurfaceTextureRenderer.drawIntoSurfaces(SurfaceTextureRenderer.java:751)
at android.hardware.camera2.legacy.GLThreadManager$1.handleMessage(GLThreadManager.java:105)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:154)
at android.os.HandlerThread.run(HandlerThread.java:61)
previewProduced called with no preview request on queue!
encoder (video) stopped
failed to post message as target looper for handler 0 is gone.
Video track source stopped
Video track stopped
Audio track stopping
Audio track source stopping
encoder (audio) stopping
0-duration samples found: 1
Received total/0-length (2/0) buffers and encoded 1 frames. - Audio
Audio track drift time: 0 us
encoder (audio) stopped
Audio track source stopped
Audio track stopped
Duration from tracks range is [0, 470155] us
Stopping writer thread
0 chunks are written in the last batch
Writer thread stopped
Video track stopping
Audio track stopping
Stopped video recording
tid 2950: eglSurfaceAttrib(1227): error 0x3009 (EGL_BAD_MATCH)
Failed to set EGL_SWAP_BEHAVIOR on surface 0x9494fda0, error=EGL_BAD_MATCH
eglMakeCurrent: 0xa153eaa0: ver 2 0 (tinfo 0xa1fe7520)
FATAL EXCEPTION: LegacyCameraCallback
Process: b4a.example, PID: 2934
java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Surface android.hardware.camera2.params.OutputConfiguration.getSurface()' on a null object reference
at android.hardware.camera2.impl.CameraDeviceImpl$CameraDeviceCallbacks.onCaptureErrorLocked(CameraDeviceImpl.java:1891)
at android.hardware.camera2.impl.CameraDeviceImpl$CameraDeviceCallbacks.onDeviceError(CameraDeviceImpl.java:1659)
at android.hardware.camera2.legacy.CameraDeviceUserShim$CameraCallbackThread$CallbackHandler.handleMessage(CameraDeviceUserShim.java:299)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.os.HandlerThread.run(HandlerThread.java:61)
Force finishing activity b4a.example/.main
** Activity (main) Pause, UserClosed = true **
Initialized EGL, version 1.4
Swap behavior 1
eglCreateContext: 0xa153ef20: maj 2 min 0 rcv 2
eglMakeCurrent: 0xa153ef20: ver 2 0 (tinfo 0x933fe100)
failed to deliver message as target handler 110 is gone.
tid 2327: eglSurfaceAttrib(1227): error 0x3009 (EGL_BAD_MATCH)
Failed to set EGL_SWAP_BEHAVIOR on surface 0x946e43c0, error=EGL_BAD_MATCH
eglMakeCurrent: 0xa153ef20: ver 2 0 (tinfo 0x933fe100)
gralloc_alloc: Creating ashmem region of size 2650112
failed to deliver message as target handler 113 is gone.
eglMakeCurrent: 0xa1576fc0: ver 2 0 (tinfo 0x946105f0)
HostConnection::get() New Host Connection established 0x942a3a80, tid 1554
Unrecognized GLES max version string in extensions: ANDROID_EMU_CHECKSUM_HELPER_v1
tid 1283: eglCreateSyncKHR(1901): error 0x3004 (EGL_BAD_ATTRIBUTE)
Long monitor contention with owner Binder:1543_1 (1554) at void com.android.server.am.ActivityManagerService.activityPaused(android.os.IBinder)(ActivityManagerService.java:6879) waiters=0 in void com.android.server.am.ActivityStackSupervisor$ActivityStackSupervisorHandler.activityIdleInternal(com.android.server.am.ActivityRecord) for 164ms
eglMakeCurrent: 0xa153eaa0: ver 2 0 (tinfo 0xa1fe7520)
Background partial concurrent mark sweep GC freed 54401(3MB) AllocSpace objects, 5(264KB) LOS objects, 26% free, 10MB/14MB, paused 2.448ms total 167.412ms
tid 2056: eglSurfaceAttrib(1227): error 0x3009 (EGL_BAD_MATCH)
Failed to set EGL_SWAP_BEHAVIOR on surface 0x94646000, error=EGL_BAD_MATCH
eglMakeCurrent: 0xa1ffbb60: ver 2 0 (tinfo 0xac6b0300)
eglMakeCurrent: 0xa1576fc0: ver 2 0 (tinfo 0x946105f0)
eglMakeCurrent: 0xa153eaa0: ver 2 0 (tinfo 0xa1fe7520)
Incorrectly called buildLayer on View: ShortcutAndWidgetContainer, destroying layer...
Incorrectly called buildLayer on View: ShortcutAndWidgetContainer, destroying layer...
Destroying surface Surface(name=b4a.example/b4a.example.main) called by com.android.server.wm.WindowStateAnimator.destroySurface:2014 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked:881 com.android.server.wm.WindowState.removeLocked:1449 com.android.server.wm.WindowManagerService.removeWindowInnerLocked:2478 com.android.server.wm.AppWindowToken.destroySurfaces:365 com.android.server.wm.WindowStateAnimator.finishExit:565 com.android.server.wm.AppWindowAnimator.stepAnimationLocked:427 com.android.server.wm.WindowAnimator.updateAppWindowsLocked:196
Destroying surface Surface(name=Toast) called by com.android.server.wm.WindowStateAnimator.destroySurface:2014 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked:881 com.android.server.wm.WindowState.destroyOrSaveSurface:2073 com.android.server.wm.WindowSurfacePlacer.performSurfacePlacementInner:429 com.android.server.wm.WindowSurfacePlacer.performSurfacePlacementLoop:232 com.android.server.wm.WindowSurfacePlacer.performSurfacePlacement:180 com.android.server.wm.WindowManagerService$H.handleMessage:8079 android.os.Handler.dispatchMessage:102
eglMakeCurrent: 0xa1576fc0: ver 2 0 (tinfo 0x946105f0)
 

swabygw

Active Member
Licensed User
Longtime User
Yes, the application continues to run and it will encounter the error again at the same point. After a few runs, the application will have a fatal error and crash/close. I'll heed your advice and continue testing on the real device.
 
Upvote 0
I know this thread is old, but my god, you have no idea how long I've been trying to debug a null pointer with the legacy camera callback. I have tried so many try/catches... Thank you.
 
Upvote 0
Top