Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't dispose of GpMetafile if a GpGraphics is using it #671

Closed
wants to merge 1 commit into from

Conversation

lambdageek
Copy link
Member

@lambdageek lambdageek commented Oct 2, 2020

Allow GpGraphics to take ownership of GpMetafile on dispose

The Windows GDI+ allows the metafile instance to be disposed before the graphics instance.

To support that, keep track in the GpGraphics of whether it is responsible for freeing the GpMetafile.

If the graphics instance is deleted first, own_metafile is FALSE and nothing happens.

If the metafile instance is disposed first, set own_metafile to TRUE and don't dispose of the metafile. It will be disposed when the graphics instance is deleted.


Also on Windows GDI+ creating more than one graphics instance for a metafile
instance throws an OutOfMemoryException, so do the same in GdipGetImageGraphicsContext


This is related to dotnet/runtime#37838

@lambdageek
Copy link
Member Author

Looks like on Win32 GDI+, you can dispose of the metadata or the graphics instances in either order. Instead of asserting, I'm working on extending the lifetime of the metadata object until the graphics instance is disposed if the metadata is disposed first.

The Windows GDI+ allows the metafile instance to be disposed before the
graphics instance.

To support that, keep track in the GpGraphics of whether it is responsible for
freeing the GpMetafile.

If the graphics instance is deleted first, own_metafile is FALSE and nothing
happens.

If the metafile instance is disposed first, set own_metafile to TRUE and don't
dispose of the metafile. It will be disposed when the graphics instance is
deleted.

---

Also on Windows GDI+ creating more than one graphics instance for a metafile
instance throws an OutOfMemoryException, so do the same in GdipGetImageGraphicsContext
@lambdageek lambdageek changed the title Track metafile dispose before graphics dispose Don't dispose of GpMetafile if a GpGraphics is using it Oct 7, 2020
Base automatically changed from master to main March 12, 2021 13:26
@lambdageek lambdageek closed this Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant