In the copy code for CScriptArray, I notice that handles are released when they are replaced.
[source]void CScriptArray::CopyBuffer(SArrayBuffer *dst, SArrayBuffer *src)
{
asIScriptEngine *engine = objType->GetEngine();
if( subTypeId & asTYPEID_OBJHANDLE )
{
// Copy the references and increase the reference counters
if( dst->numElements > 0 && src->numElements > 0 )
{
int count = dst->numElements > src->numElements ? src->numElements : dst->numElements;
void **max = (void**)(dst->data + count * sizeof(void*));
void **d = (void**)dst->data;
void **s = (void**)src->data;
for( ; d < max; d++, s++ )
{
void *tmp = *d;
*d = *s;
if( *d )
engine->AddRefScriptObject(*d, objType->GetSubType());
// Release the old ref after incrementing the new to avoid problem incase it is the same ref
if( tmp )
engine->ReleaseScriptObject(tmp, objType->GetSubType());
}
}
}
else
{
if( dst->numElements > 0 && src->numElements > 0 )
{
int count = dst->numElements > src->numElements ? src->numElements : dst->numElements;
if( subTypeId & asTYPEID_MASK_OBJECT )
{
// Call the assignment operator on all of the objects
void **max = (void**)(dst->data + count * sizeof(void*));
void **d = (void**)dst->data;
void **s = (void**)src->data;
for( ; d < max; d++, s++ )
engine->AssignScriptObject(*d, *s, subTypeId);
}
else
{
// Primitives are copied byte for byte
memcpy(dst->data, src->data, count*elementSize);
}
}
}
}
[/source]
In the Destruct function, however, only types with a bit set in the Object mask are released, which does not appear to include handles.
[source]void CScriptArray::Destruct(SArrayBuffer *buf, asUINT start, asUINT end)
{
if( subTypeId & asTYPEID_MASK_OBJECT )
{
asIScriptEngine *engine = objType->GetEngine();
void **max = (void**)(buf->data + end * sizeof(void*));
void **d = (void**)(buf->data + start * sizeof(void*));
for( ; d < max; d++ )
{
if( *d )
engine->ReleaseScriptObject(*d, objType->GetSubType());
}
}
}[/source]
Is there a reason for this, or is it an oversight?