English isn’t my primary language, so please pardon any possible mistake I might make.
I am trying to use cocos2d::Camera for my game
I’ve done it before, got the idea from
and so I tried to use it again for my new game
but as I try to run it, it throws access violation. getName function from CCTexture2d
GLuint Texture2D::getName() const
{
return _name; //here
}
I think it has to do with initializing the sprite since it is from getName function.
I used initWithFile for initializing the sprite.
ChassisTemplate* ChassisTemplate::initiate(CONTROLTYPE conType, CHASSISTYPE chaType, MANEUVERTYPE manType)
{
ChassisTemplate* chassis = new ChassisTemplate();
const char* sprName;
...
//set property
...
sprName = "Chassis.png";
if (chassis && chassis->initWithFile(sprName))
{
chassis->autorelease();
return chassis;
}
CC_SAFE_DELETE(chassis);
return NULL;
}
and camera part looks like this
camera = Camera::createOrthographic(visibleSize.width, visibleSize.height, 0.0f, 100.0f);
camera->setCameraFlag(CameraFlag::USER1);
camera->setPosition3D(Vec3(halfSize.width, halfSize.height, -1.0f));
camera->lookAt(Vec3(halfSize.width, halfSize.height, 0.0f), Vec3(0.0, 1.0, 0.0));
playLayer->addChild(camera);
playLayer->setCameraMask((unsigned short)CameraFlag::USER1, true);
I also get the same memory access violation if I use CCFollow
am I doing the initialization wrong, or is the problem from somewhere else?
EDIT1: so I commented out the part where I ‘create’ the sprites, camera seems to work
but why? should I NOT use initWithFile with camera?
EDIT2: 0xC0000005: Access violation reading location 0x0000002C.
Rather than class inheriting the Sprite class, I made my class contain Sprite variable, using static create function of sprite class to initialize the sprite.
but it still throws same error.
I also read the value of _name in getName, it goes fine until 2, then it tries to read garbage, thus throwing access violation.
still no clue how to solve this problem.
Please anyone help?