Skip to content

Commit

Permalink
Add thread information to crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
2No2Name committed Feb 19, 2025
1 parent fe7cd9c commit 9eb5814
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/main/java/no2/worldthreader/common/ServerWorldTicking.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package no2.worldthreader.common;

import net.minecraft.CrashReport;
import net.minecraft.CrashReportCategory;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.profiling.Profiler;
Expand Down Expand Up @@ -87,11 +88,17 @@ public static void tickThreaded(MinecraftServer server, WorldThreadingManager wo
}
}

private static void delegateCrash(Throwable throwable, String title, ServerLevel serverWorld, WorldThreadingManager worldThreadingManager) {
private static void delegateCrash(Throwable throwable, String title, ServerLevel serverLevel, WorldThreadingManager worldThreadingManager) {
String serverLevelOwner = ((ThreadOwnedObject) serverLevel).worldthreader$getOwningThread().getName();
String chunkCacheOwner = ((ThreadOwnedObject) serverLevel.getChunkSource()).worldthreader$getOwningThread().getName();
worldThreadingManager.tryGiveAwayExclusiveWorldAccess(); //If the exception was thrown while this thread held exclusive access, it must be returned.

CrashReport crashReport = CrashReport.forThrowable(throwable, title);
serverWorld.fillReportDetails(crashReport);
serverLevel.fillReportDetails(crashReport);
CrashReportCategory worldthreaderCrashInfo = crashReport.addCategory("WorldThreader");
worldthreaderCrashInfo.setDetail("Crashing thread", Thread.currentThread().getName());
worldthreaderCrashInfo.setDetail("Level owner", serverLevelOwner);
worldthreaderCrashInfo.setDetail("ChunkCache owner", chunkCacheOwner);
worldThreadingManager.handleCrash(crashReport);
}

Expand Down

0 comments on commit 9eb5814

Please sign in to comment.