Fix Player crash caused by unable to find ReplayStream file. Resolved it by utilizing MetaCoreDiscoverProjectRoot to find projectRoot and use relative path.

This commit is contained in:
ayuan9957 2026-05-21 17:49:16 +08:00
parent e85a5b8422
commit 77626017a3
6 changed files with 16 additions and 5 deletions

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,6 @@
{
"asset_type": "scene",
"guid": "8fc71145-66bd-4481-9b50-4f1bf9c908d7",
"importer": "SceneImporter",
"source_path": "Scenes/Main.mcscene"
}

View File

@ -1,4 +1,5 @@
#include "MetaCoreRuntimeData/MetaCoreRuntimeDataSource.h"
#include "MetaCoreFoundation/MetaCoreProject.h"
#include <algorithm>
#include <array>
@ -119,11 +120,14 @@ constexpr SOCKET MetaCoreInvalidSocket = INVALID_SOCKET;
[[nodiscard]] std::string MetaCoreResolveReplayFilePath(const std::string& replayFilePath) {
const std::filesystem::path inputPath(replayFilePath);
const std::vector<std::filesystem::path> candidates{
std::filesystem::current_path() / inputPath,
std::filesystem::current_path() / ".." / ".." / ".." / inputPath,
std::filesystem::current_path() / ".." / ".." / ".." / "TestProject" / "Runtime" / inputPath.filename()
std::vector<std::filesystem::path> candidates{
std::filesystem::current_path() / inputPath
};
if (const auto projectRoot = MetaCoreDiscoverProjectRoot()) {
candidates.push_back(*projectRoot / inputPath);
}
candidates.push_back(std::filesystem::current_path() / ".." / ".." / ".." / inputPath);
candidates.push_back(std::filesystem::current_path() / ".." / ".." / ".." / "TestProject" / "Runtime" / inputPath.filename());
for (const auto& candidate : candidates) {
std::error_code errorCode;

View File

@ -41,7 +41,8 @@ int main(int argc, char* argv[]) {
MetaCore::MetaCoreDataSourceSetting{"port", "7001"}
}
: std::vector<MetaCore::MetaCoreDataSourceSetting>{
MetaCore::MetaCoreDataSourceSetting{"file_path", "TestProject/Runtime/RuntimeReplay.mcstream"}
// 动态计算相对于项目根目录的播放流文件路径,替代原先硬编码的 TestProject
MetaCore::MetaCoreDataSourceSetting{"file_path", (std::filesystem::path(argv[1]).filename() / "RuntimeReplay.mcstream").generic_string()}
},
true,
1000