|
 |
Was browsing the source code of povray 3.7 stable and came across this
in core/shape/truetype.cpp:
ObjectPtr TrueType::Copy()
{
TrueType *New = new TrueType();
Destroy_Transform(New->Trans);
*New = *this;
New->Trans = Copy_Transform(Trans);
New->glyph = glyph; // TODO - How can this work correctly? [trf]
return (New);
}
The issue posed by the TODO comment may be unnecessary,
because TrueType::glyph is pointing to the glyph data
in the loaded font so shared references are inherent and
responsibility of deletion rests with TrueTypeInfo::~TrueTypeInfo().
It does look sus at first glance because shapes like
heightfields and meshes increment reference counters
whenever copying pointers to heavy geometry, and their
destructors decrement the counter and then delete if
the counter reaches zero.
Since that's not the case here, I recommend changing
the TODO comment to something like: "This is okay; TrueTypeInfo has sole
ownership of glyph and its dtor will dispose of it when font no longer
in use."
A safer and more self-documenting way might be to use std::shared_ptr,
but I understand that'd be a bit of work and the C++ transition is a
work in progress.
Ray Gardener
Post a reply to this message
|
 |