robotdotnet / NetworkTablesCore

Depreciated - Use NetworkTables repository instead
Other
1 stars 1 forks source link

InvalidOperationException when adding SubTableListener #19

Closed jkoritzinsky closed 8 years ago

jkoritzinsky commented 8 years ago

I found an issue while working on a possible RobotDotNet Dashboard (replacement/complement of SmartDashboard). The following steps result in an InvalidOperationException from adding two elements with the same key to an internal dictionary:

ThadHouse commented 8 years ago

Which Dictionary is the one failing? The one in CoreMethods is an easy fix. The one in NetworkTable would be harder.

Its not actually the SubTableListener that's erroring. It stores those as the value. The key is returned when the listener is added in ntcore, which ntcore starts at 0 and increments for every listener. When ntcore is shutdown, it destroys all listeners and starts counting at 0 again.

jkoritzinsky commented 8 years ago

I think I found the root of the issue. When disconnecting, NetworkTables.Native.CoreMethods.s_entryCallbacks is not cleared. However, because of the disconnect -> connect process, ntcore resets the callback count (which it uses to generate the uid that is causing the exception). I'm going to try having it clear on shutdown and see if that fixes it.

ThadHouse commented 8 years ago

With the fix, after shutdown as long as you create a new NetworkTable object using GetTable, it should pass. However any old NetworkTable objects would still fail.

jkoritzinsky commented 8 years ago

The one in CoreMethods. I'll test it out once AppVeyor finishes building it.

jkoritzinsky commented 8 years ago

That fixed it. I'll close the issue.