Cause was Object.to_mesh(), which could cause invalid memory access when calling it on text objects in edit mode.