Skip to content

Thread safe issues about PathFigureCollectionConverter #11321

@lindexi

Description

@lindexi

Description

It will thow some exceptions when we use PathFigureCollectionConverter to parse the string to PathFigureCollection with multi-thread.

Steps to Reproduce

  1. Add the path string.
  2. Parse the path string by PathFigureCollectionConverter with multi-thread.

The repor code:

        var pathFigureCollectionConverter = new PathFigureCollectionConverter();
        var pathString1 =
            "M320 96a64 64 0 0 0-64 64V896a64 64 0 0 0 64 64h384a64 64 0 0 0 64-64V160a64 64 0 0 0-64-64H320z m384 64V896H320V160h384zM128 256v576h64V256H128zM832 256v576h64V256h-64z";
        var pathString2 =
            "M230.08 738.56l58.816 58.88L574.336 512l-285.44-285.44-58.88 58.88L456.704 512l-226.56 226.56z m487.04 29.44V256h-83.2v512h83.2z";

        _ = pathFigureCollectionConverter.ConvertFrom(pathString1);
        _ = pathFigureCollectionConverter.ConvertFrom(pathString2);

        for (int i = 0; i < 100; i++)
        {
            Task.Run(() =>
            {
                var pathFigureCollection = pathFigureCollectionConverter.ConvertFrom(pathString1);
            });
        }

        for (int i = 0; i < 100; i++)
        {
            Task.Run(() =>
            {
                var pathFigureCollection = pathFigureCollectionConverter.ConvertFrom(pathString2);
            });
        }

Excepted: Work well. The PathFigureCollectionConverter can parse the path string with multi-thread.

Actual: Throw the exception.

Link to public reproduction project repository

https://github.com/lindexi/lindexi_gd/tree/abc3042ddbfc3bd46563119fc88df0463b155c8b/TestPathFigureCollectionConverter

Version with bug

6.0.486

Last version that worked well

Unknown/Other

Affected platforms

iOS, Android, Windows, macOS

Affected platform versions

All.

Did you find any workaround?

Why the PathFigureCollectionConverter not thread safe?

As the code shown, we can find the PathFigureCollectionConverter use some static fields which are not thread safe.

public static void ParseStringToPathFigureCollection(PathFigureCollection pathFigureCollection, string pathString)

And I think we can use the local function to make the PathFigureCollectionConverter thread safe.

Relevant log output

No response

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions