TextBox2 crashes when Korean input exceed certain length

In the latest textbox response, (v2021.1.4) Korean Input works flawlessly.
However, after the length of string input increases, it crashes like below.

"/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/psychopy/visual/textbox2/textbox2.py", line 956, in draw
    gl.glVertex2f(self.vertices[0, 0], self.vertices[0, 1])
  File "/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/psychopy/visual/textbox2/textbox2.py", line 1057, in vertices
    chrVerts = textbox.vertices[range(ii * 4, ii * 4 + 4)]
IndexError: index 28 is out of bounds for axis 0 with size 24

OS (e.g. Win10): MacOS 10.15.7
PsychoPy version (e.g. 1.84.x): v2021.1.4
Standard Standalone? (y/n) If not then what?:y
What are you trying to achieve?:
Proper input of Korean string

My gut feeling is that this is because of compound characters - each character is given 4 vertices to define its position, but if multiple characters become one compound character as they’re being inputted I can see that leading to indexing errors… Thanks for bringing this up, I’ll investigate further to see if my hunch is right

Could you give an example of a string you were typing when it crashed? Inputting random characters from the Hangul Jamo unicode block doesn’t replicate this error

Possibly, the bug exists in MacOS only.
Would you kindly let me know where did you tested in Windows or Mac OS?

I run Windows 10, so I’ll pass my testing experiment to another member of the team to try on Mac

Oh, Thanks @TParsons, I should mention that the issue is (and was) MacOS specific, at very first time.
I am sorry.
Due to different way dealing with ‘compound characters’ in Windows and MacOS, textbox of PsychoPy has not been function with MacOS+Korean combination for a long time, as mentioned below.

Now the issue seems resolved, but unexpected crash after several random key inputs.
(I tried to figure out the rule, but couldn’t find.)

@sotiri has checked this and can confirm the test experiment I made crashes on Mac and only on Mac, so now we at least have something we can use to investigate.

I’ve added a test to our test suite for this, so once it’s fixed we can pull the test in and catch this in future TEST: Add test for textbox typing, not just setting text by TEParsons · Pull Request #3843 · psychopy/psychopy · GitHub

1 Like

What’s going on here is that TextBox caches images of the necessary characters in a texture on the graphics card. That’s super fast to render the text, which is what we need in order to change and redraw within a screen refresh. The problem is that for character sets that have a very large number of characters it’s running out of space. @cnsla for now you can change the size of the atlas texture (currently 2048 but try doubling that) as here:
psychopy/fontmanager.py at e45520f446697d5b5fad035fa0e4e50088ffa535 · psychopy/psychopy · GitHub

We’d like to work out how to auto-grow that texture (but that’s rather complicated) so the alternative for now is probably just to expose the texture size as an option in Builder so that those using large-scale character sets can manually alter their texture size. We’ll try and have a fix like that for 2022.1.0

@jon
Thanks for checking. When I test the hack with 2021.1.4, below error happened.
I guess some more lines with rendered vector size is related.

"/Applications/PsychoPy_2021_1_4.app/Contents/Resources/lib/python3.6/psychopy/visual/textbox2/textbox2.py", line 956, in draw
    gl.glVertex2f(self.vertices[0, 0], self.vertices[0, 1])
  File "/Applications/PsychoPy_2021_1_4.app/Contents/Resources/lib/python3.6/psychopy/visual/textbox2/textbox2.py", line 1057, in vertices
    chrVerts = textbox.vertices[range(ii * 4, ii * 4 + 4)]
IndexError: index 16 is out of bounds for axis 0 with size 12
##### Experiment ended. #####

Also, same error happens even after the code is changed the code bigger

[range(ii * 4, ii * 4 + 8)] or [range(ii * 4, ii * 4 + 48)]