Fix: guard Win2D draw callbacks so a render exception can't crash the app#30
Open
andrewtheart wants to merge 1 commit into
Open
Conversation
… app A CanvasControl draw callback that throws is re-raised by WinUI as a stowed exception (0xc000027b) that fail-fasts the process and bypasses the managed UnhandledException handler. Transient out-of-range layout/geometry (e.g. GetCharacterRegions throwing E_INVALIDARG when a rebuilt layout and a computed index momentarily disagree) could therefore hard-crash the host app. Wrap each of the four Canvas_*_Draw handlers in try/catch + Debug.WriteLine so the worst case is one skipped frame instead of a crash. CanvasDrawed() tracking stays outside the try.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
Guards the four Win2D
Canvas_*_Drawcallbacks (Canvas_Text_Draw,Canvas_Selection_Draw,Canvas_Cursor_Draw,Canvas_LineNumber_Draw) with try/catch so a transient rendering exception can't crash the host app.Why
A
CanvasControldraw callback runs inside WinUI's composition/render pipeline. If it throws, WinUI re-raises the exception as a stowed exception (0xc000027b) that fail-fasts the entire process and bypasses the managedUnhandledExceptionhandler — so the app has no way to catch or recover.In practice this can happen on very large or rapidly-changing content, where the rebuilt
CanvasTextLayoutand a computed selection/geometry index momentarily disagree and a call likeCanvasTextLayout.GetCharacterRegionsthrowsE_INVALIDARG. The result is a hard crash of the whole application from inside the control.Change
Wrap each draw handler's rendering call in try/catch and log via
Debug.WriteLine.initializationManager.CanvasDrawed(n)is intentionally left outside the try so initialization tracking still completes. The worst case becomes a single skipped frame (the canvas redraws on the next invalidation) instead of a process crash.No behavior change on the success path; no new dependencies.
Testing
TextControlBox.csproj, Release/x64).Contributing this back upstream after hitting
0xc000027bfail-fasts while using TextControlBox as a vendored editor.