Skip to content

Commit

Permalink
[Savestates] Trying to fix crashes and errors
Browse files Browse the repository at this point in the history
- Trying to fix errors with the future task queue during loadstate
- Trying to fix a crash with a tickList being out of sync
  • Loading branch information
ScribbleTAS committed Jul 27, 2024
1 parent c8649a1 commit 030e215
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.minecrafttas.mctcommon.events.EventListenerRegistry;
import com.minecrafttas.tasmod.TASmod;
import com.minecrafttas.tasmod.events.EventServer.EventServerTickPost;
import com.minecrafttas.tasmod.savestates.SavestateHandlerServer.SavestateState;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
Expand Down Expand Up @@ -109,12 +110,15 @@ public void redirectThreadSleep(long msToTick) {

TASmod.gameLoopSchedulerServer.runAllTasks();

synchronized (this.futureTaskQueue) {
while (!this.futureTaskQueue.isEmpty()) {
try {
((FutureTask<?>) this.futureTaskQueue.poll()).run();
} catch (Throwable var9) {
var9.printStackTrace();
boolean stopTaskQueue = TASmod.savestateHandlerServer != null && TASmod.savestateHandlerServer.state == SavestateState.LOADING;
if (!stopTaskQueue) {
synchronized (this.futureTaskQueue) {
while (!this.futureTaskQueue.isEmpty()) {
try {
((FutureTask<?>) this.futureTaskQueue.poll()).run();
} catch (Throwable var9) {
var9.printStackTrace();
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,11 @@ public void loadState(int savestateIndex, boolean tickrate0, boolean changeIndex
ChunkHandler.addPlayerToServerChunk(player);
});

WorldServer[] worlds = server.worlds;

for (WorldServer world : worlds) {
world.tick();
}
// WorldServer[] worlds = server.worlds;
//
// for (WorldServer world : worlds) {
// world.tick();
// }

if (!tickrate0) {
TASmod.tickratechanger.pauseGame(false);
Expand Down Expand Up @@ -756,7 +756,7 @@ public void onServerPacket(PacketID id, ByteBuffer buf, String username) throws

case SAVESTATE_LOAD:
int indexing = TASmodBufferBuilder.readInt(buf);
player.getServerWorld().addScheduledTask(() -> {
TASmod.gameLoopSchedulerServer.add(() -> {
try {
TASmod.savestateHandlerServer.loadState(indexing, true);
} catch (LoadstateException e) {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/minecrafttas/tasmod/util/Monitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,4 @@ public static Object accessField(Object objectToAccess, String fieldname) {
}
return out;
}

}

0 comments on commit 030e215

Please sign in to comment.