Skip to content

Commit 7427b76

Browse files
ibesoragithub-actions[bot]
authored andcommitted
Fixes parameteric colors sometimes loading wrong cached image
GitOrigin-RevId: 3c27f5f1b09f8f39027ad9e7f2275334e453e618
1 parent 6bc06ff commit 7427b76

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

src/render/image_atlas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export function sortImagesMap(
161161
if (a.variant.sx !== b.variant.sx) return a.variant.sx - b.variant.sx;
162162
if (a.variant.sy !== b.variant.sy) return a.variant.sy - b.variant.sy;
163163

164-
return 0;
164+
return a.key.localeCompare(b.key);
165165
});
166166

167167
const sorted = new Map<StringifiedImageVariant, StyleImage>();

test/unit/render/image_atlas.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,26 @@ describe('sortImagesMap', () => {
7575
expect(keys[2]).toEqual(icon2);
7676
});
7777

78+
test('orders variants with same name and scale but different color params deterministically (GLJS #13689)', () => {
79+
// Parametric SVG icons tinted per-feature share the same name and scale but
80+
// differ only in color params. The packing order must not depend on Map
81+
// insertion order, otherwise two atlases with identical content hashes can
82+
// end up with different pixel layouts and getOrCache swaps tinted icons.
83+
const green = new ImageVariant('circle-glow', {params: {fill: new Color(0.13, 0.77, 0.37, 1)}, sx: 0.7, sy: 0.7}).toString();
84+
const gray = new ImageVariant('circle-glow', {params: {fill: new Color(0.5, 0.5, 0.5, 1)}, sx: 0.7, sy: 0.7}).toString();
85+
86+
const greenFirst = sortImagesMap(new Map([
87+
[green, createMockImage('circle-glow')],
88+
[gray, createMockImage('circle-glow')]
89+
]));
90+
const grayFirst = sortImagesMap(new Map([
91+
[gray, createMockImage('circle-glow')],
92+
[green, createMockImage('circle-glow')]
93+
]));
94+
95+
expect(Array.from(greenFirst.keys())).toEqual(Array.from(grayFirst.keys()));
96+
});
97+
7898
test('populates variant cache when provided', () => {
7999
const iconId = createImageVariantId('icon', 1, 1);
80100
const markerId = createImageVariantId('marker', 2, 2);

0 commit comments

Comments
 (0)