CodeEditSourceEditor icon indicating copy to clipboard operation
CodeEditSourceEditor copied to clipboard

🐞 Crash when deleting text

Open Wouter01 opened this issue 2 years ago • 5 comments

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

Wouter01 avatar Jun 14 '23 18:06 Wouter01

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.

nicholasss avatar Jun 20 '23 22:06 nicholasss

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 avatar Jul 11 '23 16:07 thecoolwinter

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?

thecoolwinter avatar Jul 11 '23 16:07 thecoolwinter

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

TheNightmanCodeth avatar Nov 03 '23 20:11 TheNightmanCodeth

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.

thecoolwinter avatar Sep 08 '24 04:09 thecoolwinter

Im getting a similar problem. There is no crash. The code and line numbers become invisible. If I completely change the code by selecting another snippet (and the id changes). The code becomes visible again. Bug only happens when I delete a lot of code at the same time (multiple line). (latest version 0.9.1) I can also create another issue post with more information.

I attached a video of my problem and a picture of my code. Maybe I am using it wrong.

video (bug):

https://github.com/user-attachments/assets/c290073d-f961-428d-a125-e50d2429934a

my code: Image

ignaciojuarez avatar Feb 01 '25 18:02 ignaciojuarez

When I delete a big chunk of code and that code is deleting the first line. All the code becomes invisible. And when it's invisible and I press enter, and then delete. It becomes visible again.

https://github.com/user-attachments/assets/dcdfdf4f-f8b1-48b1-9e7d-684cb582efea

ignaciojuarez avatar Feb 03 '25 04:02 ignaciojuarez

Also I sometimes get this error. When the code/numbers are invisible, and I keep typing or deleting.

Image

ignaciojuarez avatar Feb 03 '25 18:02 ignaciojuarez

I still get the same crashes very often, exactly how @ignaciojuarez is desribing them. For example, after selecting all and hitting delete. Or deleting the first or last line.

nkleemann avatar Feb 03 '25 19:02 nkleemann

@ignaciojuarez @nkleemann That crash you posted looks like what #263 fixes. I'll be making a release tonight that'll include that patch.

The layout bug I'd guess is different. I've been able to reproduce it sporadically, but that screen recording may help.

I'll take another look at it now, it may be an issue with CodeEditTextView rather than this package but I'll update this issue when I have more info.

thecoolwinter avatar Feb 04 '25 03:02 thecoolwinter

Sorry, meant #285

thecoolwinter avatar Feb 04 '25 03:02 thecoolwinter

That release is live (tagged as 0.10.0), @ignaciojuarez does that fix your editing crash?

thecoolwinter avatar Feb 05 '25 03:02 thecoolwinter

Hello @thecoolwinter. Thanks for the help! The problem is still there. Same as the video. ;( I just updated to 0.10.0 and updated to using Attributes for the ThemeEditor.

ignaciojuarez avatar Feb 05 '25 17:02 ignaciojuarez

Are you not able to replicate it @thecoolwinter?

Maybe I im using the call incorrectly. I get multiple prints: "TreeSitterClient setting up with language: swift" Every time I delete or type.

I am also using ".id(snippet.id)". I have not found another way to change the snippet/code reference.

Image Image

ignaciojuarez avatar Feb 28 '25 18:02 ignaciojuarez

I am having a hard time replicating it, but the issue you mentioned strikes me as a problem with CodeEditTextView, not CodeEditSourceEditor. Usually when text is disappearing like that, it indicates that a bug has occurred while updating the internal text layout structures.

thecoolwinter avatar Apr 08 '25 18:04 thecoolwinter

I've found a way to replicate it, it looks like the internal layout storage is getting corrupted. I'll report more as I find more.

thecoolwinter avatar Apr 14 '25 15:04 thecoolwinter

I've now found a fix and have a reproducible test case. I'll merge it into the text view package. I'm also going to close this issue, since it's gotten a little off track from the original issue.

thecoolwinter avatar Apr 14 '25 17:04 thecoolwinter

Hello @thecoolwinter. I am in version 12.0. And Im still encountering this issue. I have not found a way to fix this.

ignaciojuarez avatar Apr 29 '25 18:04 ignaciojuarez