Skip to content

[Bug]: Add-on JavaScript context not cleaned up when removing an add-on. #6041

Description

@kwvanderlinde

Describe the Bug

When an add-on is installed in a campaign, a new context is created within which the add-on's JavaScript can executed. When the add-on is removed, this context remains. Adding the same add-on again can then cause errors (e.g.,, if the same variables gets defined) or fail for logical reasons if old state is used.

To Reproduce

  1. Download this example add-on: collision-example.mtlib
  2. Drag the add-on into a blank campaign.
  3. Open File > Add On Libraries ..., select the add-on and click Remove Library.
    • Notice that typing [r: data.listNamespaces("addon:")] in the chat window results in the add-on namespace still be visible.
  4. Drag the add-on into the campaign again.
  5. Notice the error that gets presented.

The key detail in the attached add-on is that it evals this line during onInit:

const namespace = 'com.kwvanderlinde.collision';

The display of the error is not 100% consistent, so you may have to repeat steps (3) & (4) a couple times.

Expected Behaviour

When an add-on is removed, all of its state is also removed (namespace and associated context). It should be possible to add the add-on again to the same campaign without issue (unless the add-on itself is at fault for doing something very bad).

Screenshots

No response

MapTool Info

1.18.6

Desktop

Linux Mint 22.1

Additional Context

Here is the error:

Details
java.util.concurrent.CompletionException: net.rptools.parser.ParserException: com.oracle.truffle.polyglot.PolyglotEngineException error executing expression js.evalURI("com.kwvanderlinde.collision", "lib://com.kwvanderlinde.collision/example.js").
	at net.rptools.maptool.model.library.addon.AddOnLibrary.lambda$callMTSFunction$15(AddOnLibrary.java:672)
	at java.desktop/java.awt.event.InvocationEvent.dispatch(Unknown Source)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
	at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
	at java.base/java.security.AccessController.doPrivileged(Unknown Source)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.desktop/java.awt.EventQueue.dispatchEvent(Unknown Source)
	at net.rptools.maptool.client.swing.MapToolEventQueue.dispatchEvent(MapToolEventQueue.java:63)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.desktop/java.awt.WaitDispatchSupport$2.run(Unknown Source)
	at java.desktop/java.awt.WaitDispatchSupport$4.run(Unknown Source)
	at java.desktop/java.awt.WaitDispatchSupport$4.run(Unknown Source)
	at java.base/java.security.AccessController.doPrivileged(Unknown Source)
	at java.desktop/java.awt.WaitDispatchSupport.enter(Unknown Source)
	at java.desktop/java.awt.Dialog.show(Unknown Source)
	at java.desktop/javax.swing.JOptionPane.showOptionDialog(Unknown Source)
	at java.desktop/javax.swing.JOptionPane.showMessageDialog(Unknown Source)
	at java.desktop/javax.swing.JOptionPane.showMessageDialog(Unknown Source)
	at net.rptools.maptool.client.MapTool.showMessage(MapTool.java:257)
	at net.rptools.maptool.client.MapTool.showInformation(MapTool.java:380)
	at net.rptools.maptool.client.MapTool.showInformation(MapTool.java:363)
	at net.rptools.maptool.client.TransferableHelper.lambda$importData$1(TransferableHelper.java:566)
	at java.desktop/java.awt.event.InvocationEvent.dispatch(Unknown Source)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
	at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
	at java.base/java.security.AccessController.doPrivileged(Unknown Source)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.desktop/java.awt.EventQueue.dispatchEvent(Unknown Source)
	at net.rptools.maptool.client.swing.MapToolEventQueue.dispatchEvent(MapToolEventQueue.java:63)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.run(Unknown Source)
Caused by: net.rptools.parser.ParserException: com.oracle.truffle.polyglot.PolyglotEngineException error executing expression js.evalURI("com.kwvanderlinde.collision", "lib://com.kwvanderlinde.collision/example.js").
	at net.rptools.maptool.client.MapToolLineParser.parseExpression(MapToolLineParser.java:1124)
	at net.rptools.maptool.client.MapToolLineParser.parseLine(MapToolLineParser.java:857)
	at net.rptools.maptool.client.MapToolLineParser.runMacroBlock(MapToolLineParser.java:1456)
	at net.rptools.maptool.client.MapToolLineParser.runMacro(MapToolLineParser.java:1380)
	at net.rptools.maptool.client.MapToolLineParser.runMacro(MapToolLineParser.java:1177)
	at net.rptools.maptool.model.library.addon.AddOnLibrary.lambda$callMTSFunction$15(AddOnLibrary.java:670)
	... 38 more

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions