Skip to content

fix: avoid race to call some API before NSApplication is running #21175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

spouliot
Copy link
Contributor

GitHub Issue: closes #20742

PR Type:

  • 🐞 Bugfix

What is the current behavior? 🤔

There's a race where we can call some NSApplication API before NSApplicationMain. In such case the returned value is incorrect.

This replaces the workaround #21124 made for the 6.1 branch.

What is the new behavior? 🚀

The StartApp code is invoked, from native code, when NSApplication is ready.

PR Checklist ✅

Please check if your PR fulfills the following requirements:

Other information ℹ️

@Copilot Copilot AI review requested due to automatic review settings July 30, 2025 01:10
@github-actions github-actions bot added the platform/macos 🍏 Categorizes an issue or PR as relevant to the macOS platform label Jul 30, 2025
Copy link
Contributor

@Copilot 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 race condition where NSApplication APIs were being called before NSApplicationMain had fully initialized the application, which could return incorrect values. The fix ensures that the application startup code is deferred until NSApplication is ready by using a callback mechanism.

Key changes:

  • Added a new callback mechanism to defer application startup until NSApplication is ready
  • Moved resource path initialization into the deferred startup callback
  • Added proper error handling for the native callback execution

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
UNOApplication.m Implements the application start callback mechanism and triggers it when NSApplication finishes launching
UNOApplication.h Declares the application start callback function pointer type
NativeUno.cs Adds P/Invoke declaration for setting the application start callback
MacSkiaHost.cs Refactors startup flow to use the callback mechanism and adds error handling

@unodevops
Copy link
Contributor

🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-21175/docs/index.html

@unodevops
Copy link
Contributor

🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-21175/wasm-skia-net9/index.html

@unodevops
Copy link
Contributor

⚠️⚠️ The build 172313 has failed on Uno.UI - CI.

@nventive-devops
Copy link
Contributor

The build 172313 found UI Test snapshots differences: android-28-net8: 21, android-28-net8-Snap: 34, ios: 5, ios-Snap: 53, skia-linux-screenshots: 76, skia-windows-screenshots: 86, wasm: 54, wasm-automated-net9.0-WinUI-Benchmarks-automated: 0, wasm-automated-net9.0-WinUI-Default-automated: 15, wasm-automated-net9.0-WinUI-RuntimeTests-0: 0, wasm-automated-net9.0-WinUI-RuntimeTests-1: 1, wasm-automated-net9.0-WinUI-RuntimeTests-2: 0

Details
  • android-28-net8: 21 changed over 825

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • DecimalFormatterTest_UITests_Shared_Microsoft_UI_Xaml_Controls_NumberBoxTests_NumberBoxPage
    • Detereminate_ProgressRing_Validation25_[#FF0000_#008000_#FF0000_#FF0000]_Progress-Ring-Value-25
    • SelectionOnLoad_UITests_Microsoft_UI_Xaml_Controls_RadioButtonsTests_RadioButtonsInitialLoadSelected
    • SelectionTest_UITests_Microsoft_UI_Xaml_Controls_RadioButtonsTests_RadioButtonsPage
    • ProgressRing_IsEnabled_Running_UITests_Windows_UI_Xaml_Controls_ProgressRing_WindowsProgressRing_GH1220
    • SequentialAnimations_SamplesApp_Windows_UI_Xaml_Media_Animation_SequentialAnimationsPage
    • When_NoSelectionWithItemClick_Then_PointersEvents_UITests_Windows_UI_Xaml_Controls_ListView_ListView_Selection_Pointers
    • When_NoSelection_Then_PointersEvents_UITests_Windows_UI_Xaml_Controls_ListView_ListView_Selection_Pointers
    • When_Parent_PointerMoved_After_drag_on_ScrollViewer_-_touch
    • Detereminate_ProgressRing_Validation75_[#FF0000_#008000_#008000_#008000]_Progress-Ring-Value-75
    • FlyoutTest_When_NoOverlayInputPassThroughElement_Then_DontPassThrough_woOff_UITests_Shared_Windows_UI_Xaml_Controls_Flyout_Flyout_OverlayInputPassThroughElement
    • When_SingleSelectionWithoutItemClick_Then_PointersEvents_UITests_Windows_UI_Xaml_Controls_ListView_ListView_Selection_Pointers
    • When_Parent_PointerMoved_After_drag_on_non-scrolling_ScrollViewer
    • WebView_NavigateToAnchor_Initial
    • Detereminate_ProgressRing_Validation50_[#FF0000_#008000_#008000_#FF0000]_Progress-Ring-Value-50
    • ListView_SelectedItems_SamplesApp_Windows_UI_Xaml_Controls_ListView_ListViewSelectedItems
    • NavigateBackAndForthBetweenMenuItemsAndSettings_Fluent_SamplesApp_Samples_Microsoft_UI_Xaml_Controls_NavigationViewTests_FluentStyle_FluentStyle_NavigationViewSample
    • ProgressRing_Visibility_Collapsed_UITests_Windows_UI_Xaml_Controls_ProgressRing_WindowsProgressRing_GH1220
    • UpDownEnabledTest_UITests_Shared_Microsoft_UI_Xaml_Controls_NumberBoxTests_NumberBoxPage
    • UpDownTest_UITests_Shared_Microsoft_UI_Xaml_Controls_NumberBoxTests_NumberBoxPage
  • android-28-net8-Snap: 34 changed over 1074

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Border_Border_AntiAlias_UITests_Windows_UI_Xaml_Controls_BorderTests_BorderAntiAlias
    • ListView_ListViewSelectedItems_SamplesApp_Windows_UI_Xaml_Controls_ListView_ListViewSelectedItems
    • Border_AutoBorderStretchwithbottommargin_Uno_UI_Samples_UITests_BorderTestsControl_AutoBorderStretchwithbottommargin
    • Border_Simple_with_Radius_Uno_UI_Samples_UITests_BorderTestsControl_Simple_with_Radius
    • Microsoft_UI_Composition_UITests_Shared_Windows_UI_Composition_SKCanvasElement_Simple_UITests_Shared_Windows_UI_Composition_SKCanvasElement_Simple
    • Gesture_Recognizer_Pointer_Events_test_bench_UITests_Shared_Windows_UI_Input_GestureRecognizer_PointersEvents
    • Border_SimplewithNonUnifmormRadius_Uno_UI_Samples_UITests_BorderTestsControl_SimplewithNonUnifmormRadius
    • ListView_ListView_With_ListViews_Count_Measure_UITests_Shared_Windows_UI_Xaml_Controls_ListView_ListView_With_ListViews_Count_Measure
    • Border_OnepxThicknessandRadius_Uno_UI_Samples_UITests_BorderTestsControl_OnepxThicknessandRadius
    • CommandBarFlyout_MUXControlsTestApp_CommandBarFlyoutPage_MUXControlsTestApp_CommandBarFlyoutPage
    • Border_NonUniformThicknessandRadius_Uno_UI_Samples_UITests_BorderTestsControl_NonUniformThicknessandRadius
    • Border_Uno_UI_Samples_UITests_BorderTestsControl_Border_BorderThickness_Uno_UI_Samples_UITests_BorderTestsControl_Border_BorderThickness
    • Border_Border_CornerRadius_BorderThickness_UITests_Windows_UI_Xaml_Controls_BorderTests_Border_CornerRadius_BorderThickness
    • Image_UITests_Windows_UI_Xaml_Controls_ImageTests_SvgImageSource_Icons_UITests_Windows_UI_Xaml_Controls_ImageTests_SvgImageSource_Icons
    • MUX_NumberBox_UITests_Shared_Microsoft_UI_Xaml_Controls_NumberBoxTests_NumberBoxPage
    • MUX_UITests_Shared_Microsoft_UI_Xaml_Controls_TreeViewTests_TreeViewPage_UITests_Shared_Microsoft_UI_Xaml_Controls_TreeViewTests_TreeViewPage
    • Scrolling_MUXControlsTestApp_ScrollViewDynamicPage_MUXControlsTestApp_ScrollViewDynamicPage
    • Border_OnepxThicknessandRadiusAndTextBlock_Uno_UI_Samples_UITests_BorderTestsControl_OnepxThicknessandRadiusAndTextBlock
    • Border_Uniform_Thickness_and_Large_Radius_Uno_UI_Samples_UITests_BorderTestsControl_Uniform_Thickness_and_Large_Radius
    • Pickers_UITests_Windows_UI_Xaml_Controls_CalendarView_CalendarView_Theming_UITests_Windows_UI_Xaml_Controls_CalendarView_CalendarView_Theming
  • ios: 5 changed over 256

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ProgressRing_IsEnabled_Running_UITests_Windows_UI_Xaml_Controls_ProgressRing_WindowsProgressRing_GH1220
    • SequentialAnimations_SamplesApp_Windows_UI_Xaml_Media_Animation_SequentialAnimationsPage
    • Check_ListView_Swallows_Measure_UITests_Shared_Windows_UI_Xaml_Controls_ListView_ListView_With_ListViews_Count_Measure
    • TextBox_UpdatedBinding_On_OneWay_Mode_UITests_Windows_UI_Xaml_Controls_TextBox_TextBox_Bindings
    • ProgressRing_Visibility_Collapsed_UITests_Windows_UI_Xaml_Controls_ProgressRing_WindowsProgressRing_GH1220
  • ios-Snap: 53 changed over 991

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Brushes_PanelImageBrush_Uno_UI_Samples_UITests_ImageBrushTestControl_PanelImageBrush
    • Grid_Grid_DataBound_ColumnRow_Definitions_Uno_UI_Samples_Content_UITests_GridTestsControl_Grid_DataBound_ColumnRow_Definitions
    • NavigationView_FluentStyle_NavigationViewSample_SamplesApp_Samples_Microsoft_UI_Xaml_Controls_NavigationViewTests_FluentStyle_FluentStyle_NavigationViewSample
    • NavigationView_NavigationView_Tapped_UITests_Shared_Windows_UI_Xaml_Controls_NavigationViewTests_NavigationView_Tapped
    • ListView_ListView_Aligned_Left_UITests_Shared_Windows_UI_Xaml_Controls_ListView_ListView_Aligned_Left
    • SwipeControl_MUXControlsTestApp_SwipeControlPage2_MUXControlsTestApp_SwipeControlPage2
    • Icons_UITests_Shared_Windows_UI_Xaml_Controls_BitmapIconTests_BitmapIcon_Foreground_UITests_Shared_Windows_UI_Xaml_Controls_BitmapIconTests_BitmapIcon_Foreground
    • NavigationView_MUXControlsTestApp_NavigationViewMenuItemStretchPage_MUXControlsTestApp_NavigationViewMenuItemStretchPage
    • NavigationView_MUXControlsTestApp_NavigationViewMinimalPage_MUXControlsTestApp_NavigationViewMinimalPage
    • TextBox_TextBox_Disabled_State_Uno_UI_Samples_Content_UITests_TextBoxControl_TextBox_Disabled_State
    • Brushes_ImageBrushWithCompositeTransform_Uno_UI_Samples_UITests_ImageBrushTestControl_ImageBrushWithCompositeTransform
    • ColorPicker_ColorPickerSample_UITests_Microsoft_UI_Xaml_Controls_ColorPickerTests_ColorPickerSample
    • ContentControl_ContentControl_SelectorInheritance_Uno_UI_Samples_Content_UITests_ContentControlTestsControl_ContentControl_SelectorInheritance
    • Image_UITests_Shared_Windows_UI_Xaml_Controls_ImageTests_Image_Stretch_Algmnt_Inf_Vertical_UITests_Shared_Windows_UI_Xaml_Controls_ImageTests_Image_Stretch_Algmnt_Inf_Vertical
    • Image_UITests_Shared_Windows_UI_Xaml_Controls_ImageTests_Image_Stretch_Alignment_SizeOnControl_UITests_Shared_Windows_UI_Xaml_Controls_ImageTests_Image_Stretch_Alignment_SizeOnControl
    • Performance_UITests_Windows_UI_Xaml_Performance_Performance_1000ButtonsContinuousRendering_UITests_Windows_UI_Xaml_Performance_Performance_1000ButtonsContinuousRendering
    • Pickers_UITests_Windows_UI_Xaml_Controls_CalendarView_CalendarView_Theming_UITests_Windows_UI_Xaml_Controls_CalendarView_CalendarView_Theming
    • Scrolling_MUXControlsTestApp_ScrollViewDynamicPage_MUXControlsTestApp_ScrollViewDynamicPage
    • Image_Uno_UI_Samples_UITests_Image_Image_Stretch_Alignment_Smaller_Uno_UI_Samples_UITests_Image_Image_Stretch_Alignment_Smaller
    • Image_Uno_UI_Samples_UITests_Image_Image_Stretch_Alignment_Taller_Uno_UI_Samples_UITests_Image_Image_Stretch_Alignment_Taller
  • skia-linux-screenshots: 76 changed over 2282

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • CalendarView_Theming.png
    • ButtonClippingTestsControl.png-dark
    • ClipboardTests.png-dark
    • DisplayInformation.png-dark
    • ClipboardTests.png
    • ImageBrushAlignmentXY2.png-dark
    • ImageBrushAlignmentXY2.png
    • ImageBrushInList.png-dark
    • ImageBrushInList.png
    • CompositionEffectBrush.png-dark
    • CompositionEffectBrush.png
    • DropDownButtonPage.png-dark
    • Examples.png
    • ExpanderColorValidationPage.png-dark
    • ExpanderColorValidationPage.png
    • ImageWithLateSourceUniformToFill.png-dark
    • ImageWithLateSourceUniformToFill.png
    • Buttons.png
    • Gamepad_CurrentReading.png-dark
    • Gamepad_CurrentReading.png
  • skia-windows-screenshots: 86 changed over 2282

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Border_With_ScaleTransform.png
    • Border_With_TranslateTransform.png-dark
    • ClipboardTests.png-dark
    • Border_With_RotateTransform.png
    • Border_With_ScaleTransform.png-dark
    • DropDownButtonPage.png-dark
    • Border_With_CompositeTransform.png
    • Border_With_Off_Centre_RotateTransform.png-dark
    • Grid_With_RotateTransform_And_Button.png-dark
    • Grid_With_RotateTransform_And_Button.png
    • Border_With_Off_Centre_ScaleTransform.png-dark
    • Border_With_Off_Centre_ScaleTransform.png
    • DisplayInformation.png-dark
    • DisplayInformation.png
    • Examples.png-dark
    • Examples.png
    • Basics_Automated.png-dark
    • Border_With_TranslateTransform.png
    • ClipboardTests.png
    • ButtonClippingTestsControl.png-dark
  • wasm: 54 changed over 1056

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • SamplesApp.Windows_UI_Xaml_Controls.ListView.ListView_Padding_Unconstrained
    • UITests.Shared.Windows_UI_Xaml_Controls.ComboBox.ComboBox_DropDownPlacement
    • MUXControlsTestApp.ExtraCommandBarFlyoutPage
    • UITests.Microsoft_UI_Xaml_Controls.InfoBadgeTests.InfoBadgePage
    • UITests.Windows_UI_Xaml_Controls.BorderTests.BorderWithNullBrushAndNonZeroThickness
    • UITests.Windows_UI_Xaml_Controls.ImageTests.SvgImageSource_FromMsAppData
    • Uno.UI.Samples.Content.UITests.CommandBar.CommandBar_With_Long_Sentences
    • GenericApp.Views.Samples.Shared.Content.UITests.GridViewMultipleSelectionMode
    • UITests.Windows_UI_Xaml_Controls.CalendarView.CalendarView_Theming
    • UITests.Windows_UI_Xaml_Controls.ListView.ListViewItem_IsEnabled
    • UITests.Windows_UI_Xaml_Controls.ListView.ListView_DisplayMemberPath
    • UITests.Windows_UI_Xaml_Controls.ListView.ListView_DuplicateItem
    • Uno.UI.Samples.Content.UITests.ContentControlTestsControl.ContentControl_FindName
    • Uno.UI.Samples.Content.UITests.ContentControlTestsControl.ContentControl_Inheritance
    • SamplesApp.Windows_UI_Xaml_Controls.ListView.ListViewHeaderFooter_ImplicitlyBinded
    • UITests.Shared.Windows_UI_Xaml_Controls.Button.Button_Events
    • Uno.UI.Samples.Content.UITests.ButtonTestsControl.RadioButton_Multiple_Unnamed_Groups
    • Uno.UI.Samples.Content.UITests.ButtonTestsControl.RadioButton_With_GroupName
    • SamplesApp.Windows_UI_Xaml_Controls.ListView.ListView_BoundSelectedItem
    • UITests.Shared.Windows_UI_Xaml_Controls.ListView.ListView_With_ListViews_Count_Measure
  • wasm-automated-net9.0-WinUI-Benchmarks-automated: 0 changed over 1

  • wasm-automated-net9.0-WinUI-Default-automated: 15 changed over 877

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • TestProgressRing_InitialState_UITests_Microsoft_UI_Xaml_Controls_ProgressRing_WinUIProgressRing_Features
    • Default_StrokeThickness_MyPath
    • When_NoSelectionWithItemClick_Then_PointersEvents_UITests_Windows_UI_Xaml_Controls_ListView_ListView_Selection_Pointers
    • When_SingleSelectionWithoutItemClick_Then_PointersEvents_UITests_Windows_UI_Xaml_Controls_ListView_ListView_Selection_Pointers
    • Default_StrokeThickness_MyLine
    • Default_StrokeThickness_MyPolygon
    • Default_StrokeThickness_MyRect
    • SequentialAnimations_SamplesApp_Windows_UI_Xaml_Media_Animation_SequentialAnimationsPage
    • ListView_SelectedItems_SamplesApp_Windows_UI_Xaml_Controls_ListView_ListViewSelectedItems
    • When_SingleSelectionWithItemClick_Then_PointersEvents_UITests_Windows_UI_Xaml_Controls_ListView_ListView_Selection_Pointers
    • When_StretchAndAlignmentNone_ImageBrush-50-50-None-XLeft-YBottom
    • Default_StrokeThickness_MyPolyline
    • Default_StrokeThickness_MyEllipse
    • ToggleCollapsedStateToVerifyClipping_UITests_Shared_Microsoft_UI_Xaml_Controls_ExpanderTests_ExpanderColorValidationPage
    • When_Theme_Changed_No_Crash_UITests_Windows_UI_Xaml_Controls_CalendarView_CalendarView_Theming
  • wasm-automated-net9.0-WinUI-RuntimeTests-0: 0 changed over 1

  • wasm-automated-net9.0-WinUI-RuntimeTests-1: 1 changed over 1

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • RunRuntimeTests_SamplesApp_Samples_UnitTests_UnitTestsPage
  • wasm-automated-net9.0-WinUI-RuntimeTests-2: 0 changed over 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform/macos 🍏 Categorizes an issue or PR as relevant to the macOS platform
Projects
None yet
Development

Successfully merging this pull request may close these issues.

macOS crash on startup due to missing font file
3 participants