frontend: Fix crashes caused by scene collections with empty internal name #11735
+8
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Prevents API clients against creating scene collections without a name, while also handling the possible case of a malformed scene collection gracefully.
Motivation and Context
OBS Studio itself does not allow users to create scene collections without a name, but the checks were not added to the internal API as well. Thus API clients were able to limbo right underneath that requirement.
This PR adds two changes:
This should prevent new malformed scene collections to be created by API clients but also protect users against having their OBS Studio instance crash over such malformed collections.
Note
A malformed scene collection will automatically be converted into a well-formed one once OBS Studio saves the current scene collection, as the fallback name will be written into the collection.
Tip
C++ Moment
Because
collectionName
is a glvalue, the code usesstd::move
to allow C++ to pilfer the contents of it when initialisingcandidateName
(turningcollectionName
into an xvalue), as it will not be used by anything else within the loop body after that assignment.That's also the reason why
collectionName
is not marked asconst
, because pilfering requires the ability to modify the contents of it (setting its internal string pointer tonullptr
). If it wereconst
, C++ would be forced to make a copy.Fixes #11609
How Has This Been Tested?
Tested with a scene collection that has an empty name and another collection that has no
name
key in its collection.Types of changes
Checklist: