poupou's picture

missing finalizer in GraphicContext

Project:The Open Toolkit library
Version:1.1-2014-01-02
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed
Description

The type GraphicContext does not have a finalizer.

This means that only the GraphicContext instance that are "manually" disposed get removed from the `available_contexts` dictionary. IOW the instances that are freed by the Garbage Collector are never removed.

This means it's possible to get collision when a native contextis reused (same IntPtr key value) which throws unexpected exceptions to the application.

A test case showing this is available inside: https://bugzilla.xamarin.com/show_bug.cgi?id=12212

Note: I do not think the `manual` parameter in Dispose is correct, i.e. implementation should be disposed is not external.

My patch for Xamarin.iOS is:

diff --git a/Source/OpenTK/Graphics/GraphicsContext.cs b/Source/OpenTK/Graphics/GraphicsContext.cs
index c1ff637..b2cfdab 100644
--- a/Source/OpenTK/Graphics/GraphicsContext.cs
+++ b/Source/OpenTK/Graphics/GraphicsContext.cs
@@ -529,7 +529,12 @@ namespace OpenTK.Graphics
GC.SuppressFinalize(this);
}

- void Dispose(bool manual)
+ ~GraphicsContext ()
+ {
+ Dispose (false);
+ }
+
+ void Dispose (bool disposing)
{
if (!IsDisposed)
{
@@ -539,7 +544,7 @@ namespace OpenTK.Graphics
available_contexts.Remove((this as IGraphicsContextInternal).Context);
}

- if (manual && !IsExternal)
+ if (!IsExternal)
{
if (implementation != null)
implementation.Dispose();


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

#1

Version:1.x-dev» 1.1-2014-01-02
Status:open» closed

Closing issues fixed in 1.1 beta4.