mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-14 18:15:28 -04:00
Fix crashing when writing to console on the finalizer thread.
This commit is contained in:
parent
f5d623d820
commit
09faf5c45e
@ -42,7 +42,6 @@ namespace Launcher2 {
|
||||
IntPtr windowPort;
|
||||
public override void Init( IWindowInfo info ) {
|
||||
windowPort = OSX.API.GetWindowPort( info.WinHandle );
|
||||
|
||||
}
|
||||
|
||||
public override void Resize( IWindowInfo info ) {
|
||||
|
@ -6,15 +6,24 @@ namespace OpenTK {
|
||||
public static class Debug {
|
||||
|
||||
public static void Print( string text ) {
|
||||
Console.WriteLine( text );
|
||||
try {
|
||||
Console.WriteLine( text );
|
||||
} catch( NotSupportedException ) {
|
||||
} // raised by Mono sometimes when trying to write to console from the finalizer thread.
|
||||
}
|
||||
|
||||
public static void Print( object arg ) {
|
||||
Console.WriteLine( arg );
|
||||
try {
|
||||
Console.WriteLine( arg );
|
||||
} catch( NotSupportedException ) {
|
||||
}
|
||||
}
|
||||
|
||||
public static void Print( string text, params object[] args ) {
|
||||
Console.WriteLine( text, args );
|
||||
try {
|
||||
Console.WriteLine( text, args );
|
||||
} catch( NotSupportedException ) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -83,30 +83,23 @@ namespace OpenTK.Platform.MacOS
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
protected virtual void Dispose(bool disposing) {
|
||||
if (mIsDisposed)
|
||||
return;
|
||||
|
||||
Debug.Print("Disposing of CarbonGLNative window.");
|
||||
|
||||
API.DisposeWindow(window.WindowRef);
|
||||
|
||||
mIsDisposed = true;
|
||||
mExists = false;
|
||||
|
||||
if (disposing)
|
||||
{
|
||||
if (disposing) {
|
||||
mWindows.Remove(window.WindowRef);
|
||||
|
||||
window.Dispose();
|
||||
window = null;
|
||||
}
|
||||
DisposeUPP();
|
||||
}
|
||||
|
||||
~CarbonGLNative()
|
||||
{
|
||||
~CarbonGLNative() {
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
@ -134,7 +127,7 @@ namespace OpenTK.Platform.MacOS
|
||||
Debug.Print( "Created window " + windowRef );
|
||||
API.SetWindowTitle(windowRef, title);
|
||||
|
||||
window = new CarbonWindowInfo(windowRef, true);
|
||||
window = new CarbonWindowInfo(windowRef);
|
||||
SetLocation(r.X, r.Y);
|
||||
SetSize(r.Width, r.Height);
|
||||
mWindows.Add(windowRef, new WeakReference(this));
|
||||
@ -769,7 +762,6 @@ namespace OpenTK.Platform.MacOS
|
||||
return;
|
||||
|
||||
OnClosed();
|
||||
|
||||
Dispose();
|
||||
}
|
||||
|
||||
|
@ -26,86 +26,32 @@
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenTK.Platform.MacOS
|
||||
{
|
||||
namespace OpenTK.Platform.MacOS {
|
||||
|
||||
/// \internal
|
||||
/// <summary>
|
||||
/// Describes a Carbon window.
|
||||
/// </summary>
|
||||
sealed class CarbonWindowInfo : IWindowInfo
|
||||
{
|
||||
IntPtr windowRef;
|
||||
bool ownHandle = false;
|
||||
bool disposed = false;
|
||||
/// <summary> Describes a Carbon window. </summary>
|
||||
sealed class CarbonWindowInfo : IWindowInfo {
|
||||
|
||||
public IntPtr WindowRef;
|
||||
internal bool goFullScreenHack = false;
|
||||
internal bool goWindowedHack = false;
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="windowRef">A valid Carbon window reference.</param>
|
||||
/// <param name="ownHandle"></param>
|
||||
public CarbonWindowInfo(IntPtr windowRef, bool ownHandle)
|
||||
{
|
||||
this.windowRef = windowRef;
|
||||
this.ownHandle = ownHandle;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Members
|
||||
|
||||
/// <summary>
|
||||
/// Gets the window reference for this instance.
|
||||
/// </summary>
|
||||
internal IntPtr WindowRef
|
||||
{
|
||||
get { return this.windowRef; }
|
||||
public CarbonWindowInfo(IntPtr windowRef) {
|
||||
WindowRef = windowRef;
|
||||
}
|
||||
|
||||
/// <summary>Returns a System.String that represents the current window.</summary>
|
||||
/// <returns>A System.String that represents the current window.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
public override string ToString() {
|
||||
return String.Format("MacOS.CarbonWindowInfo: Handle {0}", WindowRef);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
// TODO: I have no idea if this is right.
|
||||
public IntPtr WinHandle {
|
||||
get { return windowRef; }
|
||||
get { return WindowRef; }
|
||||
}
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
public void Dispose() {
|
||||
Dispose(true);
|
||||
}
|
||||
|
||||
void Dispose(bool disposing) {
|
||||
if (disposed)
|
||||
return;
|
||||
|
||||
if (ownHandle)
|
||||
{
|
||||
Debug.Print("Disposing window {0}.", windowRef);
|
||||
Carbon.API.DisposeWindow(this.windowRef);
|
||||
windowRef = IntPtr.Zero;
|
||||
}
|
||||
|
||||
disposed = true;
|
||||
}
|
||||
|
||||
~CarbonWindowInfo() {
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user