Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Fixed null reference errors (#1916)
Browse files Browse the repository at this point in the history
Added null checks
  • Loading branch information
pictos committed Oct 2, 2022
1 parent f3a4251 commit 299fac6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,13 @@ public void StartRecord()
captureSession.AddOutput(videoOutput);

var audioDevice = AVCaptureDevice.GetDefaultDevice(AVMediaTypes.Audio);
var audioInput = AVCaptureDeviceInput.FromDevice(audioDevice);
if (audioDevice != null)
{
var audioInput = AVCaptureDeviceInput.FromDevice(audioDevice);

if (captureSession.CanAddInput(audioInput))
captureSession.AddInput(audioInput);
if (audioInput != null && captureSession.CanAddInput(audioInput))
captureSession.AddInput(audioInput);
}

captureSession.CommitConfiguration();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ protected virtual void UpdateSource()
}
else
{
if (Element.Source is XCT.FileMediaSource fileSource)
if (Element.Source is XCT.FileMediaSource fileSource && fileSource.File != null)
asset = AVAsset.FromUrl(NSUrl.FromFilename(fileSource.File));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.ComponentModel;
using CoreGraphics;
using Intents;
using UIKit;
using Xamarin.CommunityToolkit.Helpers;
using Xamarin.CommunityToolkit.PlatformConfiguration.iOSSpecific;
Expand Down Expand Up @@ -180,6 +181,9 @@ void SetSize()

void SetLayout()
{
if (PresentationController == null || PopoverPresentationController == null)
return;

((UIPopoverPresentationController)PresentationController).SourceRect = new CGRect(0, 0, PreferredContentSize.Width, PreferredContentSize.Height);

_ = Element ?? throw new InvalidOperationException($"{nameof(Element)} cannot be null");
Expand All @@ -199,6 +203,7 @@ void SetLayout()
_ => 0f
};


PopoverPresentationController.SourceRect = new CGRect(originX, originY, 0, 0);
PopoverPresentationController.PermittedArrowDirections = 0;
}
Expand Down Expand Up @@ -241,6 +246,10 @@ void SetView()

void SetPresentationController()
{

if (PresentationController == null)
return;

var popOverDelegate = new PopoverDelegate();
popOverDelegate.PopoverDismissed += HandlePopoverDelegateDismissed;

Expand Down Expand Up @@ -284,8 +293,7 @@ protected override void Dispose(bool disposing)
Element.PropertyChanged -= OnElementPropertyChanged;
Element = null;

var presentationController = (UIPopoverPresentationController)PresentationController;
if (presentationController != null)
if (PresentationController is UIPopoverPresentationController presentationController)
presentationController.Delegate = null;
}
}
Expand Down

0 comments on commit 299fac6

Please sign in to comment.