POV-Ray : Newsgroups : povray.programming : TrueType::Copy method TODO comment likely should change? Server Time
31 Mar 2025 01:18:37 EDT (-0400)
  TrueType::Copy method TODO comment likely should change? (Message 1 to 1 of 1)  
From: Ray Gardener
Subject: TrueType::Copy method TODO comment likely should change?
Date: 6 Mar 2025 01:26:31
Message: <67c94017$1@news.povray.org>
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

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.