首页 > 解决方案 > CTLineGetStringIndexForPosition 因 bad_alloc 而崩溃

问题描述

我试图在这样的一行中获取文本的位置:

CFIndex Idx = CTLineGetStringIndexForPosition(line, pos);

但是我因以下堆栈跟踪而崩溃。为什么会发生崩溃?

- libc++.1.dylib std::__throw_bad_alloc()
- CoreText std::__1::__split_buffer<TLine::CaretInfo, std::__1::allocator<TLine::CaretInfo>&>::__split_buffer(unsigned long, unsigned long, std::__1::allocator<TLine::CaretInfo>&)
- CoreText void std::__1::vector<TLine::CaretInfo, std::__1::allocator<TLine::CaretInfo> >::__emplace_back_slow_path<TLine::CaretInfo>(TLine::CaretInfo&&)
- CoreText TLine::EnumerateCaretOffsets(std::__1::function<void (double, long, bool, bool*)>) const
- CoreText TLine::PositionToCharIndex(CGPoint) const
- CTLineGetStringIndexForPosition(line, pos);

标签: c++iosobjective-ccore-textcore-foundation

解决方案


推荐阅读