From b7c624805efa2afca6cd9b5b0c1b89ecc7eb8724 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Mon, 10 Aug 2015 15:51:26 +0800 Subject: [PATCH 1/3] fix material parsing crash on WP8.1 because memory exhausted --- .../MaterialSystemTest/MaterialSystemTest.cpp | 47 ++++++++++++++++--- .../MaterialSystemTest/MaterialSystemTest.h | 3 ++ 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/tests/cpp-tests/Classes/MaterialSystemTest/MaterialSystemTest.cpp b/tests/cpp-tests/Classes/MaterialSystemTest/MaterialSystemTest.cpp index 87cbe8043b..6885acfb1a 100644 --- a/tests/cpp-tests/Classes/MaterialSystemTest/MaterialSystemTest.cpp +++ b/tests/cpp-tests/Classes/MaterialSystemTest/MaterialSystemTest.cpp @@ -30,7 +30,7 @@ #include "../testResource.h" #include "cocos2d.h" - +#include "ui/CocosGUI.h" USING_NS_CC; @@ -364,19 +364,54 @@ std::string Material_clone::subtitle() const void Material_parsePerformance::onEnter() { MaterialSystemBaseTest::onEnter(); + + _maxParsingCoumt = 1e4; + + auto screenSize = Director::getInstance()->getWinSize(); + + ui::Slider* slider = ui::Slider::create(); + slider->loadBarTexture("cocosui/sliderTrack.png"); + slider->loadSlidBallTextures("cocosui/sliderThumb.png", "cocosui/sliderThumb.png", ""); + slider->loadProgressBarTexture("cocosui/sliderProgress.png"); + slider->setPercent(50); + + slider->setPosition(Vec2(screenSize.width / 2.0f, screenSize.height / 3.0f)); + slider->addEventListener([&](Ref* sender, ui::Slider::EventType type) { + + if (type == ui::Slider::EventType::ON_PERCENTAGE_CHANGED) + { + ui::Slider* slider = dynamic_cast(sender); + float p = slider->getPercent() / 100.0f; + CCLOG("Will parsing material %d times", (int)(p * _maxParsingCoumt)); + this->scheduleOnce( + [this, p](float) + { + this->parsingTesting(p * _maxParsingCoumt); + }, + 1.0, "schedule test parsing"); + + } + }); + + addChild(slider); + +} + +void Material_parsePerformance::parsingTesting(unsigned int count) +{ std::clock_t begin = std::clock(); - - for(int i=0;i<5000;i++) + + for(int i=0;i Date: Mon, 10 Aug 2015 16:12:15 +0800 Subject: [PATCH 2/3] refine test case to be more testing friendly --- .../MaterialSystemTest/MaterialSystemTest.cpp | 34 ++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/tests/cpp-tests/Classes/MaterialSystemTest/MaterialSystemTest.cpp b/tests/cpp-tests/Classes/MaterialSystemTest/MaterialSystemTest.cpp index 6885acfb1a..f9b05d3ac9 100644 --- a/tests/cpp-tests/Classes/MaterialSystemTest/MaterialSystemTest.cpp +++ b/tests/cpp-tests/Classes/MaterialSystemTest/MaterialSystemTest.cpp @@ -361,6 +361,8 @@ std::string Material_clone::subtitle() const // // // +const int SHOW_LEBAL_TAG = 114; + void Material_parsePerformance::onEnter() { MaterialSystemBaseTest::onEnter(); @@ -378,15 +380,22 @@ void Material_parsePerformance::onEnter() slider->setPosition(Vec2(screenSize.width / 2.0f, screenSize.height / 3.0f)); slider->addEventListener([&](Ref* sender, ui::Slider::EventType type) { - if (type == ui::Slider::EventType::ON_PERCENTAGE_CHANGED) + if (type == ui::Slider::EventType::ON_SLIDEBALL_UP) { ui::Slider* slider = dynamic_cast(sender); float p = slider->getPercent() / 100.0f; + slider->setTouchEnabled(false); CCLOG("Will parsing material %d times", (int)(p * _maxParsingCoumt)); + Label* label = dynamic_cast(this->getChildByTag(SHOW_LEBAL_TAG)); + if(label) + { + label->setString("Testing start!"); + } this->scheduleOnce( - [this, p](float) + [this, p, slider](float) { this->parsingTesting(p * _maxParsingCoumt); + slider->setTouchEnabled(true); }, 1.0, "schedule test parsing"); @@ -395,6 +404,17 @@ void Material_parsePerformance::onEnter() addChild(slider); + auto label = Label::createWithSystemFont("Max parsing count is 10000, which may crash because of high memory comsumption.", "Helvetica", 10); + label->setPosition(Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f - 20)); + addChild(label); + label = Label::createWithSystemFont("Slide to test parsing performance", "Helvetica", 10); + label->setPosition(Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f)); + addChild(label); + + label = Label::createWithSystemFont("", "Helvetica", 10); + label->setPosition(Vec2(screenSize.width / 2.0f, screenSize.height / 2.0f + 20)); + label->setTag(SHOW_LEBAL_TAG); + addChild(label); } @@ -410,8 +430,14 @@ void Material_parsePerformance::parsingTesting(unsigned int count) std::clock_t end = std::clock(); double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC; - - log("Took: %f seconds for parsing material %d times.", elapsed_secs, count); + Label* label = dynamic_cast(this->getChildByTag(SHOW_LEBAL_TAG)); + if(label) + { + std::string str = StringUtils::format("Testing completed! Took: %.3f seconds for parsing material %d times.", elapsed_secs, count); + label->setString(str); + + CCLOG("Took: %.3f seconds for parsing material %d times.", elapsed_secs, count); + } } std::string Material_parsePerformance::subtitle() const From d848da0e7d2e5921bca8caa5ae28619b9958b6e3 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Mon, 10 Aug 2015 16:41:16 +0800 Subject: [PATCH 3/3] change max parsing count to 5000 --- .../cpp-tests/Classes/MaterialSystemTest/MaterialSystemTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cpp-tests/Classes/MaterialSystemTest/MaterialSystemTest.cpp b/tests/cpp-tests/Classes/MaterialSystemTest/MaterialSystemTest.cpp index f9b05d3ac9..c5ccc29eb8 100644 --- a/tests/cpp-tests/Classes/MaterialSystemTest/MaterialSystemTest.cpp +++ b/tests/cpp-tests/Classes/MaterialSystemTest/MaterialSystemTest.cpp @@ -367,7 +367,7 @@ void Material_parsePerformance::onEnter() { MaterialSystemBaseTest::onEnter(); - _maxParsingCoumt = 1e4; + _maxParsingCoumt = 5e3; auto screenSize = Director::getInstance()->getWinSize();