Throw exception on each method of CharacterBody3D derived class

Godot Version

4.2.1 windows

Question

Hello all i have some weird behavior :
those class’s

namespace fpsgame {

	class Player : public godot::CharacterBody3D
	{
		GDCLASS(Player, godot::CharacterBody3D)
	public:
		Player() {
		};
		virtual ~Player() = default;
		virtual void _ready() override;
	 
		
	protected:
		static void _bind_methods() {};
	private:
		 

	};
}

namespace fpsgame {

	void Player::_ready()
	{
		CameraController = this->get_node<godot::Camera3D>("CameraController/Camera3D");
		pAnimationPlayer = this->get_node<godot::AnimationPlayer>("AnimationPlayer");
		pShapeCast3D = this->get_node<godot::ShapeCast3D>("ShapeCast3D");
		pCameraSide = this->get_parent()->get_node<godot::Camera3D>("Camera3D_SIDE");
 	 
	}


	 
}




namespace fpsgame {
	class State : public godot::Node
	{
		GDCLASS(State, godot::Node)

	public:
		State();
		virtual ~State() = default;
		virtual void _ready() override;
		 

	protected:
		static void _bind_methods();
		Player* player;
		
	private:

};

namespace fpsgame {


	State::State()
	{
		
	}

	void State::_ready()
	{
		 
		if (!rl::engine::editor_active())
		{			 
			player = get_tree()->get_current_scene()->get_node<fpsgame::Player>("Player");
		}
	}

	void State::_bind_methods()
	{
		ADD_SIGNAL(godot::MethodInfo("transition", godot::PropertyInfo(godot::Variant::STRING_NAME, "new_state_name")));
	}
 
}

namespace fpsgame {

	class WalkingPlayerState : public State {
		GDCLASS(WalkingPlayerState, State)

	public:
		WalkingPlayerState() {};
		virtual ~WalkingPlayerState() = default;
		void _ready();
		 
	protected:
		static void _bind_methods() {};
	private:


};


 
namespace fpsgame {

	void WalkingPlayerState::_ready()
	{
		if (!rl::engine::editor_active())
		{
			Player* player2 = get_tree()->get_current_scene()->get_node<fpsgame::Player>("Player");
			float ss2 = player->get_velocity().length();
		}
	}

	
}

the player is not null and it throw exception on every method i try to access

also in visual studio iin output tab getting
image

player2 not looks like null see here :

I continued testing. I have this function that replaces nodes. When I added memfree , it can now call the methods of the player, but after two exchanges, it gives me a memory exception

do i handle this correctly ?

void StateMechine::on_child_transition(godot::StringName new_state_name)
	{
		State* new_state = Object::cast_to<State>(states[new_state_name]);
		
		if (new_state != nullptr && new_state->is_node_ready())
		{
			if (pCurrentState->get_name().to_lower() != new_state->get_name().to_lower())
			{
				pCurrentState->exit();
				pCurrentState = new_state;
				memfree(new_state);
				pCurrentState->enter();
			}
		}

	}

This is the new exception