Steps to reproduce the bug
- Add markers with Chinese descriptions to the marker track;
- Export MIDI file;
- Open this MIDI file in Cubase or another DAW to view the markers;
- The Chinese text in the marker description is truncated and appears as garbled characters, or does not display at all, but the English text remains unaffected. For example, “测试 中文标记 1” is truncated to “测试 ?”.
Tips that might be helpful to you
I tried using AI to reverse-engineer this issue, which appears to exist in multiple versions and isn’t limited to MIDI export. Here are the findings:
Technical analysis
-
The
MStringclass stores its payload in two possible encodings, flagged by bit0x40000000, and itslength()returns characters in wide mode but bytes in single-byte mode. -
In the export path, the string is converted from UTF-16 to UTF-8 and both the data pointer and the flag word are re-read afterwards — but the length snapshot in
ebxis not:
; --- Cubase 15.0.40, marker export path ---
0x141C188F3 and ebx, 3FFFFFFFh ; ebx = character count (stale snapshot)
0x141C18912 call sub_1439D2A60 ; ★ UTF-16 → UTF-8 conversion
0x141C18917 mov ecx, [rbp-8] ; ★ re-read: UTF-8 byte count
0x141C1891A mov r8, [rbp-10h] ; ★ re-read: UTF-8 buffer
0x141C18935 mov r9d, ebx ; ✗ NOT re-read → still char count
0x141C1893D call sub_141CF4060 ; PSmfEvent(this, type, data, len, 0)
- The constructor then does what it’s told:
void PSmfEvent(void *this, char type, const void *data, int len) {
*(BYTE *)(this + 0x68) = type;
*(_DWORD*)(this + 0x6C) = len; // 7, should be 19
*(QWORD *)(this + 0x78) = malloc(len);
memcpy(*(void**)(this + 0x78), data, len); // ← truncated here
}
- A classic partial reload elision: the compiler knew the conversion had side effects (hence the
ecx/r8reloads) but didn’t refresh theebxsnapshot.