Browse Source

fix NullReferenceException when closing text editor immediately after committing.

4.1
Siegfried Pammer 15 years ago
parent
commit
9eaa1c105b
  1. 31
      src/Main/Base/Project/Src/Editor/IDocumentBaseVersionProvider.cs

31
src/Main/Base/Project/Src/Editor/IDocumentBaseVersionProvider.cs

@ -67,7 +67,10 @@ namespace ICSharpCode.SharpDevelop.Editor
{ {
if (alreadyCalled) { if (alreadyCalled) {
alreadyCalled = false; alreadyCalled = false;
actions(); // thread-safety: copy delegate reference into local variable
var actions = this.actions;
if (actions != null)
actions();
} }
} }
@ -90,12 +93,14 @@ namespace ICSharpCode.SharpDevelop.Editor
public static RepoChangeWatcher AddWatch(string repositoryRoot, Action action) public static RepoChangeWatcher AddWatch(string repositoryRoot, Action action)
{ {
RepoChangeWatcher watcher; RepoChangeWatcher watcher;
if (!watchers.TryGetValue(repositoryRoot, out watcher)) { lock (watchers) {
watcher = new RepoChangeWatcher(repositoryRoot); if (!watchers.TryGetValue(repositoryRoot, out watcher)) {
watchers.Add(repositoryRoot, watcher); watcher = new RepoChangeWatcher(repositoryRoot);
watchers.Add(repositoryRoot, watcher);
}
watcher.actions += action;
} }
watcher.actions += action;
return watcher; return watcher;
} }
@ -103,12 +108,14 @@ namespace ICSharpCode.SharpDevelop.Editor
public void ReleaseWatch(Action action) public void ReleaseWatch(Action action)
{ {
actions -= action; lock (watchers) {
if (actions == null && !disposed) { actions -= action;
WorkbenchSingleton.MainWindow.Activated -= MainWindowActivated; if (actions == null && !disposed) {
watchers.Remove(watcher.Path); WorkbenchSingleton.MainWindow.Activated -= MainWindowActivated;
this.watcher.Dispose(); watchers.Remove(watcher.Path);
disposed = true; this.watcher.Dispose();
disposed = true;
}
} }
} }
} }

Loading…
Cancel
Save