This is part of the generated code
CompositionEffectFactory EffectFactory()
{
var compositeEffect = new CompositeEffect();
compositeEffect.Mode = CanvasComposite.DestinationIn;
compositeEffect.Sources.Add(new CompositionEffectSourceParameter("destination"));
compositeEffect.Sources.Add(new CompositionEffectSourceParameter("source"));
var result = _c.CreateEffectFactory(compositeEffect);
return result;
}
It is not using the using keyword for the CompositeEffect object being created, leaving undisposed resources. GitHub CodeQL scans also confirm this problem:
The correct code would be this:
CompositionEffectFactory EffectFactory()
{
using CompositeEffect compositeEffect = new();
compositeEffect.Mode = CanvasComposite.DestinationIn;
compositeEffect.Sources.Add(new CompositionEffectSourceParameter("destination"));
compositeEffect.Sources.Add(new CompositionEffectSourceParameter("source"));
var result = _c.CreateEffectFactory(compositeEffect);
return result;
}
Explanation
After CreateEffectFactory has created the CompositionEffectFactory, the code does not need the original CompositeEffect instance anymore. Disposing the local CompositeEffect after factory creation does not dispose the CompositionEffectFactory or the CompositionEffectBrush created from it. EffectBrush() creates the factory, creates a brush from it, sets the two source parameters, and returns the brush, so the CompositeEffect lifetime can end inside EffectFactory().
Details
- .NET 10
- Visual Studio latest version
- LottieGen version: 8.2.250604.1
- Command:
LottieGen -Language CSharp -Public -WinUIVersion 3.0 -InputFile Item.json
This is part of the generated code
It is not using the
usingkeyword for theCompositeEffectobject being created, leaving undisposed resources. GitHub CodeQL scans also confirm this problem:The correct code would be this:
Explanation
After
CreateEffectFactoryhas created theCompositionEffectFactory, the code does not need the originalCompositeEffectinstance anymore. Disposing the localCompositeEffectafter factory creation does not dispose theCompositionEffectFactoryor theCompositionEffectBrushcreated from it.EffectBrush()creates the factory, creates a brush from it, sets the two source parameters, and returns the brush, so theCompositeEffectlifetime can end insideEffectFactory().Details
LottieGen -Language CSharp -Public -WinUIVersion 3.0 -InputFile Item.json