home › Forums › # Technical Support › read write violations?
- This topic has 4 replies, 2 voices, and was last updated 5 years, 7 months ago by
Juan Rada-Vilela (admin).
-
AuthorPosts
-
January 18, 2018 at 05:33 #2726
Unknown
MemberHi,
i have been trying to use fuzzylite with the cocos2d game engine but it seems to be causing some problems. I have code that works for both engines separately, however when i try to combine them into one solution i get read write violations. Creating and initialising engine “Engine* engine = new Engine” will create an engine with thousands of blank input and output variables along with other junk variables. cocos will then crash from read write violations from this. Any idea what might be going wrong here? are the engines not compatible or am i perhaps using this wrong?
thanks
January 18, 2018 at 05:46 #2727Unknown
Membernote that after stripping the cocos code back to the base project with no additional code other than the fuzzylite still results in this issue
January 18, 2018 at 19:25 #2728Juan Rada-Vilela (admin)
KeymasterHi,
thank you for your post.
Could you please post a minimal working fuzzylite code, cocos2d code, and the two together? I have not heard of any memory allocation issues, and I have not experienced anything remotely similar to what you mention, either in fuzzylite or QtFuzzyLite.
Also, could you describe your system? OS, compiler, and versions of libraries?
Cheers.
January 22, 2018 at 06:01 #2736Unknown
Membermain scene header
cpp #include "cocos2d.h" #include <list> #include "fl\Headers.h" #include "fuzzyengine.h" using namespace cocos2d; class MainScene : public cocos2d::Scene { public: virtual bool init() override; static cocos2d::Scene* scene(); // a selector callback void menuCloseCallback(Ref* sender); void update(float); CREATE_FUNC(MainScene); private: fuzzyengine* f; }; </blockquote> main scene .cpp <blockquote> #include "MainScene.h" USING_NS_CC; Scene* MainScene::scene() { auto scene = Scene::createWithPhysics(); scene->getPhysicsWorld()->setGravity(Vec2(0, -50)); scene->getPhysicsWorld()->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL); auto layer = MainScene::create(); scene->addChild(layer); return scene; /*return MainScene::create();*/ } // on "init" you need to initialize your instance bool MainScene::init() { ////////////////////////////// // 1. super init first if (!Scene::init()) { return false; } f = new fuzzyengine(); f->init(); return true; } void MainScene::update(float dt) { } void MainScene::menuCloseCallback(Ref* sender) { Director::getInstance()->end(); #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) exit(0); #endif } </blockquote> fuzzy class header <blockquote> #include "fl\Headers.h" using namespace fl; class fuzzyengine { public: void init(); Engine* engine; InputVariable* health; InputVariable* hazzard; InputVariable* time; OutputVariable* mDiff; RuleBlock* ruleBlock; }; </blockquote> fuzzy class .cpp <blockquote> engine = new Engine; engine->setName("Diffciculty"); engine->setDescription("Difficulty calculator"); health = new InputVariable; health->setName("health"); health->setDescription("health gained/lost"); health->setEnabled(true); health->setRange(-100.000, 100.000); health->setLockValueInRange(true); health->addTerm(new Triangle("lost", -1500.00, -50.000, 0.000)); health->addTerm(new Triangle("same", -50.00, 0.000, 50.000)); health->addTerm(new Triangle("gained", 0.00, 50.000, 150.000)); engine->addInputVariable(health); hazzard = new InputVariable; hazzard->setName("hazzard"); hazzard->setDescription("number of hazzards touched"); hazzard->setEnabled(true); hazzard->setRange(-8.000, 0.000); hazzard->setLockValueInRange(true); hazzard->addTerm(new Triangle("few", -2, 0, 2)); hazzard->addTerm(new Triangle("some", 0, 1.5, 3)); hazzard->addTerm(new Triangle("many", 2, 4, 12)); engine->addInputVariable(hazzard); time = new InputVariable; time->setName("time"); time->setDescription("time taken more/less than last"); time->setEnabled(true); time->setRange(-2.00, 2.00); time->setLockValueInRange(true); time->addTerm(new Triangle("quicker", -2, -1, 0)); time->addTerm(new Triangle("same", -1, 0, 1)); time->addTerm(new Triangle("longer", 0, 1, 2)); engine->addInputVariable(time); mDiff = new OutputVariable; mDiff->setName("mDiff"); mDiff->setEnabled(true); mDiff->setRange(2, -2); mDiff->setLockValueInRange(false); mDiff->setAggregation(new AlgebraicSum); mDiff->setDefuzzifier(new Centroid(1000)); mDiff->setDefaultValue(fl::nan); mDiff->setLockPreviousValue(false); mDiff->addTerm(new Triangle("decrease", -2, -1, 0)); mDiff->addTerm(new Triangle("maintain", -1, 0, 1)); mDiff->addTerm(new Triangle("increase", 0, 1, 2)); engine->addOutputVariable(mDiff); ruleBlock = new RuleBlock; ruleBlock->setName("ruleBlock"); ruleBlock->setEnabled(true); ruleBlock->setConjunction(new Minimum); ruleBlock->setDisjunction(new AlgebraicSum); ruleBlock->setImplication(new Minimum); ruleBlock->setActivation(new General); ruleBlock->addRule(Rule::parse("if hazzard is few or health is gained or time is quicker then mDiff is increase", engine)); ruleBlock->addRule(Rule::parse("if hazzard is some or health is same or time is same then mDiff is maintain", engine)); ruleBlock->addRule(Rule::parse("if hazzard is many or health is lost or time is longer then mDiff is decrease", engine)); engine->addRuleBlock(ruleBlock); std::string status; if (not engine->isReady(&status)) throw Exception("[engine error] engine is not ready:\n" + status, FL_AT); </blockquote>
commenting out the f->init(); line will stop the application from crashing. When the engine is initialised the varaibles are:
Name = “”
Description = “”{\X3″
input variables size = 225145190
output variables size = 863204211both should be building for 32 bit. x86 system
January 31, 2018 at 18:29 #2764Juan Rada-Vilela (admin)
KeymasterHi,
what does the
f->init();
do?Cheers.
-
AuthorPosts
- You must be logged in to reply to this topic.