fix: fixed race condition crashes in Chart and Stack widgets (#2944)

Ensure data mutations from background readers are dispatched to the main thread to prevent conflicts with drawing logic (which runs on main thread). This resolves SIGTRAP and SIGABRT crashes observed during extended runtime.
This commit is contained in:
Andy Chong
2026-02-02 00:39:00 +08:00
committed by GitHub
parent 9f7b5303e0
commit a69627f135
4 changed files with 43 additions and 37 deletions

View File

@@ -226,24 +226,24 @@ public class StackWidget: WidgetWrapper {
}
public func setValues(_ values: [Stack_t]) {
var tableNeedsToBeUpdated: Bool = false
values.forEach { (p: Stack_t) in
if let idx = self.values.firstIndex(where: { $0.key == p.key }) {
self.values[idx].value = p.value
return
}
tableNeedsToBeUpdated = true
self.values.append(p)
}
let diff = self.values.filter({ v in values.contains(where: { $0.key == v.key }) })
if diff.count != self.values.count {
tableNeedsToBeUpdated = true
}
self.values = diff.sorted(by: { $0.index < $1.index })
DispatchQueue.main.async(execute: {
var tableNeedsToBeUpdated: Bool = false
values.forEach { (p: Stack_t) in
if let idx = self.values.firstIndex(where: { $0.key == p.key }) {
self.values[idx].value = p.value
return
}
tableNeedsToBeUpdated = true
self.values.append(p)
}
let diff = self.values.filter({ v in values.contains(where: { $0.key == v.key }) })
if diff.count != self.values.count {
tableNeedsToBeUpdated = true
}
self.values = diff.sorted(by: { $0.index < $1.index })
if tableNeedsToBeUpdated {
self.orderTableView.update()
}