-
-
Notifications
You must be signed in to change notification settings - Fork 68
Open
Description
Got a few of these on Prod, they are rare. The properties aren't binded too and set only from within as they are OneWayToSource. Crashes on page appearing.
<barcodeScanning:CameraView x:Name="Scanner"
HorizontalOptions="Fill"
VerticalOptions="Fill"
PoolingInterval="250"
CameraFacing="{Binding CameraFacing}"
PauseScanning="{Binding CameraPaused}"
CameraEnabled="{Binding ScanningActive}" // set on page appearing
OnDetectionFinishedCommand="{Binding BarcodeDetectedCommand}"/>
System.ArgumentException: Argument_AddingDuplicateWithKey, Microsoft.Maui.Controls.BindableProperty
at bool Dictionary<BindableProperty, BindablePropertyContext>.TryInsert(BindableProperty, BindablePropertyContext, InsertionBehavior)()
at void BindableObject.SetValueCore(BindableProperty property, object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes, SetterSpecificity specificity)() in BindableObject.cs:line 575
at void BindableObject.SetValue(BindableProperty property, object value)() in BindableObject.cs:line 496
at void CameraView.set_DeviceSwitchZoomFactor(float[] value)()
at void CameraManager.UpdateZoomFactor()()
at void CameraManager.UpdateCamera()+() => { }()
at void DispatchQueue.static_dispatcher_to_managed(IntPtr context)() in Dispatch.cs:line 391
Argument_AddingDuplicateWithKey, Microsoft.Maui.Controls.BindableProperty (System.ArgumentException)
at System.Collections.Generic.Dictionary`2[[Microsoft.Maui.Controls.BindableProperty, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Controls.BindableObject.BindablePropertyContext, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].TryInsert(BindableProperty , BindablePropertyContext , InsertionBehavior )
at Microsoft.Maui.Controls.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes, SetterSpecificity specificity)
at Microsoft.Maui.Controls.BindableObject.SetValue(BindableProperty property, Object value)
at BarcodeScanning.CameraView.set_MinZoomFactor(Single value)
at BarcodeScanning.CameraManager.UpdateZoomFactor()
at BarcodeScanning.CameraManager.<UpdateCamera>b__24_0()
at CoreFoundation.DispatchQueue.static_dispatcher_to_managed(IntPtr context)
Judging by the code the problem is here in setting MinZoomFactor , MaxZoomFactor and DeviceSwitchZoomFactor not on the main thread. All other cameraView properties in the code are being set using DeviceLock unlike three properties above which are dispatched on DispatchQueue("com.barcodescanning.maui.sessionQueue"
internal void UpdateZoomFactor()
{
if (_cameraView is not null && _captureDevice is not null)
{
_cameraView.MinZoomFactor = (float)_captureDevice.MinAvailableVideoZoomFactor; // not on the main thread
_cameraView.MaxZoomFactor = (float)_captureDevice.MaxAvailableVideoZoomFactor; // not on the main thread
_cameraView.DeviceSwitchZoomFactor = _captureDevice.VirtualDeviceSwitchOverVideoZoomFactors?.Select(s => (float)s).ToArray() ?? []; // not on the main thread
var factor = _cameraView.RequestZoomFactor;
if (factor > 0)
{
factor = Math.Max(factor, _cameraView.MinZoomFactor);
factor = Math.Min(factor, _cameraView.MaxZoomFactor);
DeviceLock(() =>
{
_captureDevice.VideoZoomFactor = factor;
_cameraView.CurrentZoomFactor = factor;
});
}
}
}
Metadata
Metadata
Assignees
Labels
No labels