Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI: Fix crash when creating scene collections with "unsafe" names #11301

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

PatTheMav
Copy link
Member

Description

Fixes possible crash when a new scene collection is created with a name that consists "unsafe" characters.

Motivation and Context

Scene collection names that are not considered "safe" by OBS Studio get a changed JSON file name with incompatible characters replaced.

The refactored scene collection implementation uses the Load function to either activate an existing scene collection or create a new one if it does not exist.

The Load function however overwrote the scene collection name set in the profile with its own variant based off the "safe" file name, which created a mismatch with the code that created the collection data model.

As the Load function is only called by ActivateSceneCollection (which itself already sets the name and filename for the collection), removal of this superfluous code in the Load function also fixes the issue.

How Has This Been Tested?

Tested on Windows 11 with a scene collection named "New Collection" which will be automatically stored in "New_Collection.json".

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code has been run through clang-format.
  • I have read the contributing document.
  • My code is not on the master branch.
  • The code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

Scene collection names that are not considered "safe" by OBS Studio
get a changed JSON file name with incompatible characters replaced.

The refactored scene collection implementation uses the Load function to
either activate an existing scene collection or create a new one if it
does not exist.

The Load function however overwrote the scene collection name set in
the profile with its own variant based off the "safe" file name, which
created a mismatch with the code that created the collection data
model.

As the Load function is only called by ActivateSceneCollection (which
itself already sets the name and filename for the collection), removal
of this superfluous code in the Load function also fixes the issue.
@PatTheMav PatTheMav added the Bug Fix Non-breaking change which fixes an issue label Sep 18, 2024
Comment on lines -1249 to -1252
config_set_string(App()->GetUserConfig(), "Basic",
"SceneCollection", name.c_str());
config_set_string(App()->GetUserConfig(), "Basic",
"SceneCollectionFile", name.c_str());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines were originally added as part of #11038 to fix a bug where scene collections could be erased (#11037). Can we confirm that that bug does not resurface from removing these lines?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The values are always set by ActivateCollection now, right before Load itself is called:

config_set_string(App()->GetUserConfig(), "Basic", "SceneCollection",
collection.name.c_str());
config_set_string(App()->GetUserConfig(), "Basic",
"SceneCollectionFile", collection.fileName.c_str());
Load(collection.collectionFile.u8string().c_str());

According to MSVC and Xcode that's the only function that calls Load so both config values should always be set with the added bonus that the collection name is not downgraded to a "safe" name for the file system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Fix Non-breaking change which fixes an issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants