1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-11-05 09:36:19 +00:00

Fix monitors being warped after a resize

Oh, this was a really nasty bug to reproduce. I'm not sure why - it's
very simple - I guess I've only just seen screenshots of it, and never
sat down to try myself. Reminder to actually report your bugs folks!

In this case:

 1. Place down three down three monitors and then a computer.
 2. Display something on the monitor (monitor left paint a) is my go-to.
 3. Break the middle monitor.

We'd expect the left most monitor to be cleared, however it actually
preserves the monitor contents, resizing (and skewing it) to fit on its
new size!

This is because we clear the server monitor, but never sync that over to
the client, so the client monitor retains the old contents. To fix that,
instead of nulling out the server monitor, we null out the underlying
Terminal. This causes the change to be synced, fixing the bug.
This commit is contained in:
Jonathan Coates 2023-10-03 18:20:44 +01:00
parent 4541decd40
commit ab785a0906
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
2 changed files with 14 additions and 6 deletions

View File

@ -349,13 +349,15 @@ public class MonitorBlockEntity extends BlockEntity {
// Either delete the current monitor or sync a new one.
if (needsTerminal) {
if (serverMonitor == null) serverMonitor = new ServerMonitor(advanced, this);
} else {
serverMonitor = null;
}
// Update the terminal's width and height and rebuild it. This ensures the monitor
// is consistent when syncing it to other monitors.
if (serverMonitor != null) serverMonitor.rebuild();
// Update the terminal's width and height and rebuild it. This ensures the monitor
// is consistent when syncing it to other monitors.
serverMonitor.rebuild();
} else {
// Remove the terminal from the serverMonitor, but keep it around - this ensures that we sync
// the (now blank) monitor to the client.
if (serverMonitor != null) serverMonitor.reset();
}
// Update the other monitors, setting coordinates, dimensions and the server terminal
var pos = getBlockPos();

View File

@ -55,6 +55,12 @@ public class ServerMonitor {
}
}
synchronized void reset() {
if (terminal == null) return;
terminal = null;
markChanged();
}
private void markChanged() {
if (!changed.getAndSet(true)) TickScheduler.schedule(origin.tickToken);
}