Bug about CCScale9Sprite in new version

I update the new version this morning, then find there maybe some problem about CCScale9Sprite. The source was packed by TexurePacker. I revert the CCScale9sprite then find it ok. my English is so poor that i can’t describe more detail. add my qq 414600545

Me,too

I revert to old CCScale9Sprite

But i don’t know why @@

I came cross this issue too. Some of my ui, such as CCScale9Sprite and CCControlButton, is breaked.
It seems it failed to scale my images by insets which is set in cocosbuilder;
My images are packed by TexurePacker.

Could you paste some demo to reproduce it?

Minggo Zhang wrote:

Could you paste some demo to reproduce it?

you can create a new layer performed by cocosbuilder. add a ccscale9sprite use resources packed by texturepacker. then you will find the bug

This is due sprites being rotated in TexturePacker.
I fix this in method

CCScale9Sprite::updateWithBatchNode

if ( m_capInsetsInternal.equals(CCRectZero) )
{
// Apply the 3x3 grid format
if (rotated)
{
m_capInsetsInternal = CCRectMake(l+h/3, t+w/3, w/3, h/3); //revert to previous code
}
else
{
m_capInsetsInternal = CCRectMake(w/3, h/3, w/3, h/3);
}
}

Hope this works :slight_smile:

It fix some of my breaked ui, but others are still breaked;

obi zippee wrote:

This is due sprites being rotated in TexturePacker.
I fix this in method
>
CCScale9Sprite::updateWithBatchNode
>

>
if ( m_capInsetsInternal.equals(CCRectZero) )
{
// Apply the 3x3 grid format
if (rotated)
{
m_capInsetsInternal = CCRectMake(l+h/3, t+w/3, w/3, h/3); //revert to previous code
}
else
{
m_capInsetsInternal = CCRectMake(w/3, h/3, w/3, h/3);
}
}
>
Hope this works :slight_smile:

Hi,

I was the one who made changes in CCScale9Sprite recently. I’ve added tests in cocos2d-js-tests for this code :
Before these changes :
(1) Individual sprites were being displayed correctly
(2) Sprites from a Spritesheet were not displayed correctly
(3) Sprites that were stored rotated in a spritesheet were causing a crash when used in CCScale9Sprite
After these changes, (1) and (2) were fixed.

I tested with a spritesheet created in zwoptex.

I will be fixing case (3) so that it displays correctly instead of displaying incorrectly. And also not crashing :slight_smile:
Thanks for your patience.

If somebody would like to help please look at the tests in JS… maybe it will be useful to have a C++ version also?

Ok I have the same problem, too.

I did use CCScale9Sprites from texture packer .plist’s & .pvr’s (haven’t tryed other formats of texture atlases).

Reproducing the bug is easy, just put some code like this in any CCLayer:

Im using 2.0.4

CCSpriteBatchNode *menuSpriteBatchNode= CCSpriteBatchNode::create("GameScene/menuElements.pvr.ccz");
this->addChild(menuSpriteBatchNode);    
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("GameScene/menuElements.plist");

CCScale9Sprite* menuButton= CCScale9Sprite::createWithSpriteFrameName("menuButtonBg.png",CCRectMake(5,5,8,8));

It will crash exactly on making a CCRect at updateWithBatchNode ~~> Top section because the height is negative because of , which in my case reproduces a =~~26 and crash.

Also my sprite atlas is not rotated, so maybe it’s a different problem than yours.

Call Stack:

>   CCRect::CCRect(float x, float y, float width, float height)  Line 131   C++
    CCScale9Sprite::updateWithBatchNode(cocos2d::CCSpriteBatchNode * batchnode, cocos2d::CCRect rect, bool rotated, cocos2d::CCRect capInsets)  Line 277
    CCScale9Sprite::initWithBatchNode(cocos2d::CCSpriteBatchNode * batchnode, cocos2d::CCRect rect, bool rotated, cocos2d::CCRect capInsets)  Line 98
    CCScale9Sprite::initWithSpriteFrame(cocos2d::CCSpriteFrame * spriteFrame, cocos2d::CCRect capInsets)  Line 524 + 0x95 bytes
    CCScale9Sprite::initWithSpriteFrameName(const char * spriteFrameName, cocos2d::CCRect capInsets)  Line 574 + 0x38 bytes
    CCScale9Sprite::createWithSpriteFrameName(const char * spriteFrameName, cocos2d::CCRect capInsets)  Line 586 + 0x42 bytes

If I create without CapInsets it will create without errors, but then again when adding it as child it crashes.

I’m not rotating anything so I wonder why it fails… I’m gonna have some rest and decide if go with the old CCScale9Sprite or try to fix this annoying bug.

I just fixed the case where sprites are stored rotated in a spritesheet. (It is fixed with my test cases and I will submit a pull request on Monday.) I’ll look at these other crashes right after.

Could you post the spritesheet that reproduces the crash?

folec r wrote:

I just fixed the case where sprites are stored rotated in a spritesheet. (It is fixed with my test cases and I will submit a pull request on Monday.) I’ll look at these other crashes right after.
>
Could you post the spritesheet that reproduces the crash?

Sure, in fact it crashes with all my sprite sheet. I have added the .png version of the sheet though I don’t use it since I use the .pvr.

Thanks for your time!

Hey I’m sorry, my problem was that I was adding the CCScale9Sprite to the CCSpriteBatchNode (Like you usually do with CCSprites) but CCScale9Sprite is not a subclass of CCSprite so I have to add it directly to the CCLayer/whatever.

However I’ve found that constructors like:

CCScale9Sprite* buttonBG = CCScale9Sprite::createWithSpriteFrameName("menuButtonTop.png", CCRectMake(5,5,8,8));

Will crash because the image is splitted with the wrong coordinates. So I’ve fixed that and here’s the code:

*Edit -> Removed: it still fails for other frames on the same sprite sheet

After making this changes, the constructor previously mentioned will work properly.

I have submitted a pull request to cocos2d-x to fix CCScale9Sprite when the source texture is in a spritesheet and stored rotated
https://github.com/cocos2d/cocos2d-x/pull/1974

@danadn
Happy that your game is working now!

I looked at your pastebin but could not find line 264. I think it would be best if you could submit your patch as a pull request to cocos2d-x. This way many people will be able to review it.

Thanks.

folec r wrote:

@danadn
Happy that your game is working now!
>
I looked at your pastebin but could not find line 264. I think it would be best if you could submit your patch as a pull request to cocos2d-x. This way many people will be able to review it.
>
Thanks.

Hi folec, I removed my code since I’ve found that it doesn’t work for other frames of the same sprite sheet. Weird. However I’ve downloaded your version of CCScale9Sprite and im getting this error:

 error C2039: 'm_obContentSize' : is not a member of 'cocos2d::extension::CCScale9Sprite'

Maybe should I use the beta version? Right now I’m using 2.0.4

Also, do this work for non-rotated sprite sheets?

danadn _ wrote:

[…]
>
Maybe should I use the beta version? Right now I’m using 2.0.4

My pull request is for applying on cocos2d-x “master”

Is the master version stable enough? I’ll give it a try.

Thanks for your info

Please try it and provide your feedback. The “samples” directory contains the tests. CCScale9Sprite tests are in JavaScript.

I have downloaded the version cocos2d-2.1beta3-x-2.1.1 and I have to say that CCScale9Sprites are loaded just fine from CCSpriteBatchNode.

That said, my sprite sheets aren’t rotated and I’m also using C++.

On the other hand I’ve tryed the Javascript CCScale9Sprite test.

I’ve modified the two S9SpriteTest.js:

cocos2d-2.1beta3-x-2.1.1\Debug.win32\TestJavascriptRes\ExtensionsTest\S9SpriteTest.js
cocos2d-2.1beta3-x-2.1.1\samples\Javascript\Shared\tests\ExtensionsTest

And then I’ve run again the CCScale9Sprite test from the TestJavascript project.

I don’t know if something should’ve change but the sprite sheets I saw are the same

@danadn
Thanks for testing! I have submitted a pull request to cocos2d-x with my fix. It has not been merged yet. https://github.com/cocos2d/cocos2d-x/pull/1974

Once it is merged, it will pass all the JS tests that I have added. (I think it will be merged after the new year holidays.)