Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Campaign sometimes unloaded immediately after loading. #4542

Open
kwvanderlinde opened this issue Dec 8, 2023 · 2 comments
Open

[Bug]: Campaign sometimes unloaded immediately after loading. #4542

kwvanderlinde opened this issue Dec 8, 2023 · 2 comments
Assignees
Labels

Comments

@kwvanderlinde
Copy link
Collaborator

Describe the Bug

Sometimes when I open a campaign, it opens and shows a map for a moment before disappearing and being replaced with a blank campaign. No errors are shown or logged.

To Reproduce

  1. Find a nice campaign in your file explorer.
  2. Open the campaign from your file explorer.
  3. If you're unlucky, see the campaign disappear after a moment.

Expected Behaviour

The selected campaign should remain open until I replace it.

Screenshots

No response

MapTool Info

1.14.1

Desktop

Linux Mint 21.2

Additional Context

Not all campaigns have this issue, but I don't know yet what makes the difference. Here is a test campaign of mine that consistently shows the problem for me: 4354-graaljs.cmpgn.renamed-to.zip In this campaign there is an error that comes up, but it seems to be a symptom of the campaign be unloaded rather than a problem in its own right.

I remember hitting this issue a week or so ago when opening a campaign from within MapTool instead of from the file explorer. But I tried to reproduce it now and couldn't, so I'm not sure anymore if I'm right about that.

@kwvanderlinde
Copy link
Collaborator Author

Okay, so the lib:token missing error that I get with the attached campaign is the reason that campaign is consistently dropped. It stops being consistent at 15ebc6c, I assume due to some differences in error handling (haven't actually looked at it). But the issue exists regardless, that errors is a result of the underlying problem, it's not the cause.

This seems be the rough startup sequence causing the problem:

  1. MapTool process starts.
  2. EDT queue ->
    1. New default campaign is created and set as current.
    2. New personal server is started.
    3. Client is connected to the personal server. Implicitly generates a SetCampaignMsg and sends to the client.
      • Client handles this message async on another thread, then queus and EDT action for the actual logic.
    4. EDT queue ->
      1. Load the requested campaign.
      2. Push SetCampaignMsg to the server.
        • Client does not receive as we exclude the sending client for SetCampaignMsg.
      3. Synchronously set requested campaign locally on the client.

Since (2.iv) runs on the EDT thread, if we get there before the client message handler queues its EDT action for the first SetCampaignMsg, then the default campaign will end up overwriting the requested campaign.

We can make this problem consistent by simulating a delay in the client message handling thread, e.g.:

diff --git a/src/main/java/net/rptools/maptool/client/ClientMessageHandler.java b/src/main/java/net/rptools/maptool/client/ClientMessageHandler.java
index a87961324..26bc98232 100644
--- a/src/main/java/net/rptools/maptool/client/ClientMessageHandler.java
+++ b/src/main/java/net/rptools/maptool/client/ClientMessageHandler.java
@@ -630,6 +630,10 @@ private void handle(SetCampaignNameMsg msg) {
   }
 
   private void handle(SetCampaignMsg msg) {
+    try {
+      Thread.sleep(1000);
+    } catch (Exception e) {
+    }
     EventQueue.invokeLater(
         () -> {
           Campaign campaign = Campaign.fromDto(msg.getCampaign());

Increase the delay if loading a larger campaign that itself takes a while to load.

@bubblobill
Copy link
Collaborator

bubblobill commented Dec 8, 2023

You missed a step, the default campaign is actually created twice. Not sure if it is relevant.
In MapTool -> initialize()
677 setClientFrame(new MapToolFrame(menuBar));
has createBasicCampaign buried in it and comes before this
685 Campaign cmpgn = CampaignFactory.createBasicCampaign();

It's been bugging me for months but I haven't got around to fixing it yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Merged
Development

No branches or pull requests

2 participants