浏览代码

UI: Use filename stem as fallback value on empty collection name

If - for some reason - the name in a scene collection is empty (or
the key doesn't even exist), use the filename stem as a fallback name.

This ensures that the scene collection entry in the cache has a valid
non-empty name.

Using an std::string allows the use of its "empty" method to check for
this otherwise invalid state of the collection data.

Ported from 1baa4619e4ba2c8c59b275b009a7cdadb1ab6724.

Co-authored-by: PatTheMav <[email protected]>
Ryan Foster 9 月之前
父节点
当前提交
07be61a2e3
共有 1 个文件被更改,包括 4 次插入4 次删除
  1. 4 4
      UI/window-basic-main-scene-collections.cpp

+ 4 - 4
UI/window-basic-main-scene-collections.cpp

@@ -388,12 +388,12 @@ void OBSBasic::RefreshSceneCollectionCache()
 			obs_data_create_from_json_file_safe(entry.path().u8string().c_str(), "bak");
 
 		std::string candidateName;
-		const char *collectionName = obs_data_get_string(collectionData, "name");
+		std::string collectionName = obs_data_get_string(collectionData, "name");
 
-		if (!collectionName) {
-			candidateName = entry.path().filename().u8string();
+		if (collectionName.empty()) {
+			candidateName = entry.path().stem().u8string();
 		} else {
-			candidateName = collectionName;
+			candidateName = std::move(collectionName);
 		}
 
 		foundCollections.try_emplace(candidateName,