mirror of
https://github.com/scp-fs2open/fs2open.github.com.git
synced 2026-11-07 08:15:59 -10:00
Two related fixes flagged by an audit of vm_vector_2_matrix_norm callers: ParticleEffectAction: locals.direction defaulted to vmd_zero_vector, which would trip vm_vector_2_matrix_norm's unit-length assertion (and divide by zero in release) when an action program emitted a particle effect without first running a Set Direction action. Default to vmd_z_vector so the unset-direction path always feeds a unit vector. matrix_h / Lua orientation type: the element indexer (m[1..9] = x) wrote arbitrary floats straight into mtx.a1d[idx] and the resulting non-orthonormal matrix could flow into obj->orient via the Orientation virt-vars on object/modelinstance/subsystem, breaking downstream engine code that assumes the basis vectors are unit length. getInterpolated had the same problem by design (pure linear interp, no normalization). Adds a fourth MatrixState, NeedsOrthonormalize, which the indexer setter and getInterpolated use to flag their output. ValidateMatrix and ValidateAngles now call vm_orthogonalize_matrix when they observe that state, so any consumer that reads through GetMatrix/GetAngles gets a valid orientation without each call site needing its own guard. getInterpolated is also marked ADE_FUNC_DEPRECATED at FSO 26.0 in favor of rotationalInterpolate; mods targeting older versions keep the legacy linear blend (now safely orthonormalized on use).
28 lines
603 B
C++
28 lines
603 B
C++
|
|
#include "common.h"
|
|
|
|
namespace actions {
|
|
|
|
expression::ParseContext getTableParseContext()
|
|
{
|
|
expression::ParseContext ctx;
|
|
|
|
auto& locals = ctx.variables.addScope("locals");
|
|
|
|
locals.addMember("position", expression::ValueType::Vector);
|
|
locals.addMember("direction", expression::ValueType::Vector);
|
|
|
|
return ctx;
|
|
}
|
|
expression::ProgramVariables getDefaultTableVariables()
|
|
{
|
|
expression::ProgramVariables vars;
|
|
|
|
vars.setValue({"locals", "position"}, expression::Value(vmd_zero_vector));
|
|
vars.setValue({"locals", "direction"}, expression::Value(vmd_z_vector));
|
|
|
|
return vars;
|
|
}
|
|
|
|
} // namespace actions
|