Skip to content

Commit db1fc56

Browse files
committed
Fix debug session still being started when circle fails on startup
1 parent 2d3dcba commit db1fc56

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,16 @@ public MixinBlockEntityAbstractImpetus(BlockEntityType<?> pType, BlockPos pWorld
4747
public InteractionResult startDebugging(@NotNull ServerPlayer caster, int threadId) {
4848
if (executionState != null) return InteractionResult.PASS;
4949

50+
startExecution(caster);
51+
if (executionState == null) return InteractionResult.FAIL;
52+
5053
var debugEnv = new CircleDebugEnv(caster, getBlockPos());
5154
try {
5255
HexDebugCoreAPI.INSTANCE.createDebugThread(debugEnv, threadId);
5356
} catch (DebugException ignored) {
5457
return InteractionResult.PASS;
5558
}
5659

57-
startExecution(caster);
5860
((IMixinCircleExecutionState) executionState).setDebugEnv$hexdebug(debugEnv);
5961

6062
return InteractionResult.CONSUME;

Common/src/main/kotlin/gay/object/hexdebug/adapter/DebugAdapter.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,11 @@ class DebugAdapter(val player: ServerPlayer) : IDebugProtocolServer {
113113
closeEvaluator(threadId)
114114
}
115115

116+
fun getFreeThreadId(): Int? = (0 until maxThreads).firstOrNull { !isDebugging(it) }
117+
116118
private fun resolveThreadId(threadId: Int?): Int {
117119
if (threadId == null) {
118-
return (0 until maxThreads).firstOrNull { !isDebugging(it) }
120+
return getFreeThreadId()
119121
?: throw IllegalDebugThreadException("All debug threads are already in use")
120122
}
121123

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ class HexDebugCoreAPIImpl : HexDebugCoreAPI {
2727
return DebugAdapterManager[casterId]?.debugger(threadId)?.debugEnv
2828
}
2929

30+
override fun getFreeDebugThreadId(casterId: UUID): Int? {
31+
return DebugAdapterManager[casterId]?.getFreeThreadId()
32+
}
33+
3034
override fun createDebugThread(debugEnv: DebugEnvironment, threadId: Int?) {
3135
getAdapterOrThrow(debugEnv).createDebugThread(debugEnv, threadId)
3236
}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ default DebugEnvironment getDebugEnv(@NotNull UUID casterId, int threadId) {
4444
return null;
4545
}
4646

47+
/**
48+
* Returns an arbitrary debug thread ID that is not currently in use by the given player, or
49+
* {@code null} if no threads are currently available.
50+
*/
51+
@Contract(pure = true)
52+
@Nullable
53+
default Integer getFreeDebugThreadId(@NotNull UUID casterId) {
54+
return null;
55+
}
56+
4757
/**
4858
* @throws IllegalDebugSessionException if {@code debugEnv} is currently associated with an
4959
* active debug session
@@ -101,6 +111,16 @@ default DebugEnvironment getDebugEnv(@NotNull ServerPlayer caster, int threadId)
101111
return getDebugEnv(caster.getUUID(), threadId);
102112
}
103113

114+
/**
115+
* Returns an arbitrary debug thread ID that is not currently in use by the given player, or
116+
* {@code null} if no threads are available.
117+
*/
118+
@Contract(pure = true)
119+
@Nullable
120+
default Integer getFreeDebugThreadId(@NotNull ServerPlayer caster) {
121+
return getFreeDebugThreadId(caster.getUUID());
122+
}
123+
104124
@Contract(pure = true)
105125
default boolean isSessionDebugging(@NotNull DebugEnvironment debugEnv) {
106126
return getDebugEnv(debugEnv.getCaster(), debugEnv.getSessionId()) != null;

0 commit comments

Comments
 (0)