Fixed deadlock caused by errors displayed by texture loading

This commit is contained in:
ZZYZX 2019-12-28 21:37:05 +02:00
parent 78fe6c306e
commit bd811aac7d
2 changed files with 88 additions and 69 deletions

View file

@ -106,11 +106,9 @@ namespace CodeImp.DoomBuilder
public static void Write(DebugMessageType type, string text) { Write(type, text, true); } public static void Write(DebugMessageType type, string text) { Write(type, text, true); }
public static void Write(DebugMessageType type, string text, bool append) public static void Write(DebugMessageType type, string text, bool append)
{ {
if(me != null && me.InvokeRequired) if (General.MainWindow == null)
{ return;
me.Invoke(new Action<DebugMessageType, string, bool>(Write), new object[] { type, text, append }); General.MainWindow.RunOnUIThread(() =>
}
else
{ {
if (messages.Count + 1 > MAX_MESSAGES) lock (messages) { messages.RemoveAt(0); } if (messages.Count + 1 > MAX_MESSAGES) lock (messages) { messages.RemoveAt(0); }
messages.Add(new KeyValuePair<DebugMessageType, string>(type, text)); messages.Add(new KeyValuePair<DebugMessageType, string>(type, text));
@ -118,20 +116,18 @@ namespace CodeImp.DoomBuilder
{ {
me.AddMessage(type, text, true, append); me.AddMessage(type, text, true, append);
} }
} });
} }
public static void Clear() public static void Clear()
{ {
if(me != null && me.InvokeRequired) if (General.MainWindow == null)
{ return;
me.Invoke(new Action(Clear)); General.MainWindow.RunOnUIThread(() =>
}
else
{ {
if (me != null) me.console.Clear(); if (me != null) me.console.Clear();
messages.Clear(); messages.Clear();
} });
} }
public static void StartTimer() public static void StartTimer()

View file

@ -282,6 +282,11 @@ namespace CodeImp.DoomBuilder.Windows
//mxd. Hints //mxd. Hints
hintsPanel = new HintsPanel(); hintsPanel = new HintsPanel();
hintsDocker = new Docker("hints", "Help", hintsPanel); hintsDocker = new Docker("hints", "Help", hintsPanel);
// [ZZ]
InvokeTimer.Tick += new EventHandler(InvokeHandler);
InvokeTimer.Interval = 10;
InvokeTimer.Start();
} }
#endregion #endregion
@ -4112,12 +4117,37 @@ namespace CodeImp.DoomBuilder.Windows
#region ================== Threadsafe updates #region ================== Threadsafe updates
Timer InvokeTimer = new Timer();
List<System.Action> InvokeActions = new List<System.Action>();
// this is actually InvokeTimer.Tick handler
void InvokeHandler(object sender, EventArgs e)
{
InvokeTimer.Stop();
List<System.Action> actions = null;
lock (InvokeActions)
{
if (InvokeActions.Count > 0)
{
actions = new List<System.Action>();
actions.AddRange(InvokeActions);
}
}
if (actions == null)
return;
foreach (System.Action action in actions)
action();
InvokeTimer.Start();
}
public void RunOnUIThread(System.Action action) public void RunOnUIThread(System.Action action)
{ {
if (InvokeRequired) if (!InvokeRequired) action();
Invoke(action); else lock (InvokeActions) InvokeActions.Add(action);
else
action();
} }
public void UpdateStatus() public void UpdateStatus()
@ -4198,13 +4228,8 @@ namespace CodeImp.DoomBuilder.Windows
private delegate void SetWarningsCountCallback(int count, bool blink); private delegate void SetWarningsCountCallback(int count, bool blink);
internal void SetWarningsCount(int count, bool blink) internal void SetWarningsCount(int count, bool blink)
{ {
if(this.InvokeRequired) RunOnUIThread(() =>
{ {
SetWarningsCountCallback d = SetWarningsCount;
this.Invoke(d, new object[] { count, blink });
return;
}
// Update icon, start annoying blinking if necessary // Update icon, start annoying blinking if necessary
if (count > 0) if (count > 0)
{ {
@ -4220,6 +4245,7 @@ namespace CodeImp.DoomBuilder.Windows
// Update errors count // Update errors count
warnsLabel.Text = count.ToString(); warnsLabel.Text = count.ToString();
});
} }
//mxd. Bliks warnings indicator //mxd. Bliks warnings indicator
@ -4240,7 +4266,10 @@ namespace CodeImp.DoomBuilder.Windows
if(!blinkTimer.Enabled) return; if(!blinkTimer.Enabled) return;
try try
{ {
this.Invoke(new CallBlink(Blink)); RunOnUIThread(() =>
{
Blink();
});
} catch(ObjectDisposedException) { } //la-la-la. We don't care. } catch(ObjectDisposedException) { } //la-la-la. We don't care.
} }
@ -4467,13 +4496,7 @@ namespace CodeImp.DoomBuilder.Windows
private delegate void UpdateAvailableCallback(int remoterev, string changelog); private delegate void UpdateAvailableCallback(int remoterev, string changelog);
internal void UpdateAvailable(int remoterev, string changelog) internal void UpdateAvailable(int remoterev, string changelog)
{ {
if(this.InvokeRequired) RunOnUIThread(() => {
{
UpdateAvailableCallback d = UpdateAvailable;
this.Invoke(d, new object[] { remoterev, changelog });
}
else
{
// Show the window // Show the window
UpdateForm form = new UpdateForm(remoterev, changelog); UpdateForm form = new UpdateForm(remoterev, changelog);
form.FormClosing += delegate form.FormClosing += delegate
@ -4482,7 +4505,7 @@ namespace CodeImp.DoomBuilder.Windows
General.Settings.IgnoredRemoteRevision = (form.IgnoreThisUpdate ? remoterev : 0); General.Settings.IgnoredRemoteRevision = (form.IgnoreThisUpdate ? remoterev : 0);
}; };
form.Show(this); form.Show(this);
} });
} }
#endregion #endregion