MyreMylar / pygame_gui

A GUI system for pygame.
MIT License
698 stars 83 forks source link

sending new line character to UITextEntryLine via set_text crashes TextBoxLayoutRow (TypeError: 'NoneType' object is not subscriptable) #273

Closed wadsworj closed 2 years ago

wadsworj commented 2 years ago

Describe the bug When I create a UITextEntryLine and then send it a newline character via set_text pygame_gui crashes

To Reproduce Steps to reproduce the behaviour:

  1. create UITextEntryLine
  2. call 'set_text' method on newly created UITextEntryLine
  3. when shown pygame_gui will crash

Expected behaviour I expect this to not crash. Not sure if we want to show the '\n' or show nothing at all for that character, but I don't want it to crash.

Stack Trace

  File "C:\Users\James\AppData\Local\Programs\Python\Python310\lib\site-packages\pygame_gui\elements\ui_text_entry_line.py", line 267, in set_text
    self.drawable_shape.text_box_layout.set_cursor_position(self.edit_position)
  File "C:\Users\James\AppData\Local\Programs\Python\Python310\lib\site-packages\pygame_gui\core\text\text_box_layout.py", line 538, in set_cursor_position
    row.set_cursor_position(cursor_pos - letter_acc)
  File "C:\Users\James\AppData\Local\Programs\Python\Python310\lib\site-packages\pygame_gui\core\text\text_box_layout_row.py", line 391, in set_cursor_position
    cursor_draw_width += sum([char_metric[4]
  File "C:\Users\James\AppData\Local\Programs\Python\Python310\lib\site-packages\pygame_gui\core\text\text_box_layout_row.py", line 391, in <listcomp>
    cursor_draw_width += sum([char_metric[4]
TypeError: 'NoneType' object is not subscriptable

Platform and software (please complete the following information):

Additional context The offending code:

                cursor_draw_width += sum([char_metric[4]
                                          for char_metric
                                          in chunk.font.get_metrics(chunk.text[:chunk_letter_pos])])

text_box_layout_row.py: 391

wadsworj commented 2 years ago

if possible I'd like to take a crack at fixing this myself

MyreMylar commented 2 years ago

Sure, give it a try

On Wed, 8 Jun 2022, 16:08 James Wadsworth, @.***> wrote:

if possible I'd like to take a crack at fixing this myself

— Reply to this email directly, view it on GitHub https://github.com/MyreMylar/pygame_gui/issues/273#issuecomment-1150046119, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADGDGGU4KKY7G5FS5MZPPG3VOCZOFANCNFSM5YG4NDHQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

wadsworj commented 2 years ago

fixed in pull request #274