Version: 1.7.17
**Frequency:**Consistently
Severity: Blocker
Blocker - prevents from working on the project, prevents from releasing the product
Context: WASM gauge compiled with SU4 SDK (or older)
Similar MSFS 2020 issue: none, that’s 2024 API
Bug description:
I’ve encountered an issue where my code sending key events using fsEventsTriggerKeyEvent stopped working in SU5. While I don’t know how this function works internally, here’s my suspicion:
In SU5 SDK the FsVarParamVariant structure has been changed by adding FsVec3d field to the union.
struct FsVarParamVariant
{
eFsVarParamType type;
union {
unsigned int intValue;
const char* stringValue;
FsCRC CRCValue;
double doubleValue;
FsVec3d vec3dValue;
};
};
struct FsVarParamArray {
unsigned int size = 0;
FsVarParamVariant* array = nullptr;
};
This changed the size of the structure and made FsVarParamArray incompatible between different SDK versions, in cases when there is more than one item in the array. Code compiled with older SDK will pack the FsVarParamVariant objects into the array as if each was 12 bytes in size, while the simulator now expects them to be 28 bytes in size. So the receiving function not only can’t read any item other than FsVarParamArray.array[0], but will also over-read the buffer with unpredictable results.
This approach would work if the FsVarParamArray was “a struct containing an array with pointers to the variant” (FsVarParamVariant** array), as stated in the SDK documentation description Core And Helpers
However, the actual code is instead “an array of variants” (FsVarParamVariant* array), which is susceptible to variant struct size changes and not portable between versions.
Repro steps:
This code compiled with SU4 SDK works in MSFS SU4, but not in SU5. The event is not sent to the sim at all, or it’s sent but the second event parameter contains garbled data
auto tmp = FsCreateParamArray("ii", 1013 * 16, 2);
fsEventsTriggerKeyEvent(KEY_KOHLSMAN_SET, tmp);
FsDestroyParamArray(&tmp);
Same with this code that does not use helper functions
FsVarParamVariant var[2];
var[0].type = FsVarParamTypeInteger;
var[0].intValue = 1013 * 16;
var[1].type = FsVarParamTypeInteger;
var[1].intValue = 2;
FsVarParamArray param;
param.size = 2;
param.array = var;
fsEventsTriggerKeyEvent(KEY_KOHLSMAN_SET, param);
Attachments: