SplitmediaLabsLimited / xjs

XSplit JS Framework. Make plugins for XSplit Broadcaster, quickly and easily.
Other
39 stars 11 forks source link

Race condition for isVisible (and possibly more checks) #327

Open BrendaH opened 3 years ago

BrendaH commented 3 years ago

When looping over sources to set their visibility (item.setVisible(self.visible)) only the last source was actually updated with the given visibility. It looks like there's a race condition where an item is put into a 'slot' and then the visibility is adjusted. However, when another item has to do the same thing at (nearly) the same time, it might happen that the 'slot' is filled with this newer item before the visibility change is applied. Resulting in it only working on the last item.

This might be related to the comment about async attaching here: https://github.com/SplitmediaLabsLimited/xjs/issues/297#issuecomment-616413989

I circumvented this by awaiting just about everything that is going to Xsplit/xjs, but this was quite unexpected behaviour.

SML-MeSo commented 3 years ago

Shoot... Did a little check and indeed encountered the above-mentioned issue using a simple test

xjs.Scene.getActiveScene().then(scene => {
  myScene = scene;
  return myScene.getItems();
}).then(items => {
  myItems = items

  myItems.forEach(item => {
    item.setVisible(false)
  })
});
// only the last two items are hidden

Looked into it further by getting the properties instead and it now yielded the correct results (two true and two false values). While the second test did support my answer to the mentioned comment, it also showed that there's an inconsistency on the synch-ness of the calls to attach and setting and getting properties. Will check this further on core but as of now, yeah, we might need to use await to ensure that the proper items and their method calls are in synch.