RhenaudTheLukark / CreateYourFrisk

Rhenaud The Lukark's Unitale fork
GNU General Public License v3.0
132 stars 56 forks source link

Infinite Loop: autolinebreak + encountertext/BattleDialog with certain length #65

Closed Eir-nya closed 4 years ago

Eir-nya commented 4 years ago

Describe the bug An infinite loop can occur if autolinebreak is set to true and text entered into encountertext or BattleDialog is long enough.

To Reproduce Steps to reproduce the behavior:

  1. Copy or edit the Encounter Skeleton.
  2. Paste in this code in EncounterStarting:
    autolinebreak = true
    encountertext = "wowaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
  3. Start the mod in CYF.
  4. Observe the executable instantly freezing in an infinite loop.

Expected behavior I expected the line to be split when the letters would have reached the edge of the battle box, as is what happens if the string is much longer.

Setup (please complete the following information):

Eir-nya commented 4 years ago

Further findings: The loop happens because of code on lines 554-568 of TextManager.cs. The infinite loop only happens if, after moving a word to a new line, the new width of the text manager is still > the width limit of the text manager. More simply: You can reproduce the infinite loop if you have just one really really long word and CYF decides not to split it up.

Eir-nya commented 4 years ago

^ the above commit fixes the infinite loop. HOWEVER, it is not absolutely perfect.

Continue testing with these lines:

encountertext = "wowaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" -- fixed line that would have caused an inf loop before
encountertext = "wowaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" -- this line has a different result somehow and I need to find out why
Eir-nya commented 4 years ago

let me explain quickly:

right now, if my new code activates with the example I provided, the encounter text will touch the EXACT inner edge of the arena, because it is EXACTLY 530 px which is also the limit value for the encounter text.

however, if you have text that's long enough that it doesn't activate my new code (second line in prev comment), the single character just before the inner right edge of the box will get moved down as well.

one thing I can do is make my code move down an extra letter so it behaves and looks the same - however, that's not good. if the extra character to be moved down happens to be really long, this would be actually quite noticeable. I'm hereby declaring the extra character being moved down as a bug, which I am promptly going to try to fix. I may also talk to Rhen tomorrow about reducing the limit value for encounter text and battle dialog so that letters can't be EXACTLY right up against the inner edge of the arena.