Hello everyone, I writing after encountering an error that I can not solve. in a few words I have a problems to create a object (created by me) in a HelloWorldScene function. I immediately place the code that causes the error.
header file
Palla.h
#ifndef PALLA2_H
#define PALLA2_H
#include <cocos2d.h>
class Palla : public cocos2d::Sprite
{
public:
Palla();
private:
cocos2d::RepeatForever* Rotola();
};
#endif // PALLA2_H
cpp file Palla.cpp
#include “Palla.h”
USING_NS_CC;
Palla::Palla()
{
Sprite* palla = Sprite::create(“Palla.png”);
palla->runAction(Rotola());
}
RepeatForever* Palla::Rotola()
{
RotateBy* rotazione = RotateBy::create(0.8, 360);
RepeatForever* AzioneInfinita = RepeatForever::create(rotazione);
return AzioneInfinita;
}
HelloWorldScene.h
#ifndef HELLOWORLD_SCENE_H
#define HELLOWORLD_SCENE_H
#include “cocos2d.h”
#include “Palla.h”
class HelloWorld : public cocos2d::Layer
{
public:
// there’s no ‘id’ in cpp, so we recommend returning the class instance pointer
static cocos2d::Scene* createScene();
// Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
virtual bool init();
// a selector callback
void menuCloseCallback(cocos2d::Ref* pSender);
// implement the "static create()" method manually
CREATE_FUNC(HelloWorld);
void aggiungiPalla();
cocos2d::Size winSize;
cocos2d::Point origin;
private:
Palla* palla;
};
#endif // HELLOWORLD_SCENE_H
HelloWorldScene.cpp
#include “HelloWorldScene.h”
#include “Palla.h”
USING_NS_CC;
Scene* HelloWorld::createScene()
{
// ‘scene’ is an autorelease object
auto scene = Scene::create();
// 'layer' is an autorelease object
auto layer = HelloWorld::create();
// add layer as a child to scene
scene->addChild(layer);
// return the scene
return scene;
}
// on “init” you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !Layer::init() )
{
return false;
}
winSize = Director::getInstance()->getVisibleSize();
origin = Director::getInstance()->getVisibleOrigin();
aggiungiPalla();
return true;
}
void HelloWorld::aggiungiPalla()
{
palla = new Palla();
if (!palla){ delete palla; }
palla->Node::setPosition((winSize.width / 2) + origin.x, (winSize.height / 2) + origin.y);
this->addChild(palla);
}
void HelloWorld::menuCloseCallback(Ref* pSender)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
MessageBox(“You pressed the close button. Windows Store Apps do not implement a close button.”,“Alert”);
return;
#endif
Director::getInstance()->end();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
exit(0);
#endif
}
the error is this
An unhandled exception in 0x0100CE91 in test.exe: 0xC0000005: Access violation reading location 0x0000001C.
in this function
GLuint Texture2D::getName() const
{
return _name;
}
I also tried to change the initialization of 'image in the constructor of my object. with
initWithSpriteFrameName
or
Image* palla = NULL;
palla->initWithImageFile(“Palla.png”);
Texture2D* pallaTexture = NULL;
pallaTexture->initWithImage(palla);
initWithTexture(pallaTexture);
but the error is the same…
thanks in advance for the help.
P.S:i use the compiler VISUAL STUDIO 2013.