Jump to content

manage owner


photo

Recommended Posts

Hi dongju.jeong,

There are two types of objects: one of them destroys the internal engine object in the ~Ptr() destructor and another one not.
If you see these methods:
->grab();
->release();
->isOwner();
This is an indicator that the engine object will be destroyed in the ~Ptr() destructor (if you haven't transferred ownership of this object through release() -> grab() functions).

If you don't see this, ~Ptr() destructor will not destroy the engine object. But at this point a memory leak is possible. If this object wasn't attached to another one (Camera to Player, MeshDynamic to ObjectMeshDynamic, etc.) then you need to use Camera::release_ptr(my_camera_pointer.get()) to manually destroy the internal engine object.

Is camera.release() also required in init() to clear the camera from the shutdown function?
So, no, it is not required.

Best regards,
Alexander

Link to comment

Is it mean Ownership is automatically reassigned on playerspectator? so, camera  is automically cleared too?

then, What is this process?

image.png.46b287e4d22bf55f69f6e997b11dfdd9.png

Is this required only in UnigineScript?

Link to comment
  • 2 weeks later...

Hi dongju.jeong,

Is it mean Ownership is automatically reassigned on playerspectator? so, camera  is automically cleared too?
There is some "secret feature" (bad design): when you use PlayerSpectator::setCamera(CameraPtr cam) you don't pass the pointer of the Camera to the PlayerSpectator. You just make a copy and apply it to the inner Camera object.
For example:

CameraPtr cam = Camera::create();
cam->setFov(110.0f);
playerSpectator->setCamera(cam);

cam->setFov(30.0f); // this will not change in the PlayerSpectator!
playerSpecator->setCamera(cam); // you need to call setCamera() again


Is this required only in UnigineScript?
Yes, it is.
 

Best regards,
Alexander

Link to comment
×
×
  • Create New...