fix(mac): prevent crash when deleting chat template kwargs#1634
Merged
Conversation
Owner
|
Thanks for the fix. The root cause matches the crash path in #1614: SwiftUI can keep evaluating a row after the backing array has shrunk, and the old index-based binding can then subscript out of bounds. Using the stable entry UUID for lookup keeps the stale-view path safe without changing the saved chat-template kwargs shape. This looks good to me, and I'm going to merge it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1614
Problem
Adding 2+ custom chat kwargs in model advanced settings and then deleting any one causes the app to crash and request a restart.
Root cause
EntryEditorreceived a plainIntindex from theForEachand used it to subscriptvm.chatTemplateEntriesin itsbindinggetter/setter. When a kwarg was removed, the array shrunk but SwiftUI still held views with stale indices — triggering an out-of-bounds access.Fix
EntryEditornow takes a stableUUID(entryID) instead of anIntindex.bindinggetter/setter looks up entries viafirstIndex(where:)on the UUID, which is safe across deletions and reorders.ForEachsimplified to iterate entries directly — no moreenumerated().Changes
apps/omlx-mac/Sources/AppView/Screens/ModelSettingsScreen.swiftEntryEditor:index: Int→entryID: UUIDbinding: UUID-based lookup with safe fallbackForEach:ForEach(Array(...enumerated()))→ForEach(vm.chatTemplateEntries)