getUnicodeString passed the result of PyUnicode_AsUTF8String to
PyBytes_Check without a NULL check. For a str with a lone surrogate
(for example '\udcff') the encoder fails and returns NULL, so passing such
a string to any std::string argument (putText, getTextSize, ...) crashed
the interpreter. It now returns false with the UnicodeEncodeError set,
which the converters already report.
Prepared with AI assistance (Claude Code); I reviewed the change and the verification results.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>