mirror of
https://github.com/rivo/tview.git
synced 2026-04-26 21:35:54 +03:00
[GH-ISSUE #85] Crash when calling pages.HidePage #65
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/tview#65
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 @muesli on GitHub (Mar 24, 2018).
Original GitHub issue: https://github.com/rivo/tview/issues/85
I'm experiencing a crash when calling pages.HidePage under certain circumstances. I've written and attached a little example that reproduces the issue, below.
You can trigger the crash by starting the app, pressing F3 and then triggering the
DoneFuncofsearchInput. It will try to hide itself again, which causes a null-pointer access. See the backtrace below.Interestingly, I've used this in pretty much the same fashion before, without running into this issue (see https://github.com/muesli/service-tools/blob/master/service-monitor/logscmd.go), but can't figure out what I'm doing different here. Being a null-pointer access triggered inside tview, it probably can't harm to guard against it regardless.
Backtrace:
Example:
@rivo commented on GitHub (Mar 25, 2018):
Right. I fixed this. Thanks.
@muesli commented on GitHub (Mar 26, 2018):
Thanks and confirmed as fixed! I did notice a related issue though: in the attached example, if you're now successfully hiding the InputField
searchInputagain, the cursor remains sitting there even though the field is correctly hidden. Note: In those cases where it didn't crash before your fix, no remaining cursor is visible.It's a bit difficult to explain with words probably, but if you run the attached example again, just press F3 to show the search, then press ESC to hide it again, and you'll see.
@rivo commented on GitHub (Mar 26, 2018):
Right. I noticed that. The cursor gets removed when the input field loses focus. However, in your example, it never does. (Simply keeping it from being drawn is not the same. There is no notification for a primitive that it was hidden.) In your
SetDoneFunc()callback, you should also callapp.SetFocus()to take the focus away from the input field. If you don't want any other primitive to have focus, you can providenil.I believe this should solve the cursor problem.
Btw, if you set the focus to the
Pagesprimitive instead of the input field directly, thenPageswill pass it on to the input field and, upon hiding it, callapp.SetFocus()on the top-most visible child. This will also lead to the cursor being removed, without you having to callapp.SetFocus()yourself. (Although I'm guessing that for your application, you will probably have to do it at some point anyway unless the input field is its only interactive element.)