Jump to content
The simFlight Network Forums

Key already exists exceptions


Nabeel

Recommended Posts

Hi,

I'm getting a lot of crashes with errors like these:

Quote
System.ArgumentException: An item with the same key has already been added. Key: A320_Audio:Relay_1
  ?, in bool Dictionary<TKey, TValue>.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
  ?, in void LVarCollection.add(FsLVar lvar)
  ?, in void WAPI.fsuipcw_getLvarList(ReceiveListCallback ReceiveFunction)
  ?, in void MSFSVariableServices.refreshData()
  ?, in void MSFSVariableServices.lvarsValueChanged(IntPtr id, IntPtr Value)

With various keys. I'm not sure if there's an issue in my code; here is the init code (with simconnect):

 try {
   VS.LogLevel = LOGLEVEL.LOG_LEVEL_INFO;
   VS.OnValuesChanged += VS_OnValuesChanged;
   VS.OnLogEntryReceived += VS_OnLogEntryReceived;

   VS.Init();

   VS.Start();
 } catch (Exception e) {
   Log.Error($"Error initializing WASM module ${e.Message}");
 }

And then the stripped down code which checks, but I'm not sure there's anything here that I'm doing incorrectly.

lock (_lvarUpdateLock) {
            bool anyChanged = false;
            foreach (var fvd in AircraftFeatures.FeatureLVarIterator()) {
                if (fvd == null || string.IsNullOrEmpty(fvd.LookupKey)) {
                    continue;
                }

                if (!VS.LVars.Exists(fvd.LookupKey)) {
                    continue;
                }

                var value = VS.LVars[fvd.LookupKey].Value;

                if (fvd.Value != value) {
                    Log.Trace($"LVar {fvd.LookupKey} found changed, value={value}, old={fvd.Value}");
                }

                fvd.Value = VS.LVars[fvd.LookupKey].Value;
                anyChanged = true;
            }
...

The client DLL version is 3.3.5.405. But it doesn't seem like there's anything in my code I can update. I'm removing the VS_OnValuesChanged handler on a stop, bit I'm reorganizing this code just in case there's the callback being registered multiple times. But I don't think that'd matter in this context.

Link to comment
Share on other sites

Dug another one out of error reporting

 

Quote
System.InvalidOperationException: Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct.
  ?, in ref TValue Dictionary<TKey, TValue>.FindValue(TKey key)
  ?, in void MSFSVariableServices.receiveValuesCallback(string name, double value)
  ?, in void WAPI.fsuipcw_getLvarValues(ReceiveValuesCallback ReceiveFunction)
  ?, in void MSFSVariableServices.refreshData()
  ?, in void MSFSVariableServices.lvarsValueChanged(IntPtr id, IntPtr Value)

 

Link to comment
Share on other sites

HI Nabeel,

Quote

I'm getting a lot of crashes with errors like these:

It looks like a threading issue. It seems like my DLL is receiving simultaneous callbacks from the WASM library on different threads.

It nothing to do with your code. 

Quote

Looks like they started showing up two weeks ago,

John did change the WASM library to automatically report new LVar discoveries about two weeks ago. It could be related to that.

I'll add some thread-safety to this part of my DLL tomorrow. Hopefully that will fix it.

Paul 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.