Skip to content

[TextViewer] bug fix, don't crash on Menu press#14936

Merged
Frenzie merged 2 commits into
koreader:masterfrom
Commodore64user:bug-fix
Feb 5, 2026
Merged

[TextViewer] bug fix, don't crash on Menu press#14936
Frenzie merged 2 commits into
koreader:masterfrom
Commodore64user:bug-fix

Conversation

@Commodore64user

@Commodore64user Commodore64user commented Feb 5, 2026

Copy link
Copy Markdown
Member

bug fix

  • Added a check in onShowMenu() to ensure self.titlebar.left_icon exists before proceeding, preventing errors if the menu is triggered via a key event and the icon is missing.
  • Updated the anchor logic for the menu dialog to only access self.titlebar.left_button if it exists, avoiding potential nil reference errors.
./luajit: frontend/ui/widget/textviewer.lua:770: attempt to index field 'left_button' (a nil value)
stack traceback:
        frontend/ui/widget/textviewer.lua:770: in function 'anchor'
        frontend/ui/widget/container/movablecontainer.lua:128: in function 'ensureAnchor'
        frontend/ui/widget/container/movablecontainer.lua:192: in function 'paintTo'
        frontend/ui/widget/container/centercontainer.lua:31: in function 'paintTo'
        frontend/ui/widget/container/inputcontainer.lua:91: in function 'paintTo'
        frontend/ui/widget/buttondialog.lua:355: in function 'paintTo'
        frontend/ui/uimanager.lua:1258: in function '_repaint'
        frontend/ui/uimanager.lua:1481: in function 'handleInput'
        frontend/ui/uimanager.lua:1581: in function 'run'
        reader.lua:280: in main chunk
        [C]: at 0x010db2f890
make: *** [make/emulator.mk:20: run] Error 1

This change is Reviewable

Comment thread frontend/ui/widget/textviewer.lua Outdated
end

function TextViewer:onShowMenu()
if not self.titlebar.left_icon then return end -- Menu could be triggered with a key event.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose to use the original trigger:

show_menu = true, -- titlebar left icon

Comment thread frontend/ui/widget/textviewer.lua Outdated
buttons = buttons,
anchor = function()
return self.titlebar.left_button.image.dimen
if self.titlebar.left_button then

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One guard is enough, isn't it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol, first i solved this, then realised the menu was being trigerred when it shouldn't. one should do it

@Frenzie Frenzie added this to the 2026.02 milestone Feb 5, 2026
@Frenzie Frenzie merged commit 2cb6f15 into koreader:master Feb 5, 2026
4 checks passed
@Commodore64user Commodore64user deleted the bug-fix branch February 5, 2026 16:52
0xstillb pushed a commit to 0xstillb/koreader-thai that referenced this pull request May 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants