Merge pull request #4547 from Abextm/fairy-ring-defer

Prevent crash when updating the fairy ring filter
This commit is contained in:
Tomas Slusny
2018-08-01 10:18:47 +02:00
committed by GitHub
14 changed files with 62 additions and 47 deletions

View File

@@ -41,9 +41,9 @@ public class ClientThread
@Inject @Inject
private Client client; private Client client;
public void invokeLater(Runnable r) public void invoke(Runnable r)
{ {
invokeLater(() -> invoke(() ->
{ {
r.run(); r.run();
return true; return true;
@@ -54,7 +54,7 @@ public class ClientThread
* Will run r on the game thread, at a unspecified point in the future. * Will run r on the game thread, at a unspecified point in the future.
* If r returns false, r will be ran again, at a later point * If r returns false, r will be ran again, at a later point
*/ */
public void invokeLater(BooleanSupplier r) public void invoke(BooleanSupplier r)
{ {
if (client.isClientThread()) if (client.isClientThread())
{ {
@@ -64,6 +64,25 @@ public class ClientThread
} }
return; return;
} }
invokeLater(r);
}
/**
* Will run r on the game thread after this method returns
* If r returns false, r will be ran again, at a later point
*/
public void invokeLater(Runnable r)
{
invokeLater(() ->
{
r.run();
return true;
});
}
public void invokeLater(BooleanSupplier r)
{
invokes.add(r); invokes.add(r);
} }
@@ -85,7 +104,7 @@ public class ClientThread
} }
catch (Throwable e) catch (Throwable e)
{ {
log.warn("Exception in invokeLater", e); log.warn("Exception in invoke", e);
} }
if (remove) if (remove)
{ {

View File

@@ -141,7 +141,7 @@ public class CommandManager
} }
resumed = true; resumed = true;
clientThread.invokeLater(() -> sendChatboxInput(chatType, typedText)); clientThread.invoke(() -> sendChatboxInput(chatType, typedText));
} }
}; };
boolean stop = false; boolean stop = false;
@@ -180,7 +180,7 @@ public class CommandManager
} }
resumed = true; resumed = true;
clientThread.invokeLater(() -> sendPrivmsg(target, message)); clientThread.invoke(() -> sendPrivmsg(target, message));
} }
}; };

View File

@@ -82,7 +82,7 @@ public class ChatboxInputManager
this.changed = changed; this.changed = changed;
this.characterLimit = characterLimit; this.characterLimit = characterLimit;
this.open = true; this.open = true;
clientThread.invokeLater(() -> client.runScript( clientThread.invoke(() -> client.runScript(
ScriptID.RUNELITE_CHATBOX_INPUT_INIT, ScriptID.RUNELITE_CHATBOX_INPUT_INIT,
text, text,
defaul defaul
@@ -99,7 +99,7 @@ public class ChatboxInputManager
return; return;
} }
this.open = false; this.open = false;
clientThread.invokeLater(() -> client.runScript( clientThread.invoke(() -> client.runScript(
ScriptID.CLOSE_CHATBOX_INPUT, ScriptID.CLOSE_CHATBOX_INPUT,
1, 1,
1 1
@@ -116,30 +116,23 @@ public class ChatboxInputManager
int stringStackSize = client.getStringStackSize(); int stringStackSize = client.getStringStackSize();
int typedKey = client.getIntStack()[--intStackSize]; int typedKey = client.getIntStack()[--intStackSize];
String str = client.getStringStack()[--stringStackSize]; String str = client.getStringStack()[--stringStackSize];
int retval = 0; boolean isDone = false;
switch (typedKey) switch (typedKey)
{ {
case 27: // Escape case 27: // Escape
str = ""; str = "";
if (changed != null)
{
changed.accept(str);
}
// fallthrough // fallthrough
case '\n': case '\n':
if (done != null)
{
done.accept(str);
}
this.open = false; this.open = false;
retval = 1; isDone = true;
break; break;
case '\b': case '\b':
if (str.length() > 0) if (str.length() > 0)
{ {
str = str.substring(0, str.length() - 1); str = str.substring(0, str.length() - 1);
} }
break;
default: default:
// If we wanted to do numbers only, we could add a limit here // If we wanted to do numbers only, we could add a limit here
if (typedKey >= 32 && (str.length() < characterLimit)) if (typedKey >= 32 && (str.length() < characterLimit))
@@ -153,8 +146,13 @@ public class ChatboxInputManager
changed.accept(str); changed.accept(str);
} }
if (isDone && done != null)
{
done.accept(str);
}
client.getStringStack()[stringStackSize++] = str; client.getStringStack()[stringStackSize++] = str;
client.getIntStack()[intStackSize++] = retval; client.getIntStack()[intStackSize++] = isDone ? 1 : 0;
client.setIntStackSize(intStackSize); client.setIntStackSize(intStackSize);
client.setStringStackSize(stringStackSize); client.setStringStackSize(stringStackSize);
} }

View File

@@ -216,7 +216,7 @@ public class ItemManager
private AsyncBufferedImage loadImage(int itemId, int quantity, boolean stackable) private AsyncBufferedImage loadImage(int itemId, int quantity, boolean stackable)
{ {
AsyncBufferedImage img = new AsyncBufferedImage(36, 32, BufferedImage.TYPE_INT_ARGB); AsyncBufferedImage img = new AsyncBufferedImage(36, 32, BufferedImage.TYPE_INT_ARGB);
clientThread.invokeLater(() -> clientThread.invoke(() ->
{ {
if (client.getGameState().ordinal() < GameState.LOGIN_SCREEN.ordinal()) if (client.getGameState().ordinal() < GameState.LOGIN_SCREEN.ordinal())
{ {

View File

@@ -87,7 +87,7 @@ public class SpriteManager
return; return;
} }
clientThread.invokeLater(() -> clientThread.invoke(() ->
{ {
BufferedImage img = getSprite(archive, file); BufferedImage img = getSprite(archive, file);
if (img == null) if (img == null)

View File

@@ -99,7 +99,7 @@ public class AttackStylesPlugin extends Plugin
if (client.getGameState() == GameState.LOGGED_IN) if (client.getGameState() == GameState.LOGGED_IN)
{ {
clientThread.invokeLater(this::start); clientThread.invoke(this::start);
} }
} }

View File

@@ -152,7 +152,7 @@ public class CannonPlugin extends Plugin
{ {
if (cannonPlaced) if (cannonPlaced)
{ {
clientThread.invokeLater(this::addCounter); clientThread.invoke(this::addCounter);
} }
} }
} }

View File

@@ -82,11 +82,11 @@ public class ChatKeyboardListener implements KeyListener
replacement = ""; replacement = "";
} }
clientThread.invokeLater(() -> client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, replacement)); clientThread.invoke(() -> client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, replacement));
} }
break; break;
case KeyEvent.VK_BACK_SPACE: case KeyEvent.VK_BACK_SPACE:
clientThread.invokeLater(() -> client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, "")); clientThread.invoke(() -> client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, ""));
break; break;
} }
} }

View File

@@ -97,7 +97,7 @@ public class DemonicGorillaPlugin extends Plugin
recentBoulders = new ArrayList<>(); recentBoulders = new ArrayList<>();
pendingAttacks = new ArrayList<>(); pendingAttacks = new ArrayList<>();
memorizedPlayers = new HashMap<>(); memorizedPlayers = new HashMap<>();
clientThread.invokeLater(this::reset); // Updates the list of gorillas and players clientThread.invoke(this::reset); // Updates the list of gorillas and players
} }
@Override @Override

View File

@@ -51,6 +51,7 @@ import net.runelite.api.events.WidgetLoaded;
import net.runelite.api.widgets.Widget; import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetID; import net.runelite.api.widgets.WidgetID;
import net.runelite.api.widgets.WidgetInfo; import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.callback.ClientThread;
import net.runelite.client.config.ConfigManager; import net.runelite.client.config.ConfigManager;
import net.runelite.client.game.ChatboxInputManager; import net.runelite.client.game.ChatboxInputManager;
import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.Plugin;
@@ -83,9 +84,11 @@ public class FairyRingPlugin extends Plugin
@Inject @Inject
private ChatboxInputManager chatboxInputManager; private ChatboxInputManager chatboxInputManager;
@Inject
private ClientThread clientThread;
private Widget searchBtn; private Widget searchBtn;
private boolean chatboxOpenLastTick = false; private boolean chatboxOpenLastTick = false;
private boolean clearFilter = false;
private Collection<CodeWidgets> codes = null; private Collection<CodeWidgets> codes = null;
@Data @Data
@@ -198,23 +201,18 @@ public class FairyRingPlugin extends Plugin
{ {
updateFilter(""); updateFilter("");
searchBtn.setAction(1, MENU_CLOSE); searchBtn.setAction(1, MENU_CLOSE);
chatboxInputManager.openInputWindow("Filter fairy rings", "", ChatboxInputManager.NO_LIMIT, this::updateFilter, s -> chatboxInputManager.openInputWindow("Filter fairy rings", "", ChatboxInputManager.NO_LIMIT,
{ s -> clientThread.invokeLater(() -> updateFilter(s)),
// We can't run it right now because scripts can't run other scripts in their callbacks s ->
clearFilter = true; {
searchBtn.setAction(1, MENU_OPEN); clientThread.invokeLater(() -> updateFilter(""));
}); searchBtn.setAction(1, MENU_OPEN);
});
} }
@Subscribe @Subscribe
public void onGameTick(GameTick t) public void onGameTick(GameTick t)
{ {
if (clearFilter)
{
updateFilter("");
clearFilter = false;
}
// This has to happen because the only widget that gets hidden is the tli one // This has to happen because the only widget that gets hidden is the tli one
Widget fairyRingTeleportButton = client.getWidget(WidgetInfo.FAIRY_RING_TELEPORT_BUTTON); Widget fairyRingTeleportButton = client.getWidget(WidgetInfo.FAIRY_RING_TELEPORT_BUTTON);
boolean fairyRingWidgetOpen = fairyRingTeleportButton != null && !fairyRingTeleportButton.isHidden(); boolean fairyRingWidgetOpen = fairyRingTeleportButton != null && !fairyRingTeleportButton.isHidden();

View File

@@ -80,7 +80,7 @@ public class InterfaceStylesPlugin extends Plugin
@Override @Override
protected void startUp() throws Exception protected void startUp() throws Exception
{ {
clientThread.invokeLater(() -> clientThread.invoke(() ->
{ {
overrideSprites(); overrideSprites();
overrideWidgetSprites(); overrideWidgetSprites();
@@ -92,7 +92,7 @@ public class InterfaceStylesPlugin extends Plugin
@Override @Override
protected void shutDown() throws Exception protected void shutDown() throws Exception
{ {
clientThread.invokeLater(() -> clientThread.invoke(() ->
{ {
restoreWidgetDimensions(); restoreWidgetDimensions();
removeGameframe(); removeGameframe();
@@ -104,7 +104,7 @@ public class InterfaceStylesPlugin extends Plugin
{ {
if (config.getGroup().equals("interfaceStyles")) if (config.getGroup().equals("interfaceStyles"))
{ {
clientThread.invokeLater(() -> clientThread.invoke(() ->
{ {
removeGameframe(); removeGameframe();
overrideSprites(); overrideSprites();

View File

@@ -188,7 +188,7 @@ public class NpcIndicatorsPlugin extends Plugin
overlayManager.add(npcMinimapOverlay); overlayManager.add(npcMinimapOverlay);
keyManager.registerKeyListener(inputListener); keyManager.registerKeyListener(inputListener);
highlights = getHighlights(); highlights = getHighlights();
clientThread.invokeLater(() -> clientThread.invoke(() ->
{ {
skipNextSpawnCheck = true; skipNextSpawnCheck = true;
rebuildAllNpcs(); rebuildAllNpcs();

View File

@@ -80,13 +80,13 @@ public class ReportButtonPlugin extends Plugin
@Override @Override
public void startUp() public void startUp()
{ {
clientThread.invokeLater(this::updateReportButtonTime); clientThread.invoke(this::updateReportButtonTime);
} }
@Override @Override
public void shutDown() public void shutDown()
{ {
clientThread.invokeLater(() -> clientThread.invoke(() ->
{ {
Widget reportButton = client.getWidget(WidgetInfo.CHATBOX_REPORT_TEXT); Widget reportButton = client.getWidget(WidgetInfo.CHATBOX_REPORT_TEXT);
if (reportButton != null) if (reportButton != null)

View File

@@ -179,7 +179,7 @@ public class SlayerPlugin extends Plugin
streak = config.streak(); streak = config.streak();
setExpeditiousChargeCount(config.expeditious()); setExpeditiousChargeCount(config.expeditious());
setSlaughterChargeCount(config.slaughter()); setSlaughterChargeCount(config.slaughter());
clientThread.invokeLater(() -> setTask(config.taskName(), config.amount())); clientThread.invoke(() -> setTask(config.taskName(), config.amount()));
} }
} }
@@ -459,7 +459,7 @@ public class SlayerPlugin extends Plugin
if (config.showInfobox()) if (config.showInfobox())
{ {
clientThread.invokeLater(this::addCounter); clientThread.invoke(this::addCounter);
} }
else else
{ {