Skip to content

Commit 0ec1915

Browse files
committed
StaticImageRenderer: fix mip selection off-by-one, narrow draw lock (#177)
- SelectBitmapForScale: clamp max was _mipChain.Length-1, meaning the finest mip level was never reachable and single-level chains always fell back to the source bitmap; fix to _mipChain.Length - Draw: narrow _mipChainLock to cover only SelectBitmapForScale; moving DrawImage outside the lock avoids holding it across the D2D command recording window - KickOffMipGeneration: discard Task.Run result explicitly (_ =) to make fire-and-forget intent clear to the compiler
1 parent dd2288c commit 0ec1915

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

Src/FlyPhotos/Display/ImageRendering/StaticImageRenderer.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ private void KickOffMipGeneration()
5555
{
5656
_mipGenCts = new CancellationTokenSource();
5757
var token = _mipGenCts.Token;
58-
Task.Run(() => GenerateMipChainAsync(token), token);
58+
_ = Task.Run(() => GenerateMipChainAsync(token), token);
5959
}
6060

6161
private async Task GenerateMipChainAsync(CancellationToken token)
@@ -142,11 +142,10 @@ public void Draw(CanvasDrawingSession session, CanvasViewState viewState, Canvas
142142
}
143143

144144

145+
CanvasBitmap src;
145146
lock (_mipChainLock)
146-
{
147-
var src = SelectBitmapForScale(viewState.Scale);
148-
session.DrawImage(src, viewState.ImageRect, src.Bounds, 1f, quality);
149-
}
147+
src = SelectBitmapForScale(viewState.Scale);
148+
session.DrawImage(src, viewState.ImageRect, src.Bounds, 1f, quality);
150149

151150
}
152151

@@ -161,7 +160,7 @@ private CanvasBitmap SelectBitmapForScale(float scale)
161160

162161
// k = floor(log2(1/scale)): 0 at scale≥1, 1 at scale<0.5, 2 at scale<0.25, …
163162
var k = (int)Math.Floor(Math.Log2(1.0 / scale));
164-
k = Math.Clamp(k, 0, _mipChain.Length - 1);
163+
k = Math.Clamp(k, 0, _mipChain.Length);
165164
return k == 0 ? _sourceBitmap : _mipChain[k - 1];
166165
}
167166

0 commit comments

Comments
 (0)