Skip to content

fix(widget): clamp stale saved dims and survive OOM in chart rasterizer#39

Merged
timbortnik merged 1 commit into
mainfrom
fix/widget-oom-unclamped-dims
Jun 29, 2026
Merged

fix(widget): clamp stale saved dims and survive OOM in chart rasterizer#39
timbortnik merged 1 commit into
mainfrom
fix/widget-oom-unclamped-dims

Conversation

@timbortnik

Copy link
Copy Markdown
Owner

Problem

A second, distinct path to the same "widget permanently stuck, new widget works, app fails to
update on tap" report — separate from the budget-rejection retry in #38.

When onUpdate is triggered by a self-broadcast, the launcher options can come back as 0, so it
falls back to the saved per-id dimensions (widget_<id>_width_px/height_px) — and uses them
unclamped:

val savedDims = getWidgetDimensions(widgetData, appWidgetId)
if (savedDims != null) { widthPx = savedDims.first; heightPx = savedDims.second }  // no clamp

An install upgraded from a build that stored the raw launcher size can carry an over-budget value
here. Bitmap.createBitmap then throws OutOfMemoryError — which is an Error, not an Exception — so
it escapes generateChartBitmap's catch (Exception) and crashes the in-process widget receiver on
every update (and the app when it triggers a refresh on tap), freezing that widget until it's
re-created.

This regime is invisible to #38's retry, which only catches Exception (the budget rejection's
IllegalArgumentException). The two are different failure points: #38 = IllegalArgumentException
from updateAppWidget; this = OutOfMemoryError from createBitmap.

Fix

  • Clamp the saved-dims fallback through WidgetUtils.clampChartDimensions, so a stale over-budget
    value can no longer reach createBitmap.
  • Add catch (OutOfMemoryError) to both widget bitmap rasterizers (renderSvgStringToBitmap,
    renderSvgToBitmap) so any unforeseen over-budget allocation degrades to null (placeholder /
    smaller render via fix(widget): recover from launcher bitmap-budget rejection instead of freezing #38's retry) instead of crashing.

Defense in depth: the clamp removes the cause; the OOM catch ensures graceful degradation even if
a large allocation ever slips through.

Verification

  • ./gradlew :app:compileDebugKotlin ✅
  • ./gradlew :app:test ✅
  • ./gradlew :app:lintDebug — no NewApi; only the pre-existing MissingTranslation (app_name) error,
    unrelated to this change.

A second, distinct path to the "widget permanently stuck, new widget works"
symptom: when onUpdate's launcher options come back 0 it falls back to the
saved per-id dimensions (widget_<id>_width_px/height_px) used UNCLAMPED. An
install upgraded from a build that stored the raw launcher size can carry an
over-budget value there; Bitmap.createBitmap then throws OutOfMemoryError —
which is an Error, not an Exception, so it escapes generateChartBitmap's
catch (Exception) and crashes the in-process widget receiver on every update.

- Clamp the saved-dims fallback through WidgetUtils.clampChartDimensions, so a
  stale huge value can no longer reach createBitmap.
- Add a catch (OutOfMemoryError) to both widget bitmap rasterizers
  (renderSvgStringToBitmap, renderSvgToBitmap) so any unforeseen over-budget
  allocation degrades to null (placeholder / smaller render) instead of crashing.

Distinct regime from the budget-rejection retry (other PR): that one is an
IllegalArgumentException from updateAppWidget; this one is an OutOfMemoryError
from createBitmap, which neither the existing catch nor the retry handles.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@timbortnik, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 37 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 49576d5c-9e48-4cbe-8701-a9cd168e4dff

📥 Commits

Reviewing files that changed from the base of the PR and between 63544d6 and 6d8f31f.

📒 Files selected for processing (1)
  • android/app/src/main/kotlin/org/bortnik/meteogram/MeteogramWidgetProvider.kt
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/widget-oom-unclamped-dims

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@timbortnik timbortnik merged commit c73881d into main Jun 29, 2026
6 checks passed
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.

1 participant