Skip to content

Commit

Permalink
handled child ref creation bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mkatychev committed Sep 7, 2024
1 parent d8991f7 commit 0963a4a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rex-sm"
version = "0.6.0"
version = "0.6.1"
edition = "2021"
description = "Hierarchical state machine"
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ where
f,
"{:?}<{}>",
self.kind,
self.is_nil()
(!self.is_nil())
.then(|| bs58::encode(self.uuid).into_string())
.unwrap_or_else(|| "NIL".to_string())
)
Expand Down
24 changes: 6 additions & 18 deletions src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ where
fn new_child(&self, ctx: &SmContext<K>, child_id: StateId<K>) {
let id = ctx.id;
let tree = ctx.state_store.get_tree(id).unwrap();
ctx.state_store.insert_ref(id, tree.clone());
ctx.state_store.insert_ref(child_id, tree.clone());
let mut tree = tree.lock();
tree.insert(Insert {
parent_id: Some(ctx.id),
Expand Down Expand Up @@ -387,9 +387,7 @@ mod tests {

use super::*;
use crate::{
node::{Insert, Node},
notification::GetTopic,
storage::StateStore,
test_support::Hold,
timeout::{Timeout, TimeoutMessage, TimeoutTopic, TEST_TICK_RATE, TEST_TIMEOUT},
Rex, RexBuilder, RexMessage,
Expand Down Expand Up @@ -608,21 +606,9 @@ mod tests {
let ping_id = StateId::new_rand(Game::Ping);
let pong_id = StateId::new_rand(Game::Pong);
// Menu + Ping + Pong
let menu_tree = Node::new(id)
.into_insert(Insert {
parent_id: Some(id),
id: ping_id,
})
.into_insert(Insert {
parent_id: Some(id),
id: pong_id,
});

let tree = StateStore::new_tree(menu_tree);
for id in [id, ping_id, pong_id] {
ctx.state_store.insert_ref(id, tree.clone());
}

self.create_tree(&ctx);
self.new_child(&ctx, ping_id);
self.new_child(&ctx, pong_id);
// signal to Ping state machine
ctx.signal_queue.push_back(Signal {
id: ping_id,
Expand Down Expand Up @@ -674,6 +660,7 @@ mod tests {
error!(?input, "invalid input!");
return;
};
assert!(ctx.get_parent_id().is_some());
let state = ctx.get_state().unwrap();
if Self::terminal_state(state) {
warn!(%id, ?state, "Ignoring input due to invalid state");
Expand Down Expand Up @@ -745,6 +732,7 @@ mod tests {
warn!(?state, "Ignoring input due to invalid state");
return;
}
assert!(ctx.get_parent_id().is_some());

match input {
PongInput::Packet(Packet {
Expand Down
1 change: 1 addition & 0 deletions src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ where
}
}

#[derive(Debug)]
pub struct Insert<Id> {
pub parent_id: Option<Id>,
pub id: Id,
Expand Down

0 comments on commit 0963a4a

Please sign in to comment.