Skip to content

[Screenshot] Fix NRE for UIView not being in UIWindow#29460

Merged
PureWeen merged 1 commit intodotnet:inflight/currentfrom
drasticactions:dev/timill/screenshot-ios
May 13, 2025
Merged

[Screenshot] Fix NRE for UIView not being in UIWindow#29460
PureWeen merged 1 commit intodotnet:inflight/currentfrom
drasticactions:dev/timill/screenshot-ios

Conversation

@drasticactions
Copy link
Contributor

The UIView Screenshot method uses the UIWindow as a reference for the scale it should render with, which causes the method to throw if the UIView isn't contained in a window (As you can inflate UIViews without a Window context), leading to an NRE.

Copilot AI review requested due to automatic review settings May 13, 2025 07:59
@drasticactions drasticactions requested a review from a team as a code owner May 13, 2025 07:59
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a NullReferenceException when capturing a screenshot from a UIView that is not contained in a UIWindow by providing a safe fallback for the scale factor.

  • Updated the scale assignment to safely handle null window/screen references by defaulting to 1.0f.
Comments suppressed due to low confidence (1)

src/Essentials/src/Screenshot/Screenshot.ios.cs:65

  • The null-conditional operators prevent a NullReferenceException, but defaulting to 1.0f might result in lower resolution screenshots. Verify that this fallback behavior meets the requirements for capturing accurate screenshots when view.Window is null.
Scale = view.Window?.Screen?.Scale ?? 1.0f,

@jsuarezruiz jsuarezruiz added the area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info label May 13, 2025
@rmarinho rmarinho added this to the .NET 9 SR8 milestone May 13, 2025
@rmarinho rmarinho moved this from Todo to Approved in MAUI SDK Ongoing May 13, 2025
@PureWeen PureWeen changed the base branch from main to inflight/current May 13, 2025 14:23
@PureWeen PureWeen merged commit 4d4d66d into dotnet:inflight/current May 13, 2025
127 of 129 checks passed
@github-project-automation github-project-automation bot moved this from Approved to Done in MAUI SDK Ongoing May 13, 2025
@drasticactions drasticactions deleted the dev/timill/screenshot-ios branch May 13, 2025 15:02
PureWeen added a commit that referenced this pull request May 21, 2025
For more information about inflight process check
https://github.com/dotnet/maui/wiki/Inflight-Branch-Process

# .NET MAUI Release Notes

## New Release: May 21, 2025

We're excited to announce a new release of .NET MAUI with several bug
fixes and improvements across various platforms.

### Bug Fixes

#### iOS
- **Map Control**: Fixed crash when navigating to a page containing a
map more than once (#29369)
- **CarouselView**: Fixed bounce-back behavior when Loop=false, ensuring
proper scrolling experience (#29318)
- **UIView**: Fixed NullReferenceException for UIView not being in
UIWindow (#29460)

#### Windows
- **CarouselView**: Fixed HorizontalScrollBarVisibility="Never" not
working properly (#29343)
- **UI Controls**: Fixed the color not being applied to the
Expand/Collapse Chevron icon (#29140)

#### Windows & macOS
- **Modal Navigation**: Fixed issue where Disappearing event was not
triggered when closing a window with a modal page (#29129)

#### Android
- **Modal Pages**: Improved inheritance of StatusBar and NavigationBar
background colors (#28568)
- **Footer Scrolling**: Fixed footer scrolling issues in list controls
(#29381)
- **Modal Pages**: Improved inheritance of StatusBar and NavigationBar
background colors on modal pages (#28568)

#### Cross-Platform
- **CarouselView**: Fixed ItemsLayout runtime updates to ensure proper
layout behavior (#29447)
- **CollectionView**: Fixed various issues in CollectionView
implementation (#29423)

### Testing Improvements
- Added feature matrix UITest cases for CollectionView dynamic changes
(#29424)

### Code Quality
- Fixed code formatting issues across the codebase
- Minor typo corrections (#29379)

### Contributors

This release was made possible by the hard work of our dedicated team
and community contributors. We'd like to extend our gratitude to
everyone who has contributed to this release.

### Installation

This update is available through NuGet and the .NET SDK. Update your
projects to get access to these fixes.

### Known Issues

Please refer to our issue tracker for any known issues and their
workarounds.

---

For more information about .NET MAUI, visit [the official
documentation](https://docs.microsoft.com/dotnet/maui/).
@github-actions github-actions bot locked and limited conversation to collaborators Jun 13, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants