Fix bug: op_vopen should replace cursor slot, not add new one

This commit is contained in:
Jussi Saurio
2025-05-27 10:36:07 +03:00
parent b72b99c973
commit 360b1fcdae
2 changed files with 5 additions and 3 deletions

View File

@@ -998,7 +998,9 @@ pub fn op_vopen(
state
.cursors
.borrow_mut()
.insert(*cursor_id, Some(Cursor::Virtual(cursor)));
.get_mut(*cursor_id)
.unwrap_or_else(|| panic!("cursor id {} out of bounds", *cursor_id))
.replace(Cursor::Virtual(cursor));
state.pc += 1;
Ok(InsnFunctionStepResult::Step)
}

View File

@@ -349,9 +349,9 @@ impl ProgramState {
let cursors = self.cursors.borrow_mut();
std::cell::RefMut::map(cursors, |c| {
c.get_mut(cursor_id)
.expect("cursor id out of bounds")
.unwrap_or_else(|| panic!("cursor id {} out of bounds", cursor_id))
.as_mut()
.expect("cursor not allocated")
.unwrap_or_else(|| panic!("cursor id {} is None", cursor_id))
})
}
}