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

Commit 299fac6

Browse files
authored
Fixed null reference errors (#1916)
Added null checks
1 parent f3a4251 commit 299fac6

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

src/CommunityToolkit/Xamarin.CommunityToolkit/Views/CameraView/iOS/FormsCameraView.ios.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,10 +264,13 @@ public void StartRecord()
264264
captureSession.AddOutput(videoOutput);
265265

266266
var audioDevice = AVCaptureDevice.GetDefaultDevice(AVMediaTypes.Audio);
267-
var audioInput = AVCaptureDeviceInput.FromDevice(audioDevice);
267+
if (audioDevice != null)
268+
{
269+
var audioInput = AVCaptureDeviceInput.FromDevice(audioDevice);
268270

269-
if (captureSession.CanAddInput(audioInput))
270-
captureSession.AddInput(audioInput);
271+
if (audioInput != null && captureSession.CanAddInput(audioInput))
272+
captureSession.AddInput(audioInput);
273+
}
271274

272275
captureSession.CommitConfiguration();
273276

src/CommunityToolkit/Xamarin.CommunityToolkit/Views/MediaElement/iOS/MediaElementRenderer.ios.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ protected virtual void UpdateSource()
8585
}
8686
else
8787
{
88-
if (Element.Source is XCT.FileMediaSource fileSource)
88+
if (Element.Source is XCT.FileMediaSource fileSource && fileSource.File != null)
8989
asset = AVAsset.FromUrl(NSUrl.FromFilename(fileSource.File));
9090
}
9191

src/CommunityToolkit/Xamarin.CommunityToolkit/Views/Popup/iOS/PopupRenderer.ios.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.ComponentModel;
33
using CoreGraphics;
4+
using Intents;
45
using UIKit;
56
using Xamarin.CommunityToolkit.Helpers;
67
using Xamarin.CommunityToolkit.PlatformConfiguration.iOSSpecific;
@@ -180,6 +181,9 @@ void SetSize()
180181

181182
void SetLayout()
182183
{
184+
if (PresentationController == null || PopoverPresentationController == null)
185+
return;
186+
183187
((UIPopoverPresentationController)PresentationController).SourceRect = new CGRect(0, 0, PreferredContentSize.Width, PreferredContentSize.Height);
184188

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

206+
202207
PopoverPresentationController.SourceRect = new CGRect(originX, originY, 0, 0);
203208
PopoverPresentationController.PermittedArrowDirections = 0;
204209
}
@@ -241,6 +246,10 @@ void SetView()
241246

242247
void SetPresentationController()
243248
{
249+
250+
if (PresentationController == null)
251+
return;
252+
244253
var popOverDelegate = new PopoverDelegate();
245254
popOverDelegate.PopoverDismissed += HandlePopoverDelegateDismissed;
246255

@@ -284,8 +293,7 @@ protected override void Dispose(bool disposing)
284293
Element.PropertyChanged -= OnElementPropertyChanged;
285294
Element = null;
286295

287-
var presentationController = (UIPopoverPresentationController)PresentationController;
288-
if (presentationController != null)
296+
if (PresentationController is UIPopoverPresentationController presentationController)
289297
presentationController.Delegate = null;
290298
}
291299
}

0 commit comments

Comments
 (0)