Skip to content

Commit 0cdbe04

Browse files
committed
Fix null pointer exception in MixinCircleExecutionState
1 parent 8e75b11 commit 0cdbe04

File tree

6 files changed

+19
-7
lines changed

6 files changed

+19
-7
lines changed

Common/src/main/java/gay/object/hexdebug/mixin/MixinBlockSlate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public void acceptDebugControlFlow(
5959

6060
// TODO: maybe startExecuting should return something to tell us if we can continue
6161
try {
62-
HexDebugCoreAPI.INSTANCE.startExecuting(debugEnv, env, iotas, imageIn);
62+
HexDebugCoreAPI.INSTANCE.startDebuggingIotas(debugEnv, env, iotas, imageIn);
6363
} catch (IllegalDebugSessionException ignored) {}
6464
}
6565

Common/src/main/java/gay/object/hexdebug/mixin/MixinCircleExecutionState.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,12 @@ public abstract class MixinCircleExecutionState implements IMixinCircleExecution
137137
private void hexdebug$stopDebugging(BlockEntityAbstractImpetus impetus, CallbackInfo ci) {
138138
if (debugEnv$hexdebug != null) {
139139
HexDebugCoreAPI.INSTANCE.removeDebugThread(debugEnv$hexdebug);
140-
debugEnv$hexdebug = null;
141140
}
142141
}
143142

144143
@ModifyReturnValue(method = "save", at = @At("RETURN"))
145144
private CompoundTag hexdebug$saveDebugEnvSessionId(CompoundTag out) {
146-
if (debugEnv$hexdebug != null) {
145+
if (debugEnv$hexdebug != null && debugEnv$hexdebug.isDebugging()) {
147146
out.putUUID(TAG_HEXDEBUG_SESSION_ID, debugEnv$hexdebug.getSessionId());
148147
}
149148
return out;

Common/src/main/kotlin/gay/object/hexdebug/impl/HexDebugCoreAPIImpl.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,15 @@ class HexDebugCoreAPIImpl : HexDebugCoreAPI {
2323
return DebugAdapterManager[caster]?.debugger(sessionId)?.debugEnv
2424
}
2525

26+
override fun isSessionDebugging(debugEnv: DebugEnvironment): Boolean {
27+
return DebugAdapterManager[debugEnv.caster]?.debugger(debugEnv.sessionId) != null
28+
}
29+
2630
override fun createDebugThread(debugEnv: DebugEnvironment, threadId: Int?) {
2731
getAdapterOrThrow(debugEnv).createDebugThread(debugEnv, threadId)
2832
}
2933

30-
override fun startExecuting(
34+
override fun startDebuggingIotas(
3135
debugEnv: DebugEnvironment,
3236
env: CastingEnvironment,
3337
iotas: MutableList<Iota>,

Core/src/main/java/gay/object/hexdebug/core/api/HexDebugCoreAPI.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ default DebugEnvironment getDebugEnv(@NotNull ServerPlayer caster, @NotNull UUID
3838
return null;
3939
}
4040

41+
@Contract(pure = true)
42+
default boolean isSessionDebugging(@NotNull DebugEnvironment debugEnv) {
43+
return false;
44+
}
45+
4146
/**
4247
* @throws IllegalDebugSessionException if {@code debugEnv} is currently associated with an
4348
* active debug session
@@ -54,7 +59,7 @@ default void createDebugThread(@NotNull DebugEnvironment debugEnv, @Nullable Int
5459
* @throws IllegalDebugSessionException if no debug thread is currently associated with
5560
* {@code debugEnv}, or if the debugger is already executing something
5661
*/
57-
default void startExecuting(
62+
default void startDebuggingIotas(
5863
@NotNull DebugEnvironment debugEnv,
5964
@NotNull CastingEnvironment env,
6065
@NotNull List<Iota> iotas,

Core/src/main/java/gay/object/hexdebug/core/api/debugging/DebugEnvironment.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public abstract boolean resume(
4747
* when requested by the user.
4848
* <br>
4949
* The previous debug thread is removed before this method is called, so the implementation may
50-
* use {@link HexDebugCoreAPI#createDebugThread} and {@link HexDebugCoreAPI#startExecuting}.
50+
* use {@link HexDebugCoreAPI#createDebugThread} and {@link HexDebugCoreAPI#startDebuggingIotas}.
5151
* However, note that {@link DebugEnvironment} is <strong>not</strong> called before this
5252
* method, so it's up to the implementation whether they need to call that or not.
5353
*/
@@ -95,6 +95,10 @@ public void printDebugMishap(
9595
}
9696
}
9797

98+
public boolean isDebugging() {
99+
return HexDebugCoreAPI.INSTANCE.isSessionDebugging(this);
100+
}
101+
98102
@NotNull
99103
public ServerPlayer getCaster() {
100104
return caster;

Core/src/main/java/gay/object/hexdebug/core/api/debugging/SimplePlayerBasedDebugEnv.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,6 @@ public void start(@Nullable Integer threadId)
5858
throws IllegalDebugSessionException, IllegalDebugThreadException
5959
{
6060
HexDebugCoreAPI.INSTANCE.createDebugThread(this, threadId);
61-
HexDebugCoreAPI.INSTANCE.startExecuting(this, env, iotas, null);
61+
HexDebugCoreAPI.INSTANCE.startDebuggingIotas(this, env, iotas, null);
6262
}
6363
}

0 commit comments

Comments
 (0)