Skip to content

Commit

Permalink
fix: synchronize questStepPanelList (#1866)
Browse files Browse the repository at this point in the history
* fix: synchronize questStepPanelList

Since we create/add to it from AWT thread but have to iterate & access its stuff from client thread, this seems like a
reasonable solution

* fix: clear questStepPanelList before adding panels from a new quest

Before this, we kept adding and adding more panels, making the iteration over steps slower and slower

* Make use of CopyOnWriteArray instead

This is automatically safe for iterations (which Collections.synchronizedList is not)
	and it makes more sense for our use case given the rarity of our writes
  • Loading branch information
pajlada authored Nov 24, 2024
1 parent 4866a55 commit 6b32632
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main/java/com/questhelper/panel/QuestOverviewPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.awt.event.ItemEvent;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
Expand Down Expand Up @@ -94,7 +95,7 @@ public class QuestOverviewPanel extends JPanel

private final JButton collapseBtn = new JButton();

private final List<QuestStepPanel> questStepPanelList = new ArrayList<>();
private final List<QuestStepPanel> questStepPanelList = new CopyOnWriteArrayList<>();

public QuestOverviewPanel(QuestHelperPlugin questHelperPlugin, QuestManager questManager)
{
Expand Down Expand Up @@ -254,6 +255,7 @@ private JPanel makeDropdownPanel(JComboBox dropdown, String name)
public void addQuest(QuestHelper quest, boolean isActive)
{
currentQuest = quest;
questStepPanelList.clear();

List<PanelDetails> steps = quest.getPanels();
QuestStep currentStep;
Expand Down

0 comments on commit 6b32632

Please sign in to comment.