microsoft / terminal

The new Windows Terminal and the original Windows console host, all in the same place!
MIT License
95.27k stars 8.27k forks source link

Divide by zero error with Meslo font #16579

Closed ocalvo closed 8 months ago

ocalvo commented 8 months ago

Windows Terminal version

1.18.2311

Windows build number

10.0.23531.0

Other Software

Meslo fonts: oh-my-posh install "Meslo" --user

Steps to reproduce

Start TErminal configure to use Meslo font

Expected Behavior

No crash

Actual Behavior

image

Microsoft.Terminal.Control.dll!Microsoft::Console::Render::DxEngine::GetViewportInCharacters(const Microsoft::Console::Types::Viewport & viewInPixels) Line 2026    C++
>   Microsoft.Terminal.Control.dll!winrt::Microsoft::Terminal::Control::implementation::ControlCore::Initialize(const float actualWidth, const float actualHeight, const float compositionScale) Line 358   C++
    Microsoft.Terminal.Control.dll!winrt::impl::produce<winrt::Microsoft::Terminal::Control::implementation::ControlCore,winrt::Microsoft::Terminal::Control::IControlCore>::Initialize(float actualWidth, float actualHeight, float compositionScale, bool * result) Line 2244 C++
    Microsoft.Terminal.Control.dll!winrt::impl::consume_Microsoft_Terminal_Control_IControlCore<winrt::Microsoft::Terminal::Control::IControlCore>::Initialize(float actualWidth, float actualHeight, float compositionScale) Line 91   C++
    Microsoft.Terminal.Control.dll!winrt::Microsoft::Terminal::Control::implementation::TermControl::_InitializeTerminal(const winrt::Microsoft::Terminal::Control::implementation::TermControl::InitializeReason reason) Line 957  C++
    [Inline Frame] Microsoft.Terminal.Control.dll!winrt::Microsoft::Terminal::Control::implementation::TermControl::{ctor}::__l2::<lambda_1>::operator()(winrt::Windows::Foundation::IInspectable) Line 116 C++
    Microsoft.Terminal.Control.dll!winrt::impl::delegate<winrt::Windows::Foundation::EventHandler<winrt::Windows::Foundation::IInspectable>,`winrt::Microsoft::Terminal::Control::implementation::TermControl::TermControl'::`2'::<lambda_1>>::Invoke(void * sender, void * args) Line 883  C++
    Windows.UI.Xaml.dll!DirectUI::CEventSourceBase<DirectUI::IUntypedEventSource,Windows::Foundation::IEventHandler<IInspectable *>,IInspectable,IInspectable>::Raise(IInspectable * pSource, IInspectable * pArgs) Line 275    C++
    Windows.UI.Xaml.dll!DirectUI::CEventSourceBase<DirectUI::IUntypedEventSource,Windows::Foundation::IEventHandler<IInspectable *>,IInspectable,IInspectable>::UntypedRaise(IInspectable * pSource, IInspectable * pArgs) Line 248 C++
    Windows.UI.Xaml.dll!DirectUI::FrameworkElement::RaiseLayoutUpdated(IInspectable * pSender, IInspectable * pArgs) Line 975   C++
    Windows.UI.Xaml.dll!DirectUI::DXamlCore::OnLayoutUpdated(IInspectable * pArgs) Line 2216    C++
    Windows.UI.Xaml.dll!DirectUI::DXamlCore::RaiseEvent(CDependencyObject * target, CEventArgs * pCoreArgs, DirectUI::ManagedEvent eventId) Line 2112   C++
    Windows.UI.Xaml.dll!CLayoutManager::UpdateLayout(unsigned int controlWidth, unsigned int controlHeight) Line 396    C++
    Windows.UI.Xaml.dll!CCoreServices::NWDrawTree(HWWalk * pHWWalk, CWindowRenderTarget * pRenderTarget, VisualTree * pVisualTree, unsigned int forceRedraw, XRECT_WH * prcDirtyRect) Line 6346 C++
    Windows.UI.Xaml.dll!CCoreServices::NWDrawMainTree(CWindowRenderTarget * pIRenderTarget, bool fForceRedraw, XRECT_WH * prcDirtyRect) Line 6136   C++
    Windows.UI.Xaml.dll!CWindowRenderTarget::Draw(CCoreServices * fForceRedraw, unsigned int prcDirtyRect, XRECT_WH *) Line 136 C++
    Windows.UI.Xaml.dll!CXcpBrowserHost::OnTick() Line 545  C++
    Windows.UI.Xaml.dll!CXcpDispatcher::Tick() Line 1478    C++
    Windows.UI.Xaml.dll!CXcpDispatcher::OnReentrancyProtectedWindowMessage(HWND__ * msg, unsigned int lParam, unsigned __int64) Line 1077   C++
    Windows.UI.Xaml.dll!CXcpDispatcher::ProcessMessage(HWND__ * msg, unsigned int wParam, unsigned __int64 lParam, __int64 plRet, __int64 * pbDoDefault, unsigned int *) Line 895   C++
    Windows.UI.Xaml.dll!CXcpDispatcher::WindowProc(HWND__ * hwnd, unsigned int msg, unsigned __int64 wParam, __int64 lParam) Line 841   C++
    Windows.UI.Xaml.dll!CDeferredInvoke::DispatchQueuedMessage(bool * dispatchedWork, bool * hasMoreWork) Line 298  C++
    [Inline Frame] Windows.UI.Xaml.dll!CXcpDispatcher::MessageTimerCallback() Line 1563 C++
    Windows.UI.Xaml.dll!CXcpDispatcher::MessageTimerCallbackStatic(void * myUserData) Line 1555 C++
    [Inline Frame] CoreMessaging.dll!Microsoft::CoreUI::Dispatch::TimeoutHandler::ImportAdapter$::__l2::<lambda_654db17c35df07198786f0867aa10de6>::operator()() Line 22 C++
    CoreMessaging.dll!CFlat::SehSafe::Execute<<lambda_654db17c35df07198786f0867aa10de6>>(void * hostData, Microsoft::CoreUI::Dispatch::TimeoutHandler::ImportAdapter$::__l2::<lambda_654db17c35df07198786f0867aa10de6> && body) Line 11 C++
    CoreMessaging.dll!Microsoft::CoreUI::Dispatch::TimeoutHandler::ImportAdapter$(CFlat::Box$1<CFlat::FunctionPointerAndUserData$1<long (__cdecl*)(void *)>> * func$) Line 24   C++
    [Inline Frame] CoreMessaging.dll!CFlat::DelegateImpl<Microsoft::CoreUI::Dispatch::TimeoutHandler,0,void __cdecl(void),long __cdecl(void *),0>::Invoke() Line 337    C++
    [Inline Frame] CoreMessaging.dll!Microsoft::CoreUI::Dispatch::Timeout::CallHandler() Line 23    C++
    CoreMessaging.dll!Microsoft::CoreUI::Dispatch::TimeoutManager::Callback_OnDispatch() Line 188   C++
    [Inline Frame] CoreMessaging.dll!Microsoft::CoreUI::Dispatch::Dispatcher::Callback_DispatchNextItem(Microsoft::CoreUI::Dispatch::DispatchItem * parentLoopContinuationItem) Line 899    C++
    [Inline Frame] CoreMessaging.dll!Microsoft::CoreUI::Dispatch::Dispatcher::Callback_DispatchLoop(Microsoft::CoreUI::Dispatch::RunnablePriorityMask) Line 458 C++
    CoreMessaging.dll!Microsoft::CoreUI::Dispatch::EventLoop::Callback_RunCoreLoop(Microsoft::CoreUI::Dispatch::RunMode mode) Line 419  C++
    [Inline Frame] CoreMessaging.dll!Microsoft::CoreUI::Dispatch::UserAdapter::DrainCoreMessagingQueue(Microsoft::CoreUI::Dispatch::UserAdapter$UserPriority) Line 544  C++
    CoreMessaging.dll!Microsoft::CoreUI::Dispatch::UserAdapter::OnUserDispatch(bool handlingCompletion, Microsoft::CoreUI::Dispatch::UserAdapter$UserPriority priority, CFlat::Ref<System::IntPtr> sessionExportAdapter) Line 782   C++
    [Inline Frame] CoreMessaging.dll!Microsoft::CoreUI::Dispatch::UserAdapter::OnUserDispatchRaw(Microsoft::CoreUI::Dispatch::UserAdapter$UserPriority) Line 717    C++
    CoreMessaging.dll!Microsoft::CoreUI::Dispatch::UserAdapter::DoWork(HWND__ * priority, Microsoft::CoreUI::Dispatch::UserAdapter$UserPriority handlingCompletion, bool) Line 369  C++
    CoreMessaging.dll!Microsoft::CoreUI::Dispatch::UserAdapter::WindowProc(HWND__ * hwnd, unsigned int message, unsigned __int64 wParam, __int64 lParam) Line 209   C++
    user32.dll!UserCallWinProcCheckWow(_ACTIVATION_CONTEXT * pActCtx, __int64(*)(tagWND *, unsigned int, unsigned __int64, __int64) pfn, HWND__ * hwnd, _WM_VALUE msg, unsigned __int64 wParam, __int64 lParam, void * fEnableLiteHooks, int) Line 282  C++
    user32.dll!DispatchClientMessage(tagWND * pwnd, unsigned int message, unsigned __int64 wParam, __int64 lParam, unsigned __int64 pfn) Line 3159  C++
    user32.dll!__fnDWORD(_FNDWORDMSG * pmsg) Line 1214  C++
    ntdll.dll!KiUserCallbackDispatch() Line 607 Unknown
    win32u.dll!ZwUserGetMessage() Line 189  Unknown
    user32.dll!GetMessageW(tagMSG * pmsg, HWND__ * hwnd, unsigned int wMsgFilterMin, unsigned int wMsgFilterMax) Line 537   C++
    WindowsTerminal.exe!WindowThread::_messagePump() Line 199   C++
    [Inline Frame] WindowsTerminal.exe!WindowThread::RunMessagePump() Line 44   C++
    WindowsTerminal.exe!WindowEmperor::_createNewWindowThread::__l2::<lambda_1>::operator()() Line 234  C++
    [Inline Frame] WindowsTerminal.exe!std::invoke(WindowEmperor::_createNewWindowThread::__l2::<lambda_1> &&) Line 1752    C++
    WindowsTerminal.exe!std::thread::_Invoke<std::tuple<`WindowEmperor::_createNewWindowThread'::`2'::<lambda_1>>,0>(void * _RawVals) Line 56   C++
    ucrtbase.dll!thread_start<unsigned int (__cdecl*)(void *),1>(void * const parameter) Line 97    C++
    kernel32.dll!BaseThreadInitThunk(unsigned long RunProcessInit, long(*)(void *) StartAddress, void * Argument) Line 75   C
    ntdll.dll!RtlUserThreadStart(long(*)(void *) StartAddress, void * Argument) Line 1166   C
ocalvo commented 8 months ago

Something is corrupted, I see that "this" is null in the stack frame before the crash: image

lhecker commented 8 months ago

On one hand we should probably debug this, but on the other hand we're trying to make AtlasEngine the default text renderer in the near term. As such, I think the best question would be:

Does this issue happen if you enable "AtlasEngine" in the "Rendering" settings?

If that doesn't fix it, I'd be somewhat stumped on how this crash occurred. In order for GetViewportInCharacters to be called the _renderEngine member must have been assigned, which would certainly crash if this was a nullptr. A concurrent deletion of this may be possible, but I'd hope for that to be unlikely, as WinUI should not use raw pointers internally (they do though, which worries me). So maybe, hopefully, this is just a red herring, and the issue is something more trivial like... Edit: Ah maybe since it's a Release build the this pointer register simply wasn't preserved.

When you install the font for yourself only (i.e. in %LOCALAPPDATA%\Microsoft\Windows\Fonts), then it will fail to work for a packaged app like Windows Terminal and maybe this results in a 0 sized "glyph cell". (It's necessary to install fonts for all users to not hit these issues.) The DWrite font cache may also be corrupted, but that's hopefully also unlikely.

ocalvo commented 8 months ago

On one hand we should probably debug this, but on the other hand we're trying to make AtlasEngine the default text renderer in the near term. As such, I think the best question would be:

Does this issue happen if you enable "AtlasEngine" in the "Rendering" settings?

Yes, this only happens in Windows Terminal Preview.

ocalvo commented 8 months ago

The issue started with Terminal defaulting to load "Consolas" as it failed to load "Meslo" (I also observed that the "dir" command also failed to render.) After that I started to see crashes. When to the Settings|Apps|'Terminal Preview' and selected "Repair" option and issue went away :(

DHowett commented 8 months ago

For what it's worth... if you had the "AtlasEngine" enabled, this call stack frame would not be possible:

Microsoft.Terminal.Control.dll!Microsoft::Console::Render::DxEngine::GetViewportInCharacters

carlos-zamora commented 8 months ago

Closing since it was fixed using "Repair".

ocalvo commented 7 months ago

The issue came back: image

I dont wnat to repair again. I will upload the terminal storage files from my use account here.

lhecker commented 7 months ago

Did you try to installing Meslo for all users yet (i.e. into C:\Windows\Fonts)? I'm asking just to make sure it's not some weird variation of our known DirectWrite issue (#3257).