Skip to content

[camera_android_camerax] Setting NV21 format for image streaming sometimes throws java.lang.IllegalArgumentException: newPosition > limit #176410

@camsim99

Description

@camsim99

Sometimes, when using using the NV21 format for image streaming via

_controller = CameraController(
  camera,
  ResolutionPreset.high,
  enableAudio: false,
  imageFormatGroup: Platform.isAndroid ? ImageFormatGroup.nv21 : ImageFormatGroup.bgra8888,
);

_controller!.startImageStream(...);

an exception like

E/flutter (21764): [ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: PlatformException(IllegalArgumentException, java.lang.IllegalArgumentException: newPosition > limit: (460800 > 460799), Cause: null, Stacktrace: java.lang.IllegalArgumentException: newPosition > limit: (460800 > 460799)
E/flutter (21764): 	at java.nio.Buffer.createPositionException(Buffer.java:353)
E/flutter (21764): 	at java.nio.Buffer.position(Buffer.java:328)
E/flutter (21764): 	at java.nio.ByteBuffer.position(ByteBuffer.java:1651)
E/flutter (21764): 	at java.nio.MappedByteBuffer.position(MappedByteBuffer.java:417)
E/flutter (21764): 	at io.flutter.plugins.camerax.ImageProxyUtils.areUVPlanesNV21(ImageProxyUtils.java:58)
E/flutter (21764): 	at io.flutter.plugins.camerax.ImageProxyUtils.planesToNV21(ImageProxyUtils.java:21)
E/flutter (21764): 	at io.flutter.plugins.camerax.ImageProxyUtilsProxyApi.getNv21Buffer(ImageProxyUtilsProxyApi.java:29)
E/flutter (21764): 	at io.flutter.plugins.camerax.PigeonApiImageProxyUtils$Companion.setUpMessageHandlers$lambda$1$lambda$0(CameraXLibrary.g.kt:5417)
E/flutter (21764): 	at io.flutter.plugins.camerax.PigeonApiImageProxyUtils$Companion.$r8$lambda$3CMowUUd8Zae3YPJTUaL_fPAX_U(Unknown Source:0)
E/flutter (21764): 	at io.flutter.plugins.camerax.PigeonApiImageProxyUtils$Companion$$ExternalSyntheticLambda0.onMessage(D8$$SyntheticClass:0)
E/flutter (21764): 	at io.flutter.plugin.common.BasicMessageChannel$IncomingMessageHandler.onMessage(BasicMessageChannel.java:261)
E/flutter (21764): 	at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:292)
E/flutter (21764): 	at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
E/flutter (21764): 	at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(D8$$SyntheticClass:0)
E/flutter (21764): 	at android.os.Handler.handleCallback(Handler.java:1041)
E/flutter (21764): 	at android.os.Handler.dispatchMessage(Handler.java:103)
E/flutter (21764): 	at android.os.Looper.dispatchMessage(Looper.java:315)
E/flutter (21764): 	at android.os.Looper.loopOnce(Looper.java:251)
E/flutter (21764): 	at android.os.Looper.loop(Looper.java:349)
E/flutter (21764): 	at android.app.ActivityThread.main(ActivityThread.java:9041)
E/flutter (21764): 	at java.lang.reflect.Method.invoke(Native Method)
E/flutter (21764): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:593)
E/flutter (21764): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:929)
E/flutter (21764): , null)

is thrown. Based on debugging from @Mairramer, this may be because the ImageProxyUtilsProxyApi.getNv21Buffe method in the plugin tries to advance the V buffer by one byte when its position already starts at the end, making the call exceed by the buffer's limit.

Initially reported in #174923 (comment).

Metadata

Metadata

Assignees

Labels

P1High-priority issues at the top of the work listp: cameraThe camera pluginplatform-androidAndroid applications specificallyteam-androidOwned by Android platform teamtriaged-androidTriaged by Android platform team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions