mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-15 02:25:32 -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;
|
IntPtr windowPort;
|
||||||
public override void Init( IWindowInfo info ) {
|
public override void Init( IWindowInfo info ) {
|
||||||
windowPort = OSX.API.GetWindowPort( info.WinHandle );
|
windowPort = OSX.API.GetWindowPort( info.WinHandle );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Resize( IWindowInfo info ) {
|
public override void Resize( IWindowInfo info ) {
|
||||||
|
@ -6,15 +6,24 @@ namespace OpenTK {
|
|||||||
public static class Debug {
|
public static class Debug {
|
||||||
|
|
||||||
public static void Print( string text ) {
|
public static void Print( string text ) {
|
||||||
|
try {
|
||||||
Console.WriteLine( text );
|
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 ) {
|
public static void Print( object arg ) {
|
||||||
|
try {
|
||||||
Console.WriteLine( arg );
|
Console.WriteLine( arg );
|
||||||
|
} catch( NotSupportedException ) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Print( string text, params object[] args ) {
|
public static void Print( string text, params object[] args ) {
|
||||||
|
try {
|
||||||
Console.WriteLine( text, args );
|
Console.WriteLine( text, args );
|
||||||
|
} catch( NotSupportedException ) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,30 +83,23 @@ namespace OpenTK.Platform.MacOS
|
|||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void Dispose(bool disposing)
|
protected virtual void Dispose(bool disposing) {
|
||||||
{
|
|
||||||
if (mIsDisposed)
|
if (mIsDisposed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Debug.Print("Disposing of CarbonGLNative window.");
|
Debug.Print("Disposing of CarbonGLNative window.");
|
||||||
|
|
||||||
API.DisposeWindow(window.WindowRef);
|
API.DisposeWindow(window.WindowRef);
|
||||||
|
|
||||||
mIsDisposed = true;
|
mIsDisposed = true;
|
||||||
mExists = false;
|
mExists = false;
|
||||||
|
|
||||||
if (disposing)
|
if (disposing) {
|
||||||
{
|
|
||||||
mWindows.Remove(window.WindowRef);
|
mWindows.Remove(window.WindowRef);
|
||||||
|
|
||||||
window.Dispose();
|
|
||||||
window = null;
|
window = null;
|
||||||
}
|
}
|
||||||
DisposeUPP();
|
DisposeUPP();
|
||||||
}
|
}
|
||||||
|
|
||||||
~CarbonGLNative()
|
~CarbonGLNative() {
|
||||||
{
|
|
||||||
Dispose(false);
|
Dispose(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,7 +127,7 @@ namespace OpenTK.Platform.MacOS
|
|||||||
Debug.Print( "Created window " + windowRef );
|
Debug.Print( "Created window " + windowRef );
|
||||||
API.SetWindowTitle(windowRef, title);
|
API.SetWindowTitle(windowRef, title);
|
||||||
|
|
||||||
window = new CarbonWindowInfo(windowRef, true);
|
window = new CarbonWindowInfo(windowRef);
|
||||||
SetLocation(r.X, r.Y);
|
SetLocation(r.X, r.Y);
|
||||||
SetSize(r.Width, r.Height);
|
SetSize(r.Width, r.Height);
|
||||||
mWindows.Add(windowRef, new WeakReference(this));
|
mWindows.Add(windowRef, new WeakReference(this));
|
||||||
@ -769,7 +762,6 @@ namespace OpenTK.Platform.MacOS
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
OnClosed();
|
OnClosed();
|
||||||
|
|
||||||
Dispose();
|
Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,86 +26,32 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace OpenTK.Platform.MacOS
|
namespace OpenTK.Platform.MacOS {
|
||||||
{
|
|
||||||
/// \internal
|
/// \internal
|
||||||
/// <summary>
|
/// <summary> Describes a Carbon window. </summary>
|
||||||
/// Describes a Carbon window.
|
sealed class CarbonWindowInfo : IWindowInfo {
|
||||||
/// </summary>
|
|
||||||
sealed class CarbonWindowInfo : IWindowInfo
|
public IntPtr WindowRef;
|
||||||
{
|
|
||||||
IntPtr windowRef;
|
|
||||||
bool ownHandle = false;
|
|
||||||
bool disposed = false;
|
|
||||||
internal bool goFullScreenHack = false;
|
internal bool goFullScreenHack = false;
|
||||||
internal bool goWindowedHack = false;
|
internal bool goWindowedHack = false;
|
||||||
|
|
||||||
#region Constructors
|
public CarbonWindowInfo(IntPtr windowRef) {
|
||||||
|
WindowRef = windowRef;
|
||||||
/// <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; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Returns a System.String that represents the current window.</summary>
|
/// <summary>Returns a System.String that represents the current window.</summary>
|
||||||
/// <returns>A System.String that represents the current window.</returns>
|
/// <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);
|
return String.Format("MacOS.CarbonWindowInfo: Handle {0}", WindowRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
// TODO: I have no idea if this is right.
|
|
||||||
public IntPtr WinHandle {
|
public IntPtr WinHandle {
|
||||||
get { return windowRef; }
|
get { return WindowRef; }
|
||||||
}
|
}
|
||||||
|
|
||||||
#region IDisposable Members
|
|
||||||
|
|
||||||
public void Dispose() {
|
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