Commit 11a2430
fix: avoid zero-size crash in rememberComposeBitmapDescriptor when used inside Clustering (#963)
* fix: avoid zero-size crash in rememberComposeBitmapDescriptor when used inside Clustering
rememberComposeBitmapDescriptor hosted its throwaway rendering
ComposeView on LocalView.current, which can itself be mid-attach with
no Android layout pass performed on it yet -- notably when this is
called from content composed inside Clustering's clusterItemContent,
whose InvalidatingComposeView is still being attached to its own
parent at that point. That caused measure() to return a 0x0 size and
throw IllegalStateException.
Host the throwaway view on the window's root view instead, which is
already laid out by the time any marker/cluster content is composed.
setParentCompositionContext keeps the composition correctly scoped to
the caller regardless of which Android View it's physically parented
under, so this is safe.
Fixes #694
* refactor(maps-compose): improve Canvas lifecycle and view cleanup in rememberComposeBitmapDescriptor
- Replace the file-level static fakeCanvas singleton with a locally scoped canvasOfHolding to prevent global memory retention and eliminate any risk of cross-call Canvas state/matrix contamination.
- Wrap the measurement, layout, and bitmap drawing phases in a try/finally block to guarantee that the throwaway ComposeView is always detached from the root view hierarchy even if measurement throws an IllegalStateException or rendering fails.
- Rename the Canvas instance to reflect its production role as an unbacked draw target rather than a test double.
---------
Co-authored-by: Dale Hawkins <107309+dkhawk@users.noreply.github.com>1 parent fc37801 commit 11a2430
2 files changed
Lines changed: 67 additions & 13 deletions
File tree
- maps-app/src/androidTest/java/com/google/maps/android/compose
- maps-compose/src/main/java/com/google/maps/android/compose
Lines changed: 35 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
170 | 205 | | |
Lines changed: 32 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
56 | 67 | | |
57 | | - | |
| 68 | + | |
58 | 69 | | |
59 | 70 | | |
60 | 71 | | |
| |||
63 | 74 | | |
64 | 75 | | |
65 | 76 | | |
66 | | - | |
| 77 | + | |
67 | 78 | | |
68 | | - | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
69 | 83 | | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
| 84 | + | |
74 | 85 | | |
75 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
76 | 92 | | |
77 | | - | |
78 | | - | |
| 93 | + | |
79 | 94 | | |
80 | | - | |
| 95 | + | |
| 96 | + | |
81 | 97 | | |
82 | | - | |
| 98 | + | |
83 | 99 | | |
84 | | - | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
85 | 104 | | |
0 commit comments