Cuberite Forum
safety of cMonster::m_Target - Printable Version

+- Cuberite Forum (https://forum.cuberite.org)
+-- Forum: Cuberite (https://forum.cuberite.org/forum-4.html)
+--- Forum: Development (https://forum.cuberite.org/forum-13.html)
+--- Thread: safety of cMonster::m_Target (/thread-2324.html)

Pages: 1 2


safety of cMonster::m_Target - LogicParrot - 01-19-2016

cMonster::m_Target holds a raw entity pointer. Is this safe when entities Teleport, etc.?


RE: safety of cMonster::m_Target - NiLSPACE - 01-19-2016

For teleports it should be save, but when the entity dies or is removed it's not.


RE: safety of cMonster::m_Target - LogicParrot - 01-19-2016

(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?


RE: safety of cMonster::m_Target - worktycho - 01-19-2016

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.


RE: safety of cMonster::m_Target - xoft - 01-22-2016

Not sure if that's possible with a cPlayer object, the client doesn't expect its EntityID to change.


RE: safety of cMonster::m_Target - worktycho - 01-22-2016

We could create a new entity with the same ID.


RE: safety of cMonster::m_Target - xoft - 01-23-2016

That feels much more hackish than moving the entity to another world.


RE: safety of cMonster::m_Target - LogicParrot - 01-23-2016

(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.


RE: safety of cMonster::m_Target - xoft - 01-23-2016

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.


RE: safety of cMonster::m_Target - LogicParrot - 01-23-2016

(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.