std::unique_ptr
assumes sole ownership of the pointed-to object, and deletes the object when the unique_ptr
goes out of scope. So after detectCollision
returns, charSprite
is deleted. Since you never actually allocated charSprite
(but rather allocated iPlayer
, with charSprite
in it), that's not kosher.
It sounds like you don't actually want unique_ptr
here. You don't intend to transfer ownership.