Fix: restore default white background fallback in Button:init (app-wide crash) - #12
Open
jperon wants to merge 1 commit into
Open
Fix: restore default white background fallback in Button:init (app-wide crash)#12jperon wants to merge 1 commit into
jperon wants to merge 1 commit into
Conversation
Button:init() overrides KOReader's shared ui/widget/button module (module caching means this patches the global Button class, affecting every button in the app, not just kochess's own widgets). This copy dropped the fallback that sets background to COLOR_WHITE and computes border/radius when no custom background is provided, leaving self.frame.background nil for any default (uncolored) button created anywhere in KOReader after the chess board has been opened once. That nil background then crashes any button tap application-wide as soon as flash_ui highlighting runs, since Button:_doFeedbackHighlight calls self[1].background:invert() unconditionally.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The problem
button.luadoes:In Lua,
requirecaches modules and always returns the same table. So this redefinition doesn't create a subclass local to kochess: it replaces theinitmethod of theButtonwidget shared by the whole of KOReader. Once the chess board has been opened once in a session, every button in the application (menus, dialogs, etc.) uses this patched version, even outside the plugin.This copy of the original code dropped the fallback to a default white background:
whereas the original
Button:init(frontend/ui/widget/button.lua) computes:As a result, any "default" button (without a custom background) created anywhere else in KOReader after the chess board has been opened ends up with
self.frame.background == nil. On the first tap on such a button, the highlight-feedback animation (flash_ui, enabled by default) crashes the whole app:(
Button:_doFeedbackHighlightcallsself[1].background:invert()without checking thatbackgroundisn'tnil.)Observed reproduction
On an Android e-reader (Bigme B6), after opening a chess game, the app consistently crashed when confirming any dialog (e.g. "Set as default" in the reader's configuration menu), without leaving a usable
crash.log, since this is an uncaught Lua error rather than a native crash.The fix
This PR restores the original fallback logic for
background_color/border_color/radius, so that kochess'sButton:initstays functionally equivalent to KOReader's for buttons without a custom background, while keeping kochess's own specifics (e.g.alphasupport onIconWidget).Longer term, it would probably be better for kochess to avoid monkey-patching the shared
ui/widget/buttonmodule altogether (e.g. by extendingButtonviaButton:extend{}instead of reassigningButton.init), so that any future divergence from upstream KOReader doesn't reintroduce this kind of app-wide regression. I haven't touched that architecture here, to keep the fix minimal and focused on the observed bug.