Cuberite Forum

Full Version: safety of cMonster::m_Target
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
cMonster::m_Target holds a raw entity pointer. Is this safe when entities Teleport, etc.?
For teleports it should be save, but when the entity dies or is removed it's not.
(01-19-2016, 12:38 AM)NiLSPACE Wrote: [ -> ]For teleports it should be save, but when the entity dies or is removed it's not.

What about teleports to other worlds? Do entities in different world tick in the same thread?
They tick in different threads. Which is why I think that teleport should be done by destroying the old entity, and creating a new one, rather than transfering the entity.
Not sure if that's possible with a cPlayer object, the client doesn't expect its EntityID to change.
We could create a new entity with the same ID.
That feels much more hackish than moving the entity to another world.
(01-23-2016, 01:10 AM)xoft Wrote: [ -> ]That feels much more hackish than moving the entity to another world.

We'd need a safe way of telling everyone to let go of pointers to an entity when that entity teleports to avoid threading problems. Copying is one way, possibly the simplest way.
Quite the opposite - you need to tell everyone to let go of the pointers when you delete the entity to replace it with a new one. When keeping the same entity for the new world, the pointers can be kept.
(01-23-2016, 02:06 AM)xoft Wrote: [ -> ]Quite the opposite - you need to tell everyone to let go of the pointers when you delete the entity to replace it with a new one.

That problem is unrelated to world travel, it's a global thing - you need to have code which notifies others of your destruction anyways, regardless of anything discussed in this thread.

Quote:When keeping the same entity for the new world, the pointers can be kept.
They should never be kept. It is not thread safe to keep them.
Pages: 1 2