Skip to content

Commit

Permalink
Handle camera manager null in CameraViewHandler.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
bstadick authored Jul 25, 2024
1 parent 747818c commit 43d71e1
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions ZXing.Net.MAUI/CameraViewHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,27 @@ protected override NativePlatformCameraPreviewView CreatePlatformView()
protected override async void ConnectHandler(NativePlatformCameraPreviewView nativeView)
{
base.ConnectHandler(nativeView);

if (await cameraManager.CheckPermissions())
cameraManager.Connect();

cameraManager.FrameReady += CameraManager_FrameReady;

if (cameraManager != null)
{
if (await cameraManager.CheckPermissions())
cameraManager.Connect();

cameraManager.FrameReady += CameraManager_FrameReady;
}
}

void CameraManager_FrameReady(object sender, CameraFrameBufferEventArgs e)
=> VirtualView?.FrameReady(e);

protected override void DisconnectHandler(NativePlatformCameraPreviewView nativeView)
{
cameraManager.FrameReady -= CameraManager_FrameReady;
if (cameraManager != null)
{
cameraManager.FrameReady -= CameraManager_FrameReady;

cameraManager.Disconnect();
cameraManager.Disconnect();
}

base.DisconnectHandler(nativeView);
}
Expand Down

0 comments on commit 43d71e1

Please sign in to comment.