Repository: microsoft/terminal
File: src/cascadia/WindowsTerminal/IslandWindow.cpp (C++)

Code before:
        // |____/ \____/|_____/ \_____|  |_|
        //
        // There's a bug in Windows 10 where closing a DesktopWindowXamlSource
        // on any thread will free an internal static resource that's used by
        // XAML for the entire process. This would result in closing window
        // essentially causing the entire app to crash.
        //
        // To avoid this, leak the XAML island. We only need to leak this on
        // Windows 10, since the bug is fixed in Windows 11.
        //
        // See GH #15384, MSFT:32109540
        auto a{ _source };
        winrt::detach_abi(_source);

        // </BODGY>
    }

    // GH#15454: Unset the user data for the window. This will prevent future
    // callbacks that come onto our window message loop from being sent to the
    // IslandWindow (or other derived class's) implementation.
    //
    // Specifically, this prevents a pending coroutine from being able to call
    // something like ShowWindow, and have that come back on the IslandWindow
    // message loop, where it'll end up asking XAML something that XAML is no
    // longer able to answer.
    SetWindowLongPtr(_window.get(), GWLP_USERDATA, (LONG_PTR)nullptr);

    if (_source)
    {
        _source.Close();
        _source = nullptr;
    }
}

HWND IslandWindow::GetInteropHandle() const
{
    return _interopWindowHandle;
}

// Method Description:
// - Create the actual window that we'll use for the application.
// Arguments:
// - <none>
// Return Value:
// - <none>
void IslandWindow::MakeWindow() noexcept
{
    WNDCLASS wc{};
    wc.hCursor = LoadCursor(nullptr, IDC_ARROW);
    wc.hInstance = reinterpret_cast<HINSTANCE>(&__ImageBase);
    wc.lpszClassName = XAML_HOSTING_WINDOW_CLASS_NAME;

Review comment (bug):
I am not in love with the C-style cast, nor would audit mode be - does `reinterpret_cast<LONG_PTR>(nullptr)` work?

Code after:
        // |____/ \____/|_____/ \_____|  |_|
        //
        // There's a bug in Windows 10 where closing a DesktopWindowXamlSource
        // on any thread will free an internal static resource that's used by
        // XAML for the entire process. This would result in closing window
        // essentially causing the entire app to crash.
        //
        // To avoid this, leak the XAML island. We only need to leak this on
        // Windows 10, since the bug is fixed in Windows 11.
        //
        // See GH #15384, MSFT:32109540
        auto a{ _source };
        winrt::detach_abi(_source);

        // </BODGY>
    }

    // GH#15454: Unset the user data for the window. This will prevent future
    // callbacks that come onto our window message loop from being sent to the
    // IslandWindow (or other derived class's) implementation.
    //
    // Specifically, this prevents a pending coroutine from being able to call
    // something like ShowWindow, and have that come back on the IslandWindow
    // message loop, where it'll end up asking XAML something that XAML is no
    // longer able to answer.
    SetWindowLongPtr(_window.get(), GWLP_USERDATA, 0);

    if (_source)
    {
        _source.Close();
        _source = nullptr;
    }
}

HWND IslandWindow::GetInteropHandle() const
{
    return _interopWindowHandle;
}

// Method Description:
// - Create the actual window that we'll use for the application.
// Arguments:
// - <none>
// Return Value:
// - <none>
void IslandWindow::MakeWindow() noexcept
{
    WNDCLASS wc{};
    wc.hCursor = LoadCursor(nullptr, IDC_ARROW);
    wc.hInstance = reinterpret_cast<HINSTANCE>(&__ImageBase);
    wc.lpszClassName = XAML_HOSTING_WINDOW_CLASS_NAME;