text.cpp: fixed bug that caused crash in some cases