How to avoid ChatColor client crashes

Discussion in 'Plugin Development' started by Olof Larsson, Feb 5, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    Olof Larsson

    Hello [​IMG]
    I recently made some research on under which circumstances chat colors causes client crashes.
    I have attached a file with a helper class. Please fill in with feedback and ideas.

    Anyway here is what I found out:

    In minecraft the degree sign is used as a prefix to another char to create a color.
    For example the code for white is "\u00A7f".
    The "\u00A7" is the unicode notation for the degree sign and the "f" means white.

    When does minecraft wrap the text? After how many chars?
    Answer:
    Because the font isn't monospace this differs depending on what you write.
    However we can fit 53 "M" without wrapping and the 54th char would then wrap (be at the beginning of the next line instead)
    As there is no broader char than "M" we can know for sure the minimum line length is 53.
    Note that this means the number of DISPLAYED chars per row is 53.
    A degree sign and the char after will NOT count, as they will not be displayed as chars.

    Good to know: Numbers have the same font width as an M.

    When does the client crash?
    Answer:
    When a row ends with a degree char and optionally another sign after.
    Another way to say the same: When a line ends with either a broken or valid color notation.
    AND
    The client will ALWAYS crash if the sign after the last displayed char in a row is a degree char.
    A goofy way to explatin it:
    For a line with only "M" and numbers, the fiftyfourth "displayed char" musn't be a degree sign.
     

    Attached Files:

  2. Offline

    Plague

    Good work! Pretty deep debugging here, good to know this for my chat color handling.
     
  3. Offline

    mindless728

    for the width i am pretty sure i figured this out once, i think it is 320 character pixels where most characters are 6 wide (this includes the extra pixel space between letters)

    i had code for this, but i can't find it :(
     
  4. Offline

    nossr50

    When I wrote vMinecraft for hMod we had a special word wrap function just to solve this problem. The bug happens when a color code is inserted at the end of a string with nothing following it. Notch should really fix this bug.

    You can find my code in my vChat plugin on github or vMinecraft, just look for "wordwrap" function.
     
  5. Offline

    tommytony

    Thanks for this!
     
  6. Offline

    The_Wrecker

    I encountered this as well. Just used a regex to filter color codes as a work-around till the client gets fixed.
    It is not a new introduced bug. It has been in the client for quite some time now. Really annoying.

    Server won't crash though, it's not affected. I have looked at the decompiled code of notch and it seems he uses a for loop(with a counter). In that loop he increments or substracts the counter. He also uses that counter to do some String operations (substring if I can remember). Because the counter is changed you get an 'out of bounds error' or something like that. It goes outside of the bounds of the current String object.

    Just wanted to mention it.
     
Thread Status:
Not open for further replies.

Share This Page