Skip to content

fix(mac): prevent crash when deleting chat template kwargs#1634

Merged
jundot merged 1 commit into
jundot:mainfrom
nethbotheju:fix/chat-kwarg-delete-crash
Jun 3, 2026
Merged

fix(mac): prevent crash when deleting chat template kwargs#1634
jundot merged 1 commit into
jundot:mainfrom
nethbotheju:fix/chat-kwarg-delete-crash

Conversation

@nethbotheju

Copy link
Copy Markdown

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

EntryEditor received a plain Int index from the ForEach and used it to subscript vm.chatTemplateEntries in its binding getter/setter. When a kwarg was removed, the array shrunk but SwiftUI still held views with stale indices — triggering an out-of-bounds access.

Fix

  • EntryEditor now takes a stable UUID (entryID) instead of an Int index.
  • binding getter/setter looks up entries via firstIndex(where:) on the UUID, which is safe across deletions and reorders.
  • ForEach simplified to iterate entries directly — no more enumerated().

Changes

  • apps/omlx-mac/Sources/AppView/Screens/ModelSettingsScreen.swift
  • EntryEditor: index: IntentryID: UUID
  • binding: UUID-based lookup with safe fallback
  • ForEach: ForEach(Array(...enumerated()))ForEach(vm.chatTemplateEntries)

@jundot

jundot commented Jun 3, 2026

Copy link
Copy Markdown
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.

@jundot jundot merged commit d812dab into jundot:main Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Model settings - kwarg

2 participants