Closed JzwOnly closed 3 years ago
QMUIConsole 没考虑在子线程里使用的情况,因此出现 crash,下个版本会修复,在此之前你可以将以下代码替换 QMUILog+QMUIConsole.m 里的同名方法临时修复该问题:
+ (void)load {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
OverrideImplementation([QMUILogger class], @selector(printLogWithFile:line:func:logItem:), ^id(__unsafe_unretained Class originClass, SEL originCMD, IMP (^originalIMPProvider)(void)) {
return ^(QMUILogger *selfObject, const char *file, int line, const char *func, QMUILogItem *logItem) {
// call super
void (*originSelectorIMP)(id, SEL, const char *, int, const char *, QMUILogItem *);
originSelectorIMP = (void (*)(id, SEL, const char *, int, const char *, QMUILogItem *))originalIMPProvider();
originSelectorIMP(selfObject, originCMD, file, line, func, logItem);
if (!QMUICMIActivated || !ShouldPrintQMUIWarnLogToConsole) return;
if (!logItem.enabled) return;
if (logItem.level != QMUILogLevelWarn) return;
void (^block)(void) = ^void(void) {
NSString *funcString = [NSString stringWithFormat:@"%s", func];
NSString *defaultString = [NSString stringWithFormat:@"%@:%@ | %@", funcString, @(line), logItem];
[QMUIConsole logWithLevel:logItem.levelDisplayString name:logItem.name logString:defaultString];
};
if (!NSThread.currentThread.isMainThread) {
dispatch_async(dispatch_get_main_queue(), ^{
block();
});
} else {
block();
}
};
});
});
}
Bug 表现 QMUIConsole 在网络请求中,log 偶尔会出现crash 报错信息:!!! _NSLayoutTreeLineFragmentRectForGlyphAtIndex invalid glyph index 879 截图 crash 堆栈截图
如何重现
预期的表现 正常情况下,应该是什么表现
其他信息