ClientShutdownWatchdog .java

com.mojang.blaze3d.platform.ClientShutdownWatchdog (class): members: CRASH_REPORT_PRELOAD_LOAD, startShutdownWatchdog, SHUTDOWN_STARTED_ID, THREAD_COUNTER.

com.mojang.blaze3d.platformclass54 linesclient1.9 KB

API Surface (1)

void startShutdownWatchdog(final String callsite, final boolean forceShutdown, final @Nullable Minecraft minecraft, final GameConfig gameConfig, final long mainThreadId)

Fields & Constants (4)

CRASH_REPORT_PRELOAD_LOAD
THREAD_COUNTER
SHUTDOWN_STARTED_ID
gameConfig

String literals (3)

"Client shutdown from "
"Client watchdog shutdown details"
"Client shutdown watchdog #"

Code Graph: Dependencies (6)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

ClientShutdownWatchdog.java54 lines · Minecraft 26.3 · verbatim
1
package com.mojang.blaze3d.platform;
2
3
import java.time.Duration;
4
import java.util.concurrent.atomic.AtomicInteger;
5
import net.fabricmc.api.EnvType;
6
import net.fabricmc.api.Environment;
7
import net.minecraft.CrashReport;
8
import net.minecraft.CrashReportCategory;
9
import net.minecraft.client.Minecraft;
10
import net.minecraft.client.main.GameConfig;
11
import net.minecraft.server.dedicated.ServerWatchdog;
12
import net.minecraft.util.NativeModuleLister;
13
import org.jspecify.annotations.Nullable;
14
15
@Environment(EnvType.CLIENT)
16
public class ClientShutdownWatchdog {
17
	private static final Duration CRASH_REPORT_PRELOAD_LOAD = Duration.ofSeconds(15L);
18
	private static final AtomicInteger THREAD_COUNTER = new AtomicInteger();
19
	private static final int SHUTDOWN_STARTED_ID = Integer.MIN_VALUE;
20
21
	public static void startShutdownWatchdog(
22
		final String callsite, final boolean forceShutdown, final @Nullable Minecraft minecraft, final GameConfig gameConfig, final long mainThreadId
23
	) {
24
		int id = THREAD_COUNTER.incrementAndGet();
25
		if (id >= 0) {
26
			Thread thread = new Thread(() -> {
27
				try {
28
					Thread.sleep(CRASH_REPORT_PRELOAD_LOAD);
29
				} catch (InterruptedException e) {
30
					return;
31
				}
32
33
				if (THREAD_COUNTER.compareAndSet(id, Integer.MIN_VALUE)) {
34
					CrashReport report = ServerWatchdog.createWatchdogCrashReport("Client shutdown from " + callsite, mainThreadId);
35
					CrashReportCategory details = report.addCategory("Client watchdog shutdown details");
36
					NativeModuleLister.addCrashSection(details);
37
					if (minecraft != null) {
38
						minecraft.fillReport(report);
39
					} else {
40
						Minecraft.fillReport(null, null, gameConfig.game.launchVersion, null, report);
41
					}
42
43
					Minecraft.saveReport(gameConfig.location.gameDirectory, report);
44
					if (forceShutdown) {
45
						System.exit(-8);
46
					}
47
				}
48
			}, "Client shutdown watchdog #" + id);
49
			thread.setDaemon(true);
50
			thread.start();
51
		}
52
	}
53
}
54

Decompiled Minecraft 26.3 source of ClientShutdownWatchdog (com/mojang/blaze3d/platform/ClientShutdownWatchdog.java) with Mojang official mappings, stored verbatim on the site.