Skip to content

Commit

Permalink
Merge pull request #63 from albertospelta/fix-crash
Browse files Browse the repository at this point in the history
Fix corecrl.dll fault, see photino.NET/issues/87
  • Loading branch information
albertospelta authored Jan 31, 2022
2 parents 874bfc0 + a125e08 commit 3b45b5b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
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

0 comments on commit 3b45b5b

Please sign in to comment.