Skip to content
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

Fix corecrl.dll fault, see photino.NET/issues/87 #63

Merged
merged 1 commit into from
Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/Infrastructure/AppWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using Sqlbi.Bravo.Infrastructure.Windows.Interop;
using Sqlbi.Bravo.Models;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -117,8 +116,6 @@ ThemeType GetTheme()

private void OnWindowCreating(object? sender, EventArgs e)
{
Trace.WriteLine($"::Bravo:INF:OnWindowCreating:{ _window.Title }");

var theme = UserPreferences.Current.Theme;
if (theme != ThemeType.Auto)
{
Expand All @@ -129,7 +126,6 @@ private void OnWindowCreating(object? sender, EventArgs e)

private void OnWindowCreated(object? sender, EventArgs e)
{
Trace.WriteLine($"::Bravo:INF:OnWindowCreated:{ _window.Title } ( { string.Join(", ", _host.GetListeningAddresses().Select((a) => a.ToString())) } )");
#if !DEBUG
HandleHotKeys(register: true);
#endif
Expand Down Expand Up @@ -228,6 +224,12 @@ private void CheckForUpdate()
}
else if (updateInfo.IsUpdateAvailable)
{
// HACK: see issue https://github.com/tryphotino/photino.NET/issues/87
// Wait a bit in order to ensure that the PhotinoWindow message loop is started
// This is to prevent the .NET Runtime corecrl.dll fault with a win32 access violation
Thread.Sleep(5_000);
// HACK END <<

var updateMessage = ApplicationUpdateAvailableWebMessage.CreateFrom(updateInfo);
_window.SendWebMessage(updateMessage.AsString);

Expand All @@ -243,15 +245,17 @@ private void CheckForUpdate()
/// </summary>
public void WaitForClose()
{
// HACK: see issue https://github.com/tryphotino/photino.NET/issues/87
// Wait a bit in order to ensure that the PhotinoWindow message loop is started
// This is to prevent the .NET Runtime corecrl.dll fault with a win32 access violation
// This should be moved to the OnWindowCreated handler after the issue has been resolved
if (!_startupSettings.IsEmpty)
{
// HACK: see issue https://github.com/tryphotino/photino.NET/issues/87
// This should be moved to the OnWindowCreated handler after the issue has been resolved
_ = Task.Factory.StartNew(() =>
{
try
{
Thread.Sleep(2000);
Thread.Sleep(2_000);

var startupMessage = AppInstanceStartupMessage.CreateFrom(_startupSettings);
var webMessageString = startupMessage.ToWebMessageString();
Expand All @@ -264,6 +268,7 @@ public void WaitForClose()
}
});
}
// HACK END <<

_window.WaitForClose();
}
Expand Down
12 changes: 2 additions & 10 deletions src/Infrastructure/Windows/WindowSubclass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,11 @@
/// </summary>
internal abstract class WindowSubclass : CriticalFinalizerObject, IDisposable
{
//private static readonly int DetachUnsubclassMessage;

private readonly Comctl32.SUBCLASSPROC _subclassProc;
private readonly IntPtr _subclassId;
private readonly IntPtr _hWnd;
private object _lockSync = new();
private readonly object _lockSync = new();
private bool _subclassInstalled;
//private bool _disposed;

//static WindowSubclass()
//{
// DetachUnsubclassMessage = User32.RegisterWindowMessageW("bravo_DetachSubclass");
//}

public WindowSubclass(IntPtr hWnd)
{
Expand All @@ -40,7 +32,7 @@ private IntPtr SubclassProc(IntPtr hWnd, uint uMsg, IntPtr wParam, IntPtr lParam
}
finally
{
if (uMsg == (uint)WindowMessage.WM_NCDESTROY /* || uMsg == DetachUnsubclassMessage */)
if (uMsg == (uint)WindowMessage.WM_NCDESTROY)
{
DetachSubclass();
}
Expand Down