Doesn't "reconnect" if you restart the sim whilst code is running
BarryCarlyon opened this issue · comments
So if you run your code that connects to the sim.
var success = simConnect.open("SomeName", (name, version) => {
- Open the sim
- it connects
- Close the sim (safe quit as apposed to CTD)
- it disconnects
- Open the sim
It "connects" but the .open
callback doesn't fire, but var success
is true
It's a new issue in MSFS 1.12.13.0
. I fed in the latest SDK (0.9.0.0
) but it didn't help
Not sure if it's a new MSFS bug or something with node-simconnect
? I'm trying to poke about and see if I can find out what's occurring but wanted to open this issue.
I am using westlakem modification for the Electron Compile. But I anticipate it's MSFS at fault here. As it didn't do this until todays update.
If you taskill MSFS, you get a an abnormal disconnect and it will reconnect (call the open
callback) fine.
Pre todays update or if you taskkill today, code generates a SimConnect error: 0xC000014B
Basically any "normal" close of MSFS results in not being able to reconnect to the sim, without restarting the node process.
I tried something nutty like
function connectToSim() {
simConnect = '';
for (var k in require.cache) {
if (k.indexOf('node-simconnect') >= 0) {
if (k.indexOf('index.js') >= 0) {
console.log('uncache', k);
delete require.cache[k];
}
}
}
simConnect = require('node-simconnect');
But it doesn't seem to help. (dump cache and refresh)
So it's damn weird
In some testing, it doesn't seem to affect the refactor branch. (running outside of electron)
But does the main branch (also outside of electron)
But it's stated we shouldn't use it (refactor) in "production" yet, so I'm hesitant to switch over for my app/usage.
Additionally under main, a setInterval'ed
call to
simConnect.requestDataOnSimObjectType(navInfoDefIdOthers, function(data) {
Is yielding no data/planes returned. So it's not just the open
callback that is failing. (standard 10km range, and I'm parked at EGLL/Heathrow, so there's always 100 odd planes in sim)
Edit: Random side thought, I think under MSFS 1.12.13.0
they actually fixed is so on normal close, NodeSimconnect reads a proper quit (well a quit and an error). (And it's probable the error comes from my setInterval'ed call to requestDataOnSimObjectType
And the issue is in the quit/cleanup logic. As prior to 1.12.13.0
I recall we would just get a sincommect error instead of a nice quit.
It seems that modify all "reconnect" to have an explicit close before hand resolves the problem I have observed
So
https://github.com/EvenAR/node-simconnect/blob/master/examples/nodejs/example.js#L5
Becomes
function connectToSim() {
console.log("Trying to connect...")
var success = simConnect.open("MyAppName", function(name, version) {
console.log("\n-----------------------------------------------\nConnected to: " + name + "\nSimConnect version: " + version + "\n-----------------------------------------------");
doStuffWithSimconnect();
}, () => {
console.log("Quit.... :(");
simConnect.close();
setTimeout(() => {
connectToSim();
}, 5000);
}, (exception) => {
console.log("SimConnect exception: " + exception.name + " (" + exception.dwException + ", " + exception.dwSendID + ", " + exception.dwIndex + ", " + exception.cbData + ")");
}, (error) => {
// Happens for example when connection with SimConnect is lost unexpectedly. For crash details: ntstatus.h
console.log("SimConnect error: " + error);
// The connection must be re-opened
simConnect.close();
setTimeout(() => {
connectToSim();
}, 5000);
});
if(!success) {
simConnect.close();
setTimeout(() => {
connectToSim();
}, 5000);
}
}
Instead.
It's proving more reliable in the
- start app
- open sim
- app connects
- close sim (safe quit as apposed to CTD)
- open sim
- app reconnects properly (calls open callback etc) (yay)
scenario
The explicit call to .close()
seems to tidy out whatever "normal quit" buffer/garbage that doesn't get cleaned up.
I understand a workaround was found for the old version and that v3.x handles this better.