Skip to content

IME Support - Solution to long strings being truncated results in SDL_Event breaking change #5363

@zreedy

Description

@zreedy

Hello,

We have been busy fixing various issues with IME support on the Windows platform in our fork. One of the issues is related to "long" strings being truncated. In some IMEs (particularly Chinese IMEs) it is common for the whole RESULTSTRING to be typed out in the IME and then sent wholesale to the client. Currently there are only 32 bytes available for text in SDL_TextInputEvent and SDL_TextEditingEvent. Because of this any sentence written that's larger than 16 characters is truncated. This makes any practical usage of these IMEs impossible for most of out Chinese and Japanese users.

Our solution so far has been to replace the char[32] buffer with a char* heap allocated buffer. This is a breaking change and in following the (apparent) standard set forward in SDL_DropEvent moved the responsibility of freeing this buffer to the consumer. This works in our current builds and we haven't noticed any impact on performance or memory metric.

However, I suspect that this breaking change will not be accepted upstream. I'm also unhappy with the idea of heap allocating a 2 byte buffer for the most common case which is SDL_TextInputEvent being issued for each key pressed on a keyboard without an IME active.

Brainstorming some solutions I can see any of the following being viable:

  • SDL_TextInputEvent (only) gets a union for a 28 byte text buffer, and a char* pointer. With an additional flag for which is used. If the char* is used then it's the responsibility of the consumer to free the buffer. Otherwise current behavior is retained. I believe this approach will be the most backwards compatible approach.
  • SDL allocates an internal heap buffer and the user must copy the text if into their memory space if they need to manipulate it. This will mean that we can simply expand the buffer as needed and avoid allocations per keystroke. This is a slight breaking change since anyone currently relying on the 32 byte buffer being mutable will see this break.

This is a serious issue that must be considered and needs to be fixed for our users. We would like to contribute our changes back up stream so we're hoping to have a discussion on what is an acceptable change here so that the PR will be accepted.

You can see our current changes here: https://github.com/YoYoGames/SDL/tree/zreedy-ime-feb22

Cheers,
Zach Reedy

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions