@@ -353,6 +353,9 @@ func FillPath(dst *ebiten.Image, path *Path, fillOptions *FillOptions, drawPathO
353353 defer theFillPathM .Unlock ()
354354
355355 // Remove the previous registered callbacks.
356+ bounds := dst .Bounds ()
357+ // Get the original image if dst is a sub-image to integrate the callbacks.
358+ dst = originalImage (dst )
356359 if token , ok := theCallbackTokens [dst ]; ok {
357360 removeUsageCallback (dst , token )
358361 }
@@ -369,13 +372,17 @@ func FillPath(dst *ebiten.Image, path *Path, fillOptions *FillOptions, drawPathO
369372 s .antialias = drawPathOptions .AntiAlias
370373 s .blend = drawPathOptions .Blend
371374 s .fillRule = fillOptions .FillRule
372- s .addPath (path , drawPathOptions .ColorScale )
375+ s .addPath (path , bounds , drawPathOptions .ColorScale )
373376
374377 // Use an independent callback function to avoid unexpected captures.
375378 theCallbackTokens [dst ] = addUsageCallback (dst , fillPathCallback )
376379}
377380
378381func fillPathCallback (dst * ebiten.Image ) {
382+ if originalImage (dst ) != dst {
383+ panic ("vector: dst must be the original image" )
384+ }
385+
379386 theFillPathM .Lock ()
380387 defer theFillPathM .Unlock ()
381388
@@ -404,6 +411,9 @@ func StrokePath(dst *ebiten.Image, path *Path, strokeOptions *StrokeOptions, dra
404411 FillPath (dst , & stroke , nil , drawPathOptions )
405412}
406413
414+ //go:linkname originalImage github.com/hajimehoshi/ebiten/v2.originalImage
415+ func originalImage (img * ebiten.Image ) * ebiten.Image
416+
407417//go:linkname addUsageCallback github.com/hajimehoshi/ebiten/v2.addUsageCallback
408418func addUsageCallback (img * ebiten.Image , fn func (img * ebiten.Image )) int64
409419
0 commit comments