Skip to content

Commit d8647b8

Browse files
author
ike709
committed
async proc state handling and world/New() fix
1 parent 068189c commit d8647b8

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

Content.Tests/DMProject/Tests/Builtins/caller.dm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
D.foo()
1313

1414
/proc/RunTest()
15-
ASSERT(caller.name == "New")
15+
// RunTest()'s caller is null due to how unit tests are invoked
1616
ihateithere()

OpenDreamRuntime/DreamThread.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,8 @@ public DreamValue Resume() {
238238
return ReentrantResume(null, out _);
239239
}
240240

241-
public ProcState PeekStack(int index = 0) {
241+
public ProcState? PeekStack(int index = 0) {
242+
if (_stack.Count == 0) return null;
242243
return index == 0 ? _stack.Peek() : _stack.ElementAt(index);
243244
}
244245

OpenDreamRuntime/Objects/Types/DreamObjectCallee.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
namespace OpenDreamRuntime.Objects.Types;
55

66
public sealed class DreamObjectCallee : DreamObject {
7-
public DMProcState? ProcState;
7+
public ProcState? ProcState;
88
public long ProcStateId; // Used to ensure the proc state hasn't been reused for another proc
99
private DreamObjectCallee? _caller; // Caching caller prevents issues with returning incorrect info when the proc ends or calls another proc
1010

@@ -19,7 +19,7 @@ protected override bool TryGetVar(string varName, out DreamValue value) {
1919

2020
switch (varName) {
2121
case "proc":
22-
value = new(ProcState.Proc);
22+
value = ProcState.Proc != null ? new(ProcState.Proc) : DreamValue.Null;
2323
return true;
2424
case "args":
2525
value = new(new ProcArgsList(ObjectTree.List.ObjectDefinition, ProcState));
@@ -29,19 +29,23 @@ protected override bool TryGetVar(string varName, out DreamValue value) {
2929
value = new DreamValue(_caller);
3030
return true;
3131
case "name":
32-
value = new(ProcState.Proc.VerbName);
32+
value = ProcState.Proc?.VerbName != null ? new(ProcState.Proc.VerbName) : DreamValue.Null;
3333
return true;
3434
case "desc":
35-
value = ProcState.Proc.VerbDesc != null ? new(ProcState.Proc.VerbDesc) : DreamValue.Null;
35+
value = ProcState.Proc?.VerbDesc != null ? new(ProcState.Proc.VerbDesc) : DreamValue.Null;
3636
return true;
3737
case "category":
38-
value = ProcState.Proc.VerbCategory != null ? new(ProcState.Proc.VerbCategory) : DreamValue.Null;
38+
value = ProcState.Proc?.VerbCategory != null ? new(ProcState.Proc.VerbCategory) : DreamValue.Null;
3939
return true;
4040
case "file":
41-
value = new(ProcState.Proc.GetSourceAtOffset(0).Source);
41+
value = ProcState.Proc is DMProc procFile
42+
? new DreamValue(procFile.GetSourceAtOffset(0).Source)
43+
: DreamValue.Null;
4244
return true;
4345
case "line":
44-
value = new(ProcState.Proc.GetSourceAtOffset(0).Line);
46+
value = ProcState.Proc is DMProc procLine
47+
? new DreamValue(procLine.GetSourceAtOffset(0).Line)
48+
: DreamValue.Null;
4549
return true;
4650
case "src":
4751
value = new(ProcState.Instance);

0 commit comments

Comments
 (0)