home Forums # Technical Support read write violations? Reply To: read write violations?

#2736
Unknown
Member

main 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 = 863204211

both should be building for 32 bit. x86 system