Skip to content

Commit 40e3145

Browse files
committed
Fix interactive script running flag always being set to true. Update unit test.
1 parent d662501 commit 40e3145

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

CHANGES

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
[1.7.1]
2+
- Fix interactive script running flag always being set to true. Update unit test.
3+
14
[1.7.0]
25
- Prevent game future execution by checking for script skipping in constructor
36
- Allow scripts to be marked as player interactive to restrict one interactive script running at a time

core/src/main/java/org/mini2Dx/miniscript/core/util/ScriptInvocationQueue.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ private ScriptInvocation pollInteractiveScript() {
4747
interactiveScriptLock.lockWrite();
4848
if(!interactiveScriptRunning.get()) {
4949
result = interactiveScriptQueue.poll();
50-
interactiveScriptRunning.set(true);
50+
if(result != null) {
51+
interactiveScriptRunning.set(true);
52+
}
5153
}
5254
interactiveScriptLock.unlockWrite();
5355
return result;
@@ -82,4 +84,8 @@ public void clearInteractiveScriptStatus() {
8284
interactiveScriptRunning.set(false);
8385
interactiveScriptLock.unlockWrite();
8486
}
87+
88+
public boolean isInteractiveScriptRunnung() {
89+
return interactiveScriptRunning.get();
90+
}
8591
}

core/src/test/java/org/mini2Dx/miniscript/core/util/ScriptInvocationQueueTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public void testOnlyOneInteractiveScriptPolled() {
2525
invocationQueue.offer(createInvocation(i % 10 == 0 ? INTERACTIVE_SCRIPT_ID : i, i % 10 == 0));
2626
}
2727

28-
2928
final CountDownLatch countDownLatch = new CountDownLatch(threads.length);
3029

3130
for(int i = 0; i < threads.length; i++) {
@@ -57,6 +56,12 @@ public void testOnlyOneInteractiveScriptPolled() {
5756
while(!invocationQueue.isEmpty()) {
5857
Assert.assertTrue(interactiveScriptsRunning.get() <= 1);
5958
}
59+
for(int i = 0; i < threads.length; i++) {
60+
try {
61+
threads[i].join();
62+
} catch (InterruptedException e) {}
63+
}
64+
Assert.assertFalse(invocationQueue.isInteractiveScriptRunnung());
6065
}
6166

6267
private ScriptInvocation createInvocation(int scriptId, boolean interactive) {

0 commit comments

Comments
 (0)