Skip to content

Conversation

@csaftoiu
Copy link
Contributor

This caused an infinite loop when I had a string along the lines of something like " Next ". This is the simple fix.

This caused an infinite loop when I had a string along the lines of something like " Next ". This is the simple fix.
@dingpinglv
Copy link
Contributor

Hi csaftoiu,

Could you please show a example to us?
I have tried to add a LabelTTF ("Prev Next ") in HelloHTML5World, it works well.

Thanks for your feedback.
David

@csaftoiu
Copy link
Contributor Author

Hi David,

Thanks for looking at this.

The case that messed up for me was " Next " - that is, "Next" with a space on each side - where it was too wide for one line. I'm not at a computer now but if that works for you I'll send code that demonstrates the bug.

Thanks,
Claudiu

On Nov 19, 2013, at 9:27 PM, dingpinglv notifications@github.com wrote:

Hi csaftoiu,

Could you please show a example to us?
I have tried to add a LabelTTF ("Prev Next ") in HelloHTML5World, it works well.

Thanks for your feedback.
David


Reply to this email directly or view it on GitHub.

@dingpinglv
Copy link
Contributor

Hi Claudiu,

Could you please send your codes that demonstrates the bug?

Regards
David

@csaftoiu
Copy link
Contributor Author

Ok, got it. Modify 'myApp.js' in HelloHTML5World, replacing:

    this.helloLabel = cc.LabelTTF.create("Hello World", "Arial", 38);

with

    this.helloLabel = cc.LabelTTF.create("Hello ", "Arial", 65);
    this.helloLabel.setDimensions({width: 140, height: 120});

Gist here but that's the only change: https://gist.github.com/csaftoiu/7584738 .

The bug manifests when a string ends with a space and percent is such that startSearch ends up being somewhere in the middle of the string. What happens then is that the first cutoff = strings[i].lastIndexOf(" ", cutoff - 1) returns -1, but then the second cutoff = strings[i].indexOf(" ", startSearch) also returns -1. So var newline = strings[i].substr(cutoff + 1) ends up splicing in the same line over and over again, looping forever.

@dingpinglv
Copy link
Contributor

Thank you, Claudiu.

Got it.

dingpinglv added a commit that referenced this pull request Nov 22, 2013
@dingpinglv dingpinglv merged commit 23b45d5 into cocos2d:develop Nov 22, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants