techyian / MMALSharp

C# wrapper to Broadcom's MMAL with an API to the Raspberry Pi camera.
MIT License
195 stars 33 forks source link

(.NET Core 2.2) Enable Annotation error #104

Closed techyian closed 4 years ago

techyian commented 4 years ago
Unhandled Exception: System.ArgumentException: Type could not be marshaled because the length of an embedded array instance does not match the declared length in the layout.
   at System.Runtime.InteropServices.Marshal.StructureToPtr(Object structure, IntPtr ptr, Boolean fDeleteOld)
   at System.Runtime.InteropServices.Marshal.StructureToPtr[T](T structure, IntPtr ptr, Boolean fDeleteOld)
   at MMALSharp.MMALCameraComponentExtensions.SetAnnotateSettings(MMALCameraComponent camera) in C:\Users\ianau\source\repos\techyian\MMALSharp\src\MMALSharp\MMALCameraExtensions.cs:line 325
techyian commented 4 years ago

This again is due to the way .NET Core handles marshalling arrays using "ByValArray". The array being passed must equal the size specified in the "SizeConst" field or otherwise you'll receive an exception. Mono does not have this restriction and is quite happy to pass an array of lower size if asked.

techyian commented 4 years ago

I have also noticed using the value 256 "SizeConst" causes the MMAL_PARAMETER_CAMERA_ANNOTATE_V4_T/MMAL_PARAMETER_CAMERA_ANNOTATE_V3_T structures to become too large, and MMAL throws a native exception:

mmal: mmal_vc_port_parameter_set: parameter too large (579 > 392)

As a result, I am lowering the SizeConst to 128 chars which brings the structure size down to 324 bytes and MMAL seems happy with that.