Skip to content

Commit

Permalink
Merge pull request #193 from bstadick/bugfix-null-view-exception
Browse files Browse the repository at this point in the history
Bugfix null view exception
  • Loading branch information
Redth authored Sep 12, 2024
2 parents ea0f293 + 43d71e1 commit e753ee4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
18 changes: 12 additions & 6 deletions ZXing.Net.MAUI/CameraBarcodeReaderViewHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,23 @@ protected override async void ConnectHandler(NativePlatformCameraPreviewView nat
{
base.ConnectHandler(nativeView);

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

cameraManager.FrameReady += CameraManager_FrameReady;
cameraManager.FrameReady += CameraManager_FrameReady;
}
}

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 All @@ -70,7 +76,7 @@ private void CameraManager_FrameReady(object sender, CameraFrameBufferEventArgs
{
VirtualView?.FrameReady(e);

if (VirtualView.IsDetecting)
if (VirtualView?.IsDetecting ?? false)
{
var barcodes = BarcodeReader.Decode(e.Data);

Expand Down
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 e753ee4

Please sign in to comment.