CodeEditApp / CodeEditSourceEditor

A code editor view written in Swift powered by tree-sitter.
https://codeeditapp.github.io/CodeEditSourceEditor/documentation/codeeditsourceeditor
MIT License
514 stars 80 forks source link

🐞 Crash when deleting text #196

Open Wouter01 opened 1 year ago

Wouter01 commented 1 year ago

Description

I deleted a bunch of text from a file (select text + backspace), this caused CodeEdit to crash with the following error:

Thread 57: Fatal error: Duplicate elements of type 'LanguageLayer' were found in a Set.
This usually means either that the type violates Hashable's requirements, or
that members of such a set were mutated after insertion.

at editState.touchedLayers.insert(layer) (line 63 in TreeSitterClient+Edit)

To Reproduce

Open file, delete bunch of text. I'm not sure if it's easily reproducible

Expected Behavior

No crash

Version Information

CodeEditTextView: 0.6.4 macOS: 14.0 beta 1 Xcode: 15.0 beta 1

Additional Context

I attached a video showing the issue. It crashes when I press backspace. I'm not sure, but it seems to only happen when I delete text that is at the start of the file. I haven't seen it happen when I delete text in the middle of the file.

Screenshots

https://github.com/CodeEditApp/CodeEditTextView/assets/62355975/fc958100-a1d2-4e25-8a52-2486583ac385

No response

nicholasss commented 1 year ago

Should there be debugging for beta versions of Xcode and macOS - with future changes and all?

It may not apply to this, due to the error text.

thecoolwinter commented 1 year ago

This should be a simple fix, it just needs a check to the editState if the layer has been marked as touched yet. Someone could maybe look at the hashable implementation on LanguageLayer but it should just be hashing a unique UUID.

thecoolwinter commented 1 year ago

Should there be debugging for beta versions of Xcode and macOS - with future changes and all?

It may not apply to this, due to the error text.

Could you clarify? Do you mean debugging in the editor?

TheNightmanCodeth commented 11 months ago

I'm also experiencing this. It seems like adding a "guard set doesn't contain what we're adding" or similar would fix this

thecoolwinter commented 3 weeks ago

I have a hunch this is fixed with #263. My guess is that two async operations were inserting into the same dictionary and causing a conflict that way. We'll keep it open for a bit and if it doesn't re-appear I'll close this.