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

Fix for lights not updating after token move #3981

Merged

Conversation

kwvanderlinde
Copy link
Collaborator

@kwvanderlinde kwvanderlinde commented Apr 19, 2023

Identify the Bug or Feature request

Fixes #3979

Description of the Change

In PR #3952, I modifed the ZoneView.flush() to run on the Swing thread via SwingUtilites.invokeLater(). This kept the ZoneView consistent with itself, but other components assumed they could update the ZoneRenderer immediately after the call to flush() was done. By delaying the call using invokeLater(), the ZoneRenderer would sometime update prior to the ZoneView flush being run, causing old state to be rendered until another update.

This PR goes a step further towards guaranteeing that ZoneView.flush() is only called on the Swing thread. ClientMessageHandler and ServerMessageHandler have been updated to run their message handlers on the Swing thread if they are responsible for updating the model or the ZoneRenderer. This removes the common cases of the ZoneView being accessed off-thread. With that, we no longer use SwingUtilities.invokeLater() inside of the ZoneView.flush() methods.

There might still be other places where off-thread access could happen (e.g., app actions run on a background thread). but a complete solution to threading is beyond this PR.

Possible Drawbacks

Other timing assumptions might be violated somewhere.

Documentation Notes

N/A

Release Notes

N/A


This change is Reviewable

kwvanderlinde and others added 3 commits April 19, 2023 11:56
Most of `ServerMessageHandler`'s messages are able to interact with the model - or even the zone renderer directly -
which means they should be run on the Swing thread to avoid thread safety issues. As an added perk, now that these
handlers are serialied, we can avoid the need for the explicit mutex that was used to guard access to a portion of the
model.

`ClientMessageHandler` has also been updated to run more of its methods on the Swing thread. Most of the messages were
already handled this way, but there was a few that ought to run on the Swing thread but weren't.
Now that `ServerMessageHandler` and `ClientMessageHandler` are more careful about running on the Swing thread, they do
not cause off-thread flushes of the `ZoneView`. There are still a few places where off-thread acesss is possible (e.g.,
an app action that runs on a background thread) but these are far more rare and less likely to cause issues. Also
solving them all would be quite involved.
@kwvanderlinde
Copy link
Collaborator Author

I reran the checks. Maven decided to work this time.

@cwisniew
Copy link
Member

I reran the checks. Maven decided to work this time.

The maven repo had a DNS issue which was causing havoc (not just for us, not just for GitHub either) and that's why it was failing.

@cwisniew cwisniew merged commit aa6334c into RPTools:release-1.13 Apr 20, 2023
@kwvanderlinde kwvanderlinde deleted the bugfix/3979-stale-light-rendering branch April 20, 2023 04:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Merged
Development

Successfully merging this pull request may close these issues.

2 participants