fsCommBusCall() always returns true

Version: SU15 - 1.37.8.0

SDK Version: 0.24.1.0

Frequency: Consistently

Severity: High

Hi Team,

so, I was trying to figure out, if a certain function has already been registered via fsCommBusRegister() by a wasm with the above mentioned method in order to determine, if I should register it myself.

My approach was to simply call the function and as it should not have been registered yet, receiving a false from the above mentioned methods return value. But this method always returns true for me, as if the call was going somewhere successful, even though this is not possible and of course the breakpoint in this method is also not hit in my code, suggesting that something is wrong with the return value of fsCommBusCall() itself.

In this very quick and dirty demo I try and register “fooBar” right after my wasm has been loaded by the sim and as you can see, callReturnValue is true after the fsCommBusCall().

As I was not using the whole CommBus functionality prior to SU 15 flighting and the most recent SDK, I cannot say, if it behaved differently before.

Maybe somebody can enlighten me, what might be going on?

Greets,
Ben

Just some observations from the published docs…

The docs on the return type of fsCommBusCall() are clearly just copied from fsCommBusRegister() docs, which basically means we don’t know what it’s supposed to return. Clearly a docs bug there, at least. But it’s quite possible the function itself never checks if a method is registered.

(Many of the C API functions behave this way, presumably they just place an event into a queue, essentially, and don’t know what happens with it later. For example execute_calculator_code() returns true even for complete junk RPN which will show errors in the MSFS dev Console – but there’s no way to programmatically determine if the input was good.)

Not sure if this helps, the docs for fsCommBusRegister() discuss re-registering a method in the Remarks section.
https://docs.flightsimulator.com/html/Programming_Tools/WASM/Communication_API/fsCommBusRegister.htm#remarks

-Max

1 Like

Thanks for the thorough reply and your observations, Max. But then I am asking myself as to why those methods even return anything at all, if the return value is basically meaningless :laughing: .

For me the main question is, what happens if I am fsCommBusRegister(“fooBar”, MyCallback, nullptr) ing, but exactly the same method name has already been registered in the MSFS ecosystem, even of course with another callback function as second arg. How would an fsCommBusCall(“fooBar”, nullptr, 0, FsCommBusBroadcast_AllWasm) be handled in terms of which callback to call? As the docs only mention the case, when the same wasm tries to fsCommBusRegister() with the exact same arguments again.

If anything, having a distinct fsCommBusIsRegistered(“fooBar”) or something along those lines seems like a sensible idea to me?

But then mabye I am making up a problem where there actually is none :grinning:.

Greets,
Ben

Hi

This function will post a message on a bus which will call registered functions. This part will be delayed and is not synchrone with your wasm module. This is the first reason why you cannot have a return value to know if a message has been delivered to someone. Furthermore, knowing who is registered on a specific event is “against” the principle of the message bus.

But don’t worry, this function can fail for internal reasons or bad uses (buf = nullptr and size != 0 for instance). So, this is a good thing who always sees it succeeds :slightly_smiling_face:.

About your second question :

what happens if I am fsCommBusRegister(“fooBar”, MyCallback, nullptr) ing, but exactly the same method name has already been registered in the MSFS ecosystem, even of course with another callback function as second arg.

You don’t have to worry about what other people register on what event. Even if a other module register a MyCallback function on the “foobar” event, it will not collide with yours.

How would an fsCommBusCall(“fooBar”, nullptr, 0, FsCommBusBroadcast_AllWasm) be handled in terms of which callback to call?

This will call every function (wasm side) registered on the “fooBar” event. If there is no function registered, nothing will happen. Otherwise, each function will be called with a buf = nullptr and size = 0. Note that, by using the FsCommBusBroadcast_AllWasm flag, all wasm callbacks will be called including yours.

when the same wasm tries to fsCommBusRegister() with the exact same arguments again.

This will fail

If anything, having a distinct fsCommBusIsRegistered(“fooBar”) or something along those lines seems like a sensible idea to me?

As i said, I don’t think this is a good idea to know precisely what and who is registered. But if you have a specific case in mind, in which this feature is mandatory, please let us know.

Best Regards
Maxime / Asobo

2 Likes

Hello @Arzop ,

Without wanting to hijack this post, can you please let us know what is the maximum size of fsCommBusCall() for the buffer?

1 Like

Merci beaucoup Maxime…that clears things up for me in understanding the mechanic.

Blockquote You don’t have to worry about what other people register on what event. Even if a other module register a MyCallback function on the “foobar” event, it will not collide with yours.

So the way I read that is that the CommBus functionality is confined to…only my own package? Meaning a wasm or js running from another package will not be able to call my specific fsCommBusRegister() ed methods?

Thanks again for the clarifications.

Hi

I advice you not to exceed 8 Mb. The current limit is a bit bigger but we might reduce it in the futur.

Best Regards
Maxime / Asobo

Hi

So, everyone is able to register to any event independently.
For instance, a wasm module A (from the package A) with a MyCallback function can register to the foobar event. Then, a wasm module B (from the package B) with a MyCallback function can also register to the foobar event. Both modules are independant and they don’t know that someone else has registered to this event. Finally, a js module (from package C) sends a message to the foobar event. This message will be delivered to A and B.

The point of this API is to deliver messages between module regardless their package. So anyone can register and/or call any event.

Best Regards
Maxime / Asobo

1 Like

Thanks Maxime:

Finally, a js module (from package C ) sends a message to the foobar event. This message will be delivered to A and B .

This clears it up fully for me.

Maybe also the CommBus docs can be ammended to include the registration being confined to package scope, but calling being done MSFS wide.

Have a nice weekend.

Greets,
Ben