Skip to content

Commit

Permalink
Do not dispose platform structs (fix #74)
Browse files Browse the repository at this point in the history
  • Loading branch information
SupinePandora43 committed Sep 8, 2023
1 parent 4d06b37 commit e00ddc5
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 42 deletions.
10 changes: 3 additions & 7 deletions src/UltralightNet/Platform/Clipboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public unsafe struct ULClipboard
#endif
}
}
public interface IClipboard : IDisposable
public interface IClipboard
{
void Clear();
string ReadPlainText();
Expand Down Expand Up @@ -75,12 +75,8 @@ public void Dispose()
foreach (var handle in handles) if (handle.IsAllocated) handle.Free();
}

try { instance.Dispose(); }
finally
{
GC.SuppressFinalize(this);
IsDisposed = true;
}
GC.SuppressFinalize(this);
IsDisposed = true;
}
~Wrapper() => Dispose();
}
Expand Down
10 changes: 3 additions & 7 deletions src/UltralightNet/Platform/Filesystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public unsafe struct ULFileSystem
#endif
}
}
public interface IFileSystem : IDisposable
public interface IFileSystem
{
bool FileExists(string path);
string GetFileMimeType(string path);
Expand Down Expand Up @@ -78,12 +78,8 @@ public void Dispose()
foreach (var handle in handles) if (handle.IsAllocated) handle.Free();
}

try { instance.Dispose(); }
finally
{
GC.SuppressFinalize(this);
IsDisposed = true;
}
GC.SuppressFinalize(this);
IsDisposed = true;
}
~Wrapper() => Dispose();
}
Expand Down
10 changes: 3 additions & 7 deletions src/UltralightNet/Platform/FontLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public unsafe struct ULFontLoader
#endif
}
}
public interface IFontLoader : IDisposable
public interface IFontLoader
{
string GetFallbackFont();
string GetFallbackFontForCharacters(string text, int weight, bool italic);
Expand Down Expand Up @@ -75,12 +75,8 @@ public void Dispose()
foreach (var handle in handles) if (handle.IsAllocated) handle.Free();
}

try { instance.Dispose(); }
finally
{
GC.SuppressFinalize(this);
IsDisposed = true;
}
GC.SuppressFinalize(this);
IsDisposed = true;
}
~Wrapper() => Dispose();
}
Expand Down
10 changes: 3 additions & 7 deletions src/UltralightNet/Platform/GPUDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public unsafe struct ULGPUDriver
}
}

public interface IGPUDriver : IDisposable
public interface IGPUDriver
{
uint NextTextureId();
void CreateTexture(uint textureId, ULBitmap bitmap);
Expand Down Expand Up @@ -149,12 +149,8 @@ public void Dispose()
foreach (var handle in handles) if (handle.IsAllocated) handle.Free();
}

try { instance.Dispose(); }
finally
{
GC.SuppressFinalize(this);
IsDisposed = true;
}
GC.SuppressFinalize(this);
IsDisposed = true;
}
~Wrapper() => Dispose();
}
Expand Down
10 changes: 3 additions & 7 deletions src/UltralightNet/Platform/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public unsafe struct ULLogger
#endif
}
}
public interface ILogger : IDisposable
public interface ILogger
{
void LogMessage(ULLogLevel logLevel, string message);

Expand Down Expand Up @@ -60,12 +60,8 @@ public void Dispose()
if (IsDisposed) return;
if (handle.IsAllocated) handle.Free();

try { instance.Dispose(); }
finally
{
GC.SuppressFinalize(this);
IsDisposed = true;
}
GC.SuppressFinalize(this);
IsDisposed = true;
}
~Wrapper() => Dispose();
}
Expand Down
10 changes: 3 additions & 7 deletions src/UltralightNet/Platform/SurfaceDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public unsafe struct ULSurfaceDefinition
#endif
}
}
public interface ISurfaceDefinition : IDisposable
public interface ISurfaceDefinition
{
nint Create(uint width, uint height);
void Destroy(nint id);
Expand Down Expand Up @@ -100,12 +100,8 @@ public void Dispose()
foreach (var handle in handles) if (handle.IsAllocated) handle.Free();
}

try { instance.Dispose(); }
finally
{
GC.SuppressFinalize(this);
IsDisposed = true;
}
GC.SuppressFinalize(this);
IsDisposed = true;
}
~Wrapper() => Dispose();
}
Expand Down

0 comments on commit e00ddc5

Please sign in to comment.