adding defensive check to ensure device context is valid before D2D operations #15620
+21
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Adding defensive check to ensure device context is valid before D2D operations, this fix protects the RNW layer but does not fix crashes inside RNSVG - that library needs to add its own null checks before calling D2D APIs like SetTextAntialiasMode.
Type of Change
Why
Prevents crashes from failed BeginDraw: If the drawing surface cannot be acquired, the code now gracefully handles this instead of passing an invalid pointer
Consistent null-safety pattern: External libraries using GetRenderTarget() receive nullptr when the device context is unavailable, allowing them to safely skip drawing
Defense in depth: While the ultimate fix should be in RNSVG itself, these changes provide protection at the React Native Windows boundary
Resolves [https://microsoft.visualstudio.com/OS/_workitems/edit/60739119/?view=edit]
What
Changes made in Autodraw.h and UriImageMangaer.cpp
Screenshots
Testing
Tested palyground-composition.sln
Changelog
Should this change be included in the release notes: yes
adding defensive check to ensure device context is valid before D2D operations