Skip to content

Commit

Permalink
Fix null derefernce when enumerating deleted objects (#2128)
Browse files Browse the repository at this point in the history
Co-authored-by: wixoa <[email protected]>
  • Loading branch information
amylizzle and wixoaGit authored Dec 29, 2024
1 parent 7aff19a commit f7b6d43
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions OpenDreamRuntime/Objects/DreamObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ public void Delete(bool possiblyThreaded = false) {
}

public bool IsSubtypeOf(TreeEntry ancestor) {
if(Deleted) //null deref protection, deleted objects don't have ObjectDefinition anymore
return false;
return ObjectDefinition.IsSubtypeOf(ancestor);
}

Expand Down
6 changes: 5 additions & 1 deletion OpenDreamRuntime/Procs/DreamEnumerators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ public DreamObjectEnumerator(IEnumerable<DreamObject> dreamObjects, TreeEntry? f

public bool Enumerate(DMProcState state, DreamReference? reference) {
bool success = _dreamObjectEnumerator.MoveNext();

while(success && _dreamObjectEnumerator.Current.Deleted) //skip over deleted
success = _dreamObjectEnumerator.MoveNext();

if (_filterType != null) {
while (success && !_dreamObjectEnumerator.Current.IsSubtypeOf(_filterType)) {
while (success && (_dreamObjectEnumerator.Current.Deleted || !_dreamObjectEnumerator.Current.IsSubtypeOf(_filterType))) {
success = _dreamObjectEnumerator.MoveNext();
}
}
Expand Down

0 comments on commit f7b6d43

Please sign in to comment.