Another features request for further releases - FilledPolygon, WrappedText, Clip Node etc.

Very good work Damiano Mazzella, after pulling a lot of hair trying to make another port work - I downloaded your port and it worked great! Thanks

Damiano Mazzella wrote:

Hi all,
sorry but I’ve been away for the holidays :slight_smile:
>
I attach the new version of PRKit for cocos2d-x 2.0.
>
I hope you find it useful,
D.

Hi all! Im newbie in OpenGL and I find this port very usefull. Ive been use it for about a week, doing some tests whithout problems. But when I use this code in a more complicated project, it throws some random bugs. This minors bug where solved when I initialize these variables in class PRFilledPolygon class:

int areaTrianglePointCount;
CCTexture2D texture;
CCPoint
areaTrianglePoints;
CCPoint textureCoordinates;
PRRatcliffTriangulator
triangulator;

To solve it I made a constructor directly in PRFilledPolygon.h:

PRFilledPolygon() {
areaTrianglePointCount = 0;
texture = NULL;
areaTrianglePoints = NULL;
textureCoordinates = NULL;
triangulator = NULL;
}

You can initialize the variables wherever you want.

Thanks again!
Leonardo…

Hello,sir! i write my code like this:
@

texture = CCTextureCache::sharedTextureCache()>addImage;
void HelloWorld::ccTouchMoved
{
//CCPoint test = pTouch
>getLocationInView();
CCPoint test = pTouch~~>getLocation;
//points.push_back);
vc.push_back);
CCLog;
}
PRFilledPolygon *temp = PRFilledPolygon::filledPolygonWithPointsAndTexture;
@
but the program will crash at
`void PRFilledPolygon::setTexture(CCTexture2D* texture2D) {

CCAssert(texture2D, `“NO TEXTURE SET”);

CC_SAFE_RELEASE;//crash at this line
texture = texture2D;
CC_SAFE_RETAIN;
ccTexParams texParams = { GL_NEAREST, GL_NEAREST, GL_REPEAT, GL_REPEAT };
texture~~>setTexParameters(&texParams);

updateBlendFunc();
calculateTextureCoordinates();

}
@

I don’t know why. can you help me ? i use cocos2d-x 2.0.4 Thank you

qiujie tian wrote:

Hello,sir! i write my code like this:
@
>
texture = CCTextureCache::sharedTextureCache()>addImage;
>
void HelloWorld::ccTouchMoved
{
//CCPoint test = pTouch
>getLocationInView();
CCPoint test = pTouch->getLocation();
//points.push_back(new p2t::Point(test.x, test.y));
vc.push_back(Vector2d(test.x, test.y));
CCLog(“—x=f, --y=f”, test.x, test.y);
}
>
PRFilledPolygon *temp = PRFilledPolygon::filledPolygonWithPointsAndTexture;
>
@
>
but the program will crash at
`void PRFilledPolygon::setTexture(CCTexture2D
texture2D) {

CCAssert(texture2D, `“NO TEXTURE SET”);

CC_SAFE_RELEASE;//crash at this line
texture = texture2D;
CC_SAFE_RETAIN;
ccTexParams texParams = { GL_NEAREST, GL_NEAREST, GL_REPEAT, GL_REPEAT };
texture->setTexParameters;
>
updateBlendFunc;
calculateTextureCoordinates;
>
}
@
>
I don’t know why. can you help me ? i use cocos2d-x 2.0.4 Thank you
I think this error its beacuse the texture, you load in the cache, was released by cocos2dx in some moment before want to use it inPRFilledPolygon::filledPolygonWithPointsAndTexture(vc, texture);. Cocos2dx release it, but you still have a pointer to that texture, the when PRFilledPolygon wants to release some thing already released, it crash.
A possible solution, if it was the case, should be putting**CC_SAFE_RETAIN(texture);* after the line texture = CCTextureCache::sharedTextureCache->addImage; to prevent that cocos2dx dispose. And maybe, somewere, do a CC_SAFE_RELEASE; after you use it or in the destructor of that class. Hope this work.

Leonardo Gomez wrote:

qiujie tian wrote:
> Hello,sir! i write my code like this:
> @
>
> texture = CCTextureCache::sharedTextureCache()>addImage;
>
> void HelloWorld::ccTouchMoved
> {
> //CCPoint test = pTouch
>getLocationInView();
> CCPoint test = pTouch->getLocation();
> //points.push_back(new p2t::Point(test.x, test.y));
> vc.push_back(Vector2d(test.x, test.y));
> CCLog(“—x=f, --y=f”, test.x, test.y);
> }
>
> PRFilledPolygon *temp = PRFilledPolygon::filledPolygonWithPointsAndTexture;
>
> @
>
> but the program will crash at
> `void PRFilledPolygon::setTexture(CCTexture2D
texture2D) {

CCAssert(texture2D, `“NO TEXTURE SET”);

> CC_SAFE_RELEASE;//crash at this line
> texture = texture2D;
> CC_SAFE_RETAIN;
> ccTexParams texParams = { GL_NEAREST, GL_NEAREST, GL_REPEAT, GL_REPEAT };
> texture->setTexParameters;
>
> updateBlendFunc;
> calculateTextureCoordinates;
>
> }
> @
>
> I don’t know why. can you help me ? i use cocos2d-x 2.0.4 Thank you
>
I think this error its beacuse the texture, you load in the cache, was released by cocos2dx in some moment before want to use it inPRFilledPolygon::filledPolygonWithPointsAndTexture(vc, texture);. Cocos2dx release it, but you still have a pointer to that texture, the when PRFilledPolygon wants to release some thing already released, it crash.
>
A possible solution, if it was the case, should be putting**CC_SAFE_RETAIN(texture);* after the line texture = CCTextureCache::sharedTextureCache->addImage; to prevent that cocos2dx dispose. And maybe, somewere, do a CC_SAFE_RELEASE; after you use it or in the destructor of that class. Hope this work.

Hello,sir. thank you for your reply. but it also crash at that line , i write this:
texture = CCTextureCache::sharedTextureCache()->addImage("HelloWorld.png"); CC_SAFE_RETAIN(texture);

please help me

can you give me your code …….you said you use it smoothly. thank you

Thank you for share. it work normal now . i add some code:
PRFilledPolygon()
{
texture = NULL;
areaTrianglePoints = NULL;
textureCoordinates = NULL;
triangulator = NULL;
}

haha

qiujie tian wrote:

can you give me your code …….you said you use it smoothly. thank you

My code its exactly the same as the posted here by Damiano Mazzella, except for the fix that I posted, tho one that initialize the variables. Every thing works great. Ive been use it for two month without any problem. I think I get confused and doesnt understand right your error, but using retain and release is something to care about.

Leonardo Gomez wrote:

qiujie tian wrote:
> can you give me your code …….you said you use it smoothly. thank you
>
My code its exactly the same as the posted here by Damiano Mazzella, except for the fix that I posted, tho one that initialize the variables. Every thing works great. Ive been use it for two month without any problem. I think I get confused and doesnt understand right your error, but using retain and release is something to care about.

Hello, sir. i want to save the lastest texture, how can i do ?

qiujie tian wrote:

Leonardo Gomez wrote:
> qiujie tian wrote:
> > can you give me your code …….you said you use it smoothly. thank you
>
> My code its exactly the same as the posted here by Damiano Mazzella, except for the fix that I posted, tho one that initialize the variables. Every thing works great. Ive been use it for two month without any problem. I think I get confused and doesnt understand right your error, but using retain and release is something to care about.
>
Hello, sir. i want to save the lastest texture, how can i do ?

Hi qiujie tian,

if you want to save in a file you could use CCRenderTexture.

bool saveToFile (const char *name, tCCImageFormat format)
saves the texture into a file.

Regards,

D.

Hi all, I just created a repository on github, you can find it at this link: git://github.com/dmazzella/cocos2d-x-PRKit.git

:slight_smile:

1 Like