Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

If you ever need to pass ownership of an API object outside a function, and the object is wrapped in a smart pointer, you can use the Detach() method of the MaxwellMayaPtr class. For example, if you want to write a function which creates and returns a mesh, you can write do something like this:

MaxwellMayaMesh* MakeMesh()
{
    MaxwellMayaMeshPtr mesh(api->CreateMesh(/* arguments */));
    if(!mesh)
    {
        // MaxwellMayaPtr can wrap NULL pointers. In that case, it simply does nothing when it goes out of scope.
        return NULL;
    }
    if(!mesh->SetPositions(/* arguments */))
    {
        // You can just return and the smart pointer will correctly destroy the mesh handle.
        return NULL;
    }
    // Pass ownership of the raw pointer to the caller. Detach() sets the internal pointer to
    // NULL, so nothing happens when the smart pointer exists the scope.
    return mesh.Detach();
}

...