mirror of
https://github.com/rivo/tview.git
synced 2026-04-26 21:35:54 +03:00
[GH-ISSUE #636] panic in long textview #463
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/tview#463
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @SamWhited on GitHub (Aug 19, 2021).
Original GitHub issue: https://github.com/rivo/tview/issues/636
I'm frequently getting the following (trimmed to relevant parts) panic starting in the textview's draw function at line 1017:
EDIT: actually, it appears to happen when I write a lot of text to the text view regardless of whether I'm scrolling. I'm normally at the top of the text view around position 0, then clearing it, then writing a bunch of new things.
@rivo commented on GitHub (Sep 12, 2021):
Please see https://github.com/rivo/tview/wiki/Concurrency. Most of the functions are not thread-safe. You need to take care of that yourself. (The
Write()function is an exception and I'm not sure if, for consistency reasons, it should've been like the other functions.)@SamWhited commented on GitHub (Sep 12, 2021):
This is all happening synchronously and there should be no race possible here.
EDIT: unless something else is triggering a redraw maybe? I don't think I can reasonably control when redraws happen though, nor can I wrap them in a mutex or anything so I'm not sure what to do if that were the culprit.
@rivo commented on GitHub (Sep 12, 2021):
I don't see your code so it's hard to say. Do you write to the
TextViewusing theio.Writerinterface, callingClear()periodically? And other parts of the program could cause a non-main-thread redraw. Is this a correct assumption?@SamWhited commented on GitHub (Sep 12, 2021):
I think so, I haven't managed to get this into an easily reproducible form, and it's been long enough that I don't really remember what was happening now. It is possible (though unlikely, I think?) that other areas of the code could be calling
app.Redraw()which could be trickling down to this.I'm not really calling Clear periodically, just calling Clear then writing some new text with the writer interface.
@SamWhited commented on GitHub (Sep 17, 2021):
I have tested this, I still get the panic even with locking around the scrolling. I am also certain that nothing is being cleared during the scroll (it is possible that it is being redrawn though).
@rivo commented on GitHub (Sep 23, 2021):
Responding to https://github.com/rivo/tview/pull/641#issuecomment-925438772 here: This is actually what I would like to suggest. In fact, if it weren't for backwards compatibility, I'd probably even remove the lock from the
Write()function and leave everything up to the user.When I implemented this, I was under the impression that implementing the
io.Writerinterface required thread safety so I introduced a mutex. Now it's a bit inconsistent, leading to the confusion outlined in this issue. That's my bad.But removing the lock completely might break existing implementations. I'm very reluctant to do this.
@SamWhited commented on GitHub (Sep 23, 2021):
As much as it clutters the API, I wonder if for backwards compatibility purposes we could use two constructors for this? eg. the existing
NewTextViewwould continue to work as sis, butNewTextViewUnsafeor something would create one with an internal property set that skips over the locking?EDIT: I have a better idea (I think); I will flush it out and then open a PR to suggest it if it works.
@SamWhited commented on GitHub (Oct 22, 2021):
Closing as this specific issue is "fixed" in so far as I know why it's happening and can work around it (I think). Please consider #652 as a follow up that would remove the need for my hacky work arounds. Thanks!