mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-12 09:06:55 -04:00
Don't crash when the device is lost, partially addresses #30. Need to conduct more thorough testing to ensure that this works on all graphics cards.
This commit is contained in:
parent
df879604f2
commit
4bf4209a4c
@ -108,8 +108,8 @@ namespace ClassicalSharp {
|
|||||||
void PrintGraphicsInfo() {
|
void PrintGraphicsInfo() {
|
||||||
Console.ForegroundColor = ConsoleColor.Green;
|
Console.ForegroundColor = ConsoleColor.Green;
|
||||||
Graphics.PrintApiSpecificInfo();
|
Graphics.PrintApiSpecificInfo();
|
||||||
Console.WriteLine( "Max 2D texture dimensions: " + Graphics.MaxTextureDimensions );
|
Utils.Log( "Max 2D texture dimensions: " + Graphics.MaxTextureDimensions );
|
||||||
Console.WriteLine( "== End of graphics info ==" );
|
Utils.Log( "== End of graphics info ==" );
|
||||||
Console.ResetColor();
|
Console.ResetColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Drawing.Imaging;
|
using System.Drawing.Imaging;
|
||||||
using System.Reflection;
|
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Threading;
|
||||||
using SharpDX;
|
using SharpDX;
|
||||||
using SharpDX.Direct3D9;
|
using SharpDX.Direct3D9;
|
||||||
using D3D = SharpDX.Direct3D9;
|
using D3D = SharpDX.Direct3D9;
|
||||||
@ -413,7 +413,24 @@ namespace ClassicalSharp.GraphicsAPI {
|
|||||||
|
|
||||||
public override void EndFrame( Game game ) {
|
public override void EndFrame( Game game ) {
|
||||||
device.EndScene();
|
device.EndScene();
|
||||||
device.Present();
|
int code = device.Present().Code;
|
||||||
|
if( code >= 0 ) return;
|
||||||
|
|
||||||
|
if( (uint)code != (uint)Direct3DError.DeviceLost )
|
||||||
|
throw new SharpDXException( code );
|
||||||
|
|
||||||
|
// TODO: Make sure this actually works on all graphics cards.
|
||||||
|
Utils.LogDebug( "Lost Direct3D device." );
|
||||||
|
while( true ) {
|
||||||
|
Thread.Sleep( 50 );
|
||||||
|
code = device.TestCooperativeLevel().Code;
|
||||||
|
if( (uint)code == (uint)Direct3DError.DeviceNotReset ) {
|
||||||
|
Utils.Log( "Retrieved Direct3D device again." );
|
||||||
|
RecreateDevice( game );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
game.Network.Tick( 1 / 20.0 );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool vsync = false;
|
bool vsync = false;
|
||||||
@ -547,10 +564,10 @@ namespace ClassicalSharp.GraphicsAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override void PrintApiSpecificInfo() {
|
public override void PrintApiSpecificInfo() {
|
||||||
Console.WriteLine( "D3D tex memory available: " + (uint)device.AvailableTextureMemory );
|
Utils.Log( "D3D tex memory available: " + (uint)device.AvailableTextureMemory );
|
||||||
Console.WriteLine( "D3D vertex processing: " + createFlags );
|
Utils.Log( "D3D vertex processing: " + createFlags );
|
||||||
Console.WriteLine( "D3D depth buffer format: " + depthFormat );
|
Utils.Log( "D3D depth buffer format: " + depthFormat );
|
||||||
Console.WriteLine( "D3D device caps: " + caps.DeviceCaps );
|
Utils.Log( "D3D device caps: " + caps.DeviceCaps );
|
||||||
}
|
}
|
||||||
|
|
||||||
public unsafe override void TakeScreenshot( string output, Size size ) {
|
public unsafe override void TakeScreenshot( string output, Size size ) {
|
||||||
|
@ -379,12 +379,12 @@ namespace ClassicalSharp.GraphicsAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public unsafe override void PrintApiSpecificInfo() {
|
public unsafe override void PrintApiSpecificInfo() {
|
||||||
Console.WriteLine( "OpenGL vendor: " + new String( (sbyte*)GL.GetString( StringName.Vendor ) ) );
|
Utils.Log( "OpenGL vendor: " + new String( (sbyte*)GL.GetString( StringName.Vendor ) ) );
|
||||||
Console.WriteLine( "OpenGL renderer: " + new String( (sbyte*)GL.GetString( StringName.Renderer ) ) );
|
Utils.Log( "OpenGL renderer: " + new String( (sbyte*)GL.GetString( StringName.Renderer ) ) );
|
||||||
Console.WriteLine( "OpenGL version: " + new String( (sbyte*)GL.GetString( StringName.Version ) ) );
|
Utils.Log( "OpenGL version: " + new String( (sbyte*)GL.GetString( StringName.Version ) ) );
|
||||||
int depthBits = 0;
|
int depthBits = 0;
|
||||||
GL.GetIntegerv( GetPName.DepthBits, &depthBits );
|
GL.GetIntegerv( GetPName.DepthBits, &depthBits );
|
||||||
Console.WriteLine( "Depth buffer bits: " + depthBits );
|
Utils.Log( "Depth buffer bits: " + depthBits );
|
||||||
if( depthBits < 24 ) {
|
if( depthBits < 24 ) {
|
||||||
Utils.LogWarning( "Depth buffer is less than 24 bits, you may see some issues " +
|
Utils.LogWarning( "Depth buffer is less than 24 bits, you may see some issues " +
|
||||||
"with disappearing and/or 'white' graphics." );
|
"with disappearing and/or 'white' graphics." );
|
||||||
|
@ -14,7 +14,7 @@ namespace ClassicalSharp {
|
|||||||
AppDomain.CurrentDomain.UnhandledException += UnhandledException;
|
AppDomain.CurrentDomain.UnhandledException += UnhandledException;
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine( "Starting " + Utils.AppName + ".." );
|
Utils.Log( "Starting " + Utils.AppName + ".." );
|
||||||
if( !AllResourcesExist( "terrain.png", "char.png", "clouds.png" ) ) {
|
if( !AllResourcesExist( "terrain.png", "char.png", "clouds.png" ) ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -60,7 +60,7 @@ namespace ClassicalSharp {
|
|||||||
|
|
||||||
static void Fail( string text ) {
|
static void Fail( string text ) {
|
||||||
Utils.LogWarning( text );
|
Utils.LogWarning( text );
|
||||||
Console.WriteLine( "Press any key to exit.." );
|
Utils.Log( "Press any key to exit.." );
|
||||||
Console.ReadKey( true );
|
Console.ReadKey( true );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,18 +156,34 @@ namespace ClassicalSharp {
|
|||||||
return new Vector3( (float)x, (float)y, (float)z );
|
return new Vector3( (float)x, (float)y, (float)z );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void Log( string text ) {
|
||||||
|
Console.WriteLine( text );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Log( string text, params object[] args ) {
|
||||||
|
Log( String.Format( text, args ) );
|
||||||
|
}
|
||||||
|
|
||||||
public static void LogWarning( string text ) {
|
public static void LogWarning( string text ) {
|
||||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||||
Console.WriteLine( text );
|
Console.WriteLine( text );
|
||||||
Console.ResetColor();
|
Console.ResetColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void LogWarning( string text, params object[] args ) {
|
||||||
|
LogWarning( String.Format( text, args ) );
|
||||||
|
}
|
||||||
|
|
||||||
public static void LogError( string text ) {
|
public static void LogError( string text ) {
|
||||||
Console.ForegroundColor = ConsoleColor.Red;
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
Console.WriteLine( text );
|
Console.WriteLine( text );
|
||||||
Console.ResetColor();
|
Console.ResetColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void LogError( string text, params object[] args ) {
|
||||||
|
LogError( String.Format( text, args ) );
|
||||||
|
}
|
||||||
|
|
||||||
public static void LogDebug( string text ) {
|
public static void LogDebug( string text ) {
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
Console.ForegroundColor = ConsoleColor.DarkGray;
|
Console.ForegroundColor = ConsoleColor.DarkGray;
|
||||||
@ -176,14 +192,6 @@ namespace ClassicalSharp {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LogWarning( string text, params object[] args ) {
|
|
||||||
LogWarning( String.Format( text, args ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void LogError( string text, params object[] args ) {
|
|
||||||
LogError( String.Format( text, args ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void LogDebug( string text, params object[] args ) {
|
public static void LogDebug( string text, params object[] args ) {
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
LogDebug( String.Format( text, args ) );
|
LogDebug( String.Format( text, args ) );
|
||||||
|
@ -50,8 +50,8 @@ namespace SharpDX.Direct3D9
|
|||||||
DrawIndexedPrimitiveUP(type, minimumVertexIndex, vertexCount, primitiveCount, (IntPtr)Interop.Fixed(ref indexData[startIndex]), indexDataFormat, (IntPtr)Interop.Fixed(ref vertexData[startVertex]), Interop.SizeOf<T>());
|
DrawIndexedPrimitiveUP(type, minimumVertexIndex, vertexCount, primitiveCount, (IntPtr)Interop.Fixed(ref indexData[startIndex]), indexDataFormat, (IntPtr)Interop.Fixed(ref vertexData[startVertex]), Interop.SizeOf<T>());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Present() {
|
public Result Present() {
|
||||||
Present(IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
|
return Present(IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Result TestCooperativeLevel() {
|
public Result TestCooperativeLevel() {
|
||||||
@ -95,13 +95,12 @@ namespace SharpDX.Direct3D9
|
|||||||
public void Reset(params PresentParameters[] presentationParametersRef) {
|
public void Reset(params PresentParameters[] presentationParametersRef) {
|
||||||
Result res;
|
Result res;
|
||||||
fixed (void* presentParamsRef = presentationParametersRef)
|
fixed (void* presentParamsRef = presentationParametersRef)
|
||||||
res= Interop.Calli(comPointer, (IntPtr)presentParamsRef,(*(IntPtr**)comPointer)[16]);
|
res = Interop.Calli(comPointer, (IntPtr)presentParamsRef,(*(IntPtr**)comPointer)[16]);
|
||||||
res.CheckError();
|
res.CheckError();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void Present(IntPtr sourceRectRef, IntPtr destRectRef, IntPtr hDestWindowOverride, IntPtr dirtyRegionRef) {
|
internal Result Present(IntPtr sourceRectRef, IntPtr destRectRef, IntPtr hDestWindowOverride, IntPtr dirtyRegionRef) {
|
||||||
Result res = Interop.Calli(comPointer, sourceRectRef, destRectRef, hDestWindowOverride, dirtyRegionRef,(*(IntPtr**)comPointer)[17]);
|
return Interop.Calli(comPointer, sourceRectRef, destRectRef, hDestWindowOverride, dirtyRegionRef,(*(IntPtr**)comPointer)[17]);
|
||||||
res.CheckError();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Surface GetBackBuffer(int iSwapChain, int iBackBuffer, BackBufferType type) {
|
public Surface GetBackBuffer(int iSwapChain, int iBackBuffer, BackBufferType type) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user