Instead of temporary allocating dynamic memory, which subsequently is
copied into another dynamically allocated piece of memory, provide a
temporary buffer on the stack.
The script value inserted into the VM still needs to allocate
dynamically though...
A few sites are adapted to not create a ScriptVariant_t from a temporary
Vector to avoid dynamic allocation there too.
cf. mapbase-source/source-sdk-2013#321
When assigning a null value in getVariant(), make sure a previous
SV_FREE is not carried over.
In SqurrelVM::ReleaseValue(), make sure SV_FREE is not kept after
Free()ing a value.
Type FIELD_HSCRIPT is removed, it never sets SV_FREE.
All dynamic memory is now free`d via free(). For strdup(), this would be
the conformant way in standard C++. It matters not in Source, since both
use the same global allocator of the engine, but it is tidier.
Vector and QAngle are now allocated via malloc() instead of new to
provide symmetry.
This function is used to color impact particles.
On Linux I've noticed that this function sometimes is not successful on
retrieving the surface color, leaving an odd color to render the
particles with. The engine function TraceLineMaterialAndLighting() even
has a boolean return value indicating success.
GetModelMaterialColorAndLighting() does not though, but I still observe
failures (the color parameter is not modified). The color is initialized
with an invalid value. If it detects that retrieving the color failed
(engine function said so or the invalid value was left in place), this
now hamfistedly assumes a lightish grey color, but at least still
correctly (presumably) incorporates lighting information.
When this situation is detected, a warning is also printed to the
console. Because why not.
When a Vector or QAngle rvalue reference is returned from a VScript
function, the constructed ScriptVariant_t must not store the pointer to
it since it is, per convention, a temporary reference. Only do that for
lvalue-references, but do a copy when constructing from or assigning a
rvalue reference.