Skip to content

Undisposed resource problem in the generated codes #582

Description

@HotCakeX

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:

Image

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions