From 3bd09ae286e4ac8d82bbe57c833bf5f2e108bf43 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 22 Mar 2017 11:17:52 +0800 Subject: [PATCH] [win32] Fixes cpp-tests/FileUtilsTest crash. (#17551) --- .../Classes/FileUtilsTest/FileUtilsTest.cpp | 8 ++++---- .../NewAudioEngineTest/NewAudioEngineTest.cpp | 2 +- .../Classes/lua_assetsmanager_test_sample.cpp | 13 +------------ 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/tests/cpp-tests/Classes/FileUtilsTest/FileUtilsTest.cpp b/tests/cpp-tests/Classes/FileUtilsTest/FileUtilsTest.cpp index 93bfa9078b..1f85a16359 100644 --- a/tests/cpp-tests/Classes/FileUtilsTest/FileUtilsTest.cpp +++ b/tests/cpp-tests/Classes/FileUtilsTest/FileUtilsTest.cpp @@ -35,7 +35,7 @@ void TestResolutionDirectories::onEnter() std::string ret; sharedFileUtils->purgeCachedEntries(); - _defaultSearchPathArray = sharedFileUtils->getSearchPaths(); + _defaultSearchPathArray = sharedFileUtils->getOriginalSearchPaths(); std::vector searchPaths = _defaultSearchPathArray; searchPaths.insert(searchPaths.begin(), "Misc"); sharedFileUtils->setSearchPaths(searchPaths); @@ -89,7 +89,7 @@ void TestSearchPath::onEnter() std::string ret; sharedFileUtils->purgeCachedEntries(); - _defaultSearchPathArray = sharedFileUtils->getSearchPaths(); + _defaultSearchPathArray = sharedFileUtils->getOriginalSearchPaths(); std::vector searchPaths = _defaultSearchPathArray; std::string writablePath = sharedFileUtils->getWritablePath(); std::string fileName = writablePath+"external.txt"; @@ -139,7 +139,7 @@ void TestSearchPath::onEnter() // Save old resource root path std::string oldDefaultRootPath = sharedFileUtils->getDefaultResourceRootPath(); - sharedFileUtils->setDefaultResourceRootPath("extensions"); + sharedFileUtils->setDefaultResourceRootPath(oldDefaultRootPath + "extensions"); auto sp1 = Sprite::create("orange_edit.png"); sp1->setPosition(VisibleRect::center()); addChild(sp1); @@ -147,7 +147,7 @@ void TestSearchPath::onEnter() // Recover resource root path sharedFileUtils->setDefaultResourceRootPath(oldDefaultRootPath); - auto oldSearchPaths = sharedFileUtils->getSearchPaths(); + auto oldSearchPaths = sharedFileUtils->getOriginalSearchPaths(); sharedFileUtils->addSearchPath("Images"); auto sp2 = Sprite::create("btn-about-normal.png"); sp2->setPosition(VisibleRect::center() + Vec2(0, -50)); diff --git a/tests/cpp-tests/Classes/NewAudioEngineTest/NewAudioEngineTest.cpp b/tests/cpp-tests/Classes/NewAudioEngineTest/NewAudioEngineTest.cpp index ec7b9552fd..c0fc194fe8 100644 --- a/tests/cpp-tests/Classes/NewAudioEngineTest/NewAudioEngineTest.cpp +++ b/tests/cpp-tests/Classes/NewAudioEngineTest/NewAudioEngineTest.cpp @@ -952,7 +952,7 @@ void AudioPlayFileInWritablePath::onEnter() std::string musicFile = "background.mp3"; std::string saveFilePath = writablePath + "background_in_writable_dir.mp3"; - _oldSearchPaths = fileUtils->getSearchPaths(); + _oldSearchPaths = fileUtils->getOriginalSearchPaths(); fileUtils->addSearchPath(writablePath, true); if (!fileUtils->isFileExist(saveFilePath)) diff --git a/tests/lua-tests/project/Classes/lua_assetsmanager_test_sample.cpp b/tests/lua-tests/project/Classes/lua_assetsmanager_test_sample.cpp index b872a8c0a9..1f28ceb31c 100644 --- a/tests/lua-tests/project/Classes/lua_assetsmanager_test_sample.cpp +++ b/tests/lua-tests/project/Classes/lua_assetsmanager_test_sample.cpp @@ -113,18 +113,7 @@ static int lua_cocos2dx_addSearchPath(lua_State* L) #endif std::string pathToSave = tolua_tostring(L, 1, ""); bool before = tolua_toboolean(L, 2, 0); - std::vector searchPaths = FileUtils::getInstance()->getSearchPaths(); - if (before) - { - searchPaths.insert(searchPaths.begin(), pathToSave); - } - else - { - searchPaths.push_back(pathToSave); - } - - FileUtils::getInstance()->setSearchPaths(searchPaths); - + FileUtils::getInstance()->addSearchPath(pathToSave, before); return 0; } CCLOG("'addSearchPath' function wrong number of arguments: %d, was expecting %d\n", argc, 2);