Commit b38da135 authored by Dominik Charousset's avatar Dominik Charousset

Initialize state in ctor of parent actor

Initializing the state eagerly avoids subtle bugs such as accessing the
name of an actor before it is initialized.
parent e96c0df0
...@@ -46,6 +46,7 @@ public: ...@@ -46,6 +46,7 @@ public:
state(state_) { state(state_) {
if (detail::is_serializable<State>::value) if (detail::is_serializable<State>::value)
this->setf(Base::is_serializable_flag); this->setf(Base::is_serializable_flag);
cr_state(this);
} }
~stateful_actor() override { ~stateful_actor() override {
...@@ -55,8 +56,7 @@ public: ...@@ -55,8 +56,7 @@ public:
/// Destroys the state of this actor (no further overriding allowed). /// Destroys the state of this actor (no further overriding allowed).
void on_exit() final { void on_exit() final {
CAF_LOG_TRACE(""); CAF_LOG_TRACE("");
if (this->getf(Base::is_initialized_flag)) state_.~State();
state_.~State();
} }
const char* name() const final { const char* name() const final {
...@@ -77,7 +77,6 @@ public: ...@@ -77,7 +77,6 @@ public:
/// @cond PRIVATE /// @cond PRIVATE
void initialize() override { void initialize() override {
cr_state(this);
Base::initialize(); Base::initialize();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment