Skip to content

Commit

Permalink
Prevent a crash when changing OE data categories during a search.
Browse files Browse the repository at this point in the history
This clears up issue #50
  • Loading branch information
apocalyptech committed Aug 11, 2023
1 parent 4a50c90 commit 0b8684c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ OpenBLCMM Changelog
Explorer search history.
- Fixed a crash which could occur when navigating Object Explorer bookmarks.
- Fixed a crash when triggering a search while no datapack is loaded.
- Fixed a crash when updating the OE Data category selections while an OE
search is running.
- Fixed a bug where Object Explorer data category selection wasn't applying
properly on app startup.
- Dialogs should be closeable with the OS "window close" button when possible.
Expand Down
30 changes: 27 additions & 3 deletions src/blcmm/gui/panels/ObjectExplorerPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -1573,14 +1574,37 @@ private abstract class Worker extends SwingWorker {
boolean stop = false;
protected final DataManager dm;
final String query;

private final Set<Options.OESearch> activeCategories;
private final TreeSet<UEClass> availableClasses;

/**
* A new Worker, using the specified DataManager and with the given
* query.
*
* Note that we're making a *copy* of our active category/class state,
* from Options and DataManager respectively, because it's possible to
* edit settings mid-search. If that happens and we're using the "live"
* variables, we'll get a concurrency exception. Really it's only
* the class list that we really need to worry about, but if we don't
* also cache the active categories, our active-categories-during-search
* report (shown when there are no results) could be wrong.
*
* @param dm A DataManager to use
* @param query The query to run
*/
public Worker(DataManager dm, String query) {
this.dm = dm;
this.query = query;
this.activeCategories = new HashSet<>(Options.INSTANCE.getOESearchCategories());
this.availableClasses = (TreeSet<UEClass>)this.dm.getAllClassesByEnabledCategory().clone();
}

protected TreeSet<UEClass> getAvailableClasses() {
return this.dm.getAllClassesByEnabledCategory();
return this.availableClasses;
}

protected Set<Options.OESearch> getActiveCategories() {
return this.activeCategories;
}

public abstract void loop(BufferedReader br, TreeMap<String, Boolean> matches) throws IOException;
Expand Down Expand Up @@ -1701,7 +1725,7 @@ protected Object doInBackground() throws Exception {
sb.append("\n");
sb.append("Active search categories:\n");
sb.append("\n");
Set<Options.OESearch> activeCats = Options.INSTANCE.getOESearchCategories();
Set<Options.OESearch> activeCats = this.getActiveCategories();
for (Options.OESearch searchType : Options.OESearch.values()) {
sb.append("\t");
sb.append(activeCats.contains(searchType) ? "YES" : " NO");
Expand Down

0 comments on commit 0b8684c

Please sign in to comment.