CodeEditApp / CodeEditApp/CodeEditSourceEditor

🐞 Segfault when using asset catalog colors

未关闭
#368 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
bug
主要语言
Swift
星标
719
派生
160
PR 合并指标
30 天内没有已合并 PR

描述

### Description

When creating an EditorTheme from asset catalog colours, a segfault occurs at launch unless the background colour is explicitly cast to sRGB (`NSColor.editorBackground.usingColorSpace(.sRGB)!`).

### To Reproduce

1. Create a new SwiftUI macOS app
2. Add CodeEditSourceEditor as a dependency
3. Add sRGB colors sets to the Asset catalog
4. Use those colors through NSColor to define an EditorTheme (e.g. `NSColor.editorBackground`)
5. Launch the app
6. Something segfaults
7. If you set the background to `NSColor.editorBackground.usingColorSpace(.sRGB)!`, it doesn't

### Expected Behavior

It should be possible to use colours from the asset catalog to define the theme colours without additional hijinks.

### Version Information

CodeEditSourceEditor: 0.15.2
macOS: 15.7.4
Xcode: 26.3

### Additional Context

Minimal reproduction project: [EditorThemeReproduction.zip](https://github.com/user-attachments/files/25798129/EditorThemeReproduction.zip) (`ContentView.swift` contains all the relevant code.)

How I'm creating the theme (the asset catalog is included with the above project):

```swift
extension EditorTheme {
/// Creates an ``EditorTheme`` from colors defined in the asset catalog.
static func fromAssetCatalog() -> Self {
EditorTheme(
text: EditorTheme.Attribute(color: NSColor.editorText),
insertionPoint: NSColor.editorInsertionPoint,
invisibles: EditorTheme.Attribute(color: NSColor.editorInvisibles),

// This segfaults:
background: NSColor.editorBackground,

// This does not, despite the asset catalog color sets being defined as sRGB
// background: NSColor.editorBackground.usingColorSpace(.sRGB)!,

lineHighlight: NSColor.editorLineHighlight,
selection: NSColor.editorSelection,
keywords: EditorTheme.Attribute(
color: NSColor.editorKeywords,
bold: true
),
commands: EditorTheme.Attribute(color: NSColor.editorCommands),
types: EditorTheme.Attribute(color: NSColor.editorTypes),
attributes: EditorTheme.Attribute(color: NSColor.editorAttributes),
variables: EditorTheme.Attribute(color: NSColor.editorVariables),
values: EditorTheme.Attribute(color: NSColor.editorValues),
numbers: EditorTheme.Attribute(color: NSColor.editorNumbers),
strings: EditorTheme.Attribute(color: NSColor.editorStrings),
characters: EditorTheme.Attribute(color: NSColor.editorCharacters),
comments: EditorTheme.Attribute(color: NSColor.editorComments)
)
}
}
```

### Screenshots

Xcode segfault screenshot

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。