Skip to content

Commit 6b933ed

Browse files
committed
Fix race condition
1 parent dbb9e3c commit 6b933ed

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Source/RunActivity/Viewer3D/WebServices/WebServer.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ IEnumerable<string> GetValues()
262262
// SetCabControls() expects a request passing an array of ControlValuePost objects using JSON.
263263
// For example:
264264
// [{ "TypeName": "THROTTLE" // A CABViewControlTypes name - must be uppercase.
265-
// , "ControlIndex": 1 // This property is optional and used in rendering cab view
265+
// , "ControlIndex": 1 // Index of control type in CVF (optional for most controls)
266266
// , "Value": 0.50 // A floating-point value
267267
// }
268268
// ]
@@ -271,14 +271,16 @@ IEnumerable<string> GetValues()
271271
public async Task SetCabControls()
272272
{
273273
var data = await HttpContext.GetRequestDataAsync<IEnumerable<ControlValuePost>>(WebServer.DeserializationCallback<IEnumerable<ControlValuePost>>);
274-
var dev = UserInput.WebDeviceState;
274+
var dev = UserInput.WebDeviceState;
275275
foreach (var control in data)
276276
{
277277
var key = (new CabViewControlType(control.TypeName), control.ControlIndex);
278278
if (!dev.CabControls.TryGetValue(key, out var state))
279279
{
280280
state = new ExternalDeviceCabControl();
281-
dev.CabControls[key] = state;
281+
var controls = new Dictionary<(CabViewControlType, int), ExternalDeviceCabControl>(dev.CabControls);
282+
controls[key] = state;
283+
dev.CabControls = controls;
282284
}
283285
state.Value = (float)control.Value;
284286
}

0 commit comments

Comments
 (0)