felixse / FluentTerminal

A Terminal Emulator based on UWP and web technologies.
GNU General Public License v3.0
9.21k stars 443 forks source link

Crash when opening the settings... #957

Closed BruceGeng2012 closed 2 years ago

BruceGeng2012 commented 3 years ago

Hi there,

When I try to open settings, still crash. Don't know why, can u plz help. 1st time to use the app. Love it...

OS Name: Microsoft Windows 10 Professional OS Version: 10.0.19042 N/A Build 19042 System Type: x64-based PC Total Physical Memory: 16,351 MB Processor(s): 1 Processor(s) Installed. [01]: Intel64 Family 6 Model 42 Stepping 7 GenuineIntel ~3301 Mhz

Thanks

beyond-danube commented 2 years ago

Hi @BruceGeng2012, I did face the same issue, it's related to obtaining system installed fonts for settings. Crash occurs in Microsoft.Graphics.Canvas.Text which is a part of Microsoft's Win2D library (https://github.com/microsoft/Win2D) that is used for obtaining list of fonts.

Preconditions on what is causing this exactly are unknown.

Here is external exception message:

Exception thrown at 0x00007FF99E52770E (DWrite.dll) in FluentTerminal.App.exe: 0xC0000005: Access violation reading location 0x00000214BCC01FE8.

I did not find alternative to obtain fonts, unfortunately. Seems there was System.Drawing.Text in 4.8 Framework, while it's missing in .NET core - which is obvious since it's platform dependent.

Note: this is unrelated to #874

beyond-danube commented 2 years ago

OK, so issue is more unpleasant then it looks at first glance.

Long story short: there is no easy workaround.

Background, I have 2 laptops. 100% reproducible on one, and not reproducible on another. Exception happens in DWrite.dll, which is written in C++, an external unmanaged library from CLR perspective. Exception is an Access Violation, so it cannot be catched or processed as a generic unhandled exception from UWP app and .NET above 4.0.

Exceptions happens on getting Fonts installed in system, so it would be OK just not to show fonts to a user in that case, but it's impossible due to case above. Logged issue Win2D, however I don't think it's going to be fixed any time soon https://github.com/microsoft/Win2D/issues/863

References on MSDN: HandleProcessCorruptedStateExceptionsAttribute legacyCorruptedStateExceptionsPolicy

I tried to move service to FluentTerminal.App.Services.Implementation which is in .NET Standard 2.0, did not help obviously since method call happens from UWP anyway, it fails just in another place.

Other way to keep same functionality would be to use System.Drawing.Common with good old GDI+ to get installed fonts and LOGFONT Structure hook to detect if font is monospaced or not. This will not work for similar reason, no platform-dependent libraries will work with UWP.

I have made a PR with using CanvasTextFormat.GetSystemFontFamilies() instead of CanvasFontSet.GetSystemFontSet(), works OK. It drops monospace highlighting feature, which is a reasonable trade-off I believe for not having crash on opening settings.

hanskokx commented 2 years ago

Wait, YOU made Wookie Weather? Respect.

beyond-danube commented 2 years ago

Thanks! It's a spin-off of Tom Scott's original idea that went down years ago, extended with art. He's credited and aware of Wookiee Weather :)

hanskokx commented 2 years ago

Oh, yeah. I'm aware.

beyond-danube commented 2 years ago

I spent another 20 min on this case, and discovered the root cause as close as possible. Ah it reminded me times when I just started to work as QA Engineer in CAD software company, and was looking for tricky cases all day long, was much fun :)

So steps to reproduce are in https://github.com/microsoft/Win2D/issues/863, it's impossible to handle this from outside of Win2D (i.e. from Fluent Terminal) without ugly hooks like comparing checking %APPDATA%/Local/Microsoft/Windows/Fonts folder for files, and call one or another method depending in result.

Miss time when companies size of Microsoft were a little bit more careful about shipping public libraries.