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() {
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
Graphics.PrintApiSpecificInfo();
|
||||
Console.WriteLine( "Max 2D texture dimensions: " + Graphics.MaxTextureDimensions );
|
||||
Console.WriteLine( "== End of graphics info ==" );
|
||||
Utils.Log( "Max 2D texture dimensions: " + Graphics.MaxTextureDimensions );
|
||||
Utils.Log( "== End of graphics info ==" );
|
||||
Console.ResetColor();
|
||||
}
|
||||
|
||||
|
@ -2,8 +2,8 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using SharpDX;
|
||||
using SharpDX.Direct3D9;
|
||||
using D3D = SharpDX.Direct3D9;
|
||||
@ -413,7 +413,24 @@ namespace ClassicalSharp.GraphicsAPI {
|
||||
|
||||
public override void EndFrame( Game game ) {
|
||||
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;
|
||||
@ -547,10 +564,10 @@ namespace ClassicalSharp.GraphicsAPI {
|
||||
}
|
||||
|
||||
public override void PrintApiSpecificInfo() {
|
||||
Console.WriteLine( "D3D tex memory available: " + (uint)device.AvailableTextureMemory );
|
||||
Console.WriteLine( "D3D vertex processing: " + createFlags );
|
||||
Console.WriteLine( "D3D depth buffer format: " + depthFormat );
|
||||
Console.WriteLine( "D3D device caps: " + caps.DeviceCaps );
|
||||
Utils.Log( "D3D tex memory available: " + (uint)device.AvailableTextureMemory );
|
||||
Utils.Log( "D3D vertex processing: " + createFlags );
|
||||
Utils.Log( "D3D depth buffer format: " + depthFormat );
|
||||
Utils.Log( "D3D device caps: " + caps.DeviceCaps );
|
||||
}
|
||||
|
||||
public unsafe override void TakeScreenshot( string output, Size size ) {
|
||||
|
@ -379,12 +379,12 @@ namespace ClassicalSharp.GraphicsAPI {
|
||||
}
|
||||
|
||||
public unsafe override void PrintApiSpecificInfo() {
|
||||
Console.WriteLine( "OpenGL vendor: " + new String( (sbyte*)GL.GetString( StringName.Vendor ) ) );
|
||||
Console.WriteLine( "OpenGL renderer: " + new String( (sbyte*)GL.GetString( StringName.Renderer ) ) );
|
||||
Console.WriteLine( "OpenGL version: " + new String( (sbyte*)GL.GetString( StringName.Version ) ) );
|
||||
Utils.Log( "OpenGL vendor: " + new String( (sbyte*)GL.GetString( StringName.Vendor ) ) );
|
||||
Utils.Log( "OpenGL renderer: " + new String( (sbyte*)GL.GetString( StringName.Renderer ) ) );
|
||||
Utils.Log( "OpenGL version: " + new String( (sbyte*)GL.GetString( StringName.Version ) ) );
|
||||
int depthBits = 0;
|
||||
GL.GetIntegerv( GetPName.DepthBits, &depthBits );
|
||||
Console.WriteLine( "Depth buffer bits: " + depthBits );
|
||||
Utils.Log( "Depth buffer bits: " + depthBits );
|
||||
if( depthBits < 24 ) {
|
||||
Utils.LogWarning( "Depth buffer is less than 24 bits, you may see some issues " +
|
||||
"with disappearing and/or 'white' graphics." );
|
||||
|
@ -14,7 +14,7 @@ namespace ClassicalSharp {
|
||||
AppDomain.CurrentDomain.UnhandledException += UnhandledException;
|
||||
}
|
||||
|
||||
Console.WriteLine( "Starting " + Utils.AppName + ".." );
|
||||
Utils.Log( "Starting " + Utils.AppName + ".." );
|
||||
if( !AllResourcesExist( "terrain.png", "char.png", "clouds.png" ) ) {
|
||||
return;
|
||||
}
|
||||
@ -60,7 +60,7 @@ namespace ClassicalSharp {
|
||||
|
||||
static void Fail( string text ) {
|
||||
Utils.LogWarning( text );
|
||||
Console.WriteLine( "Press any key to exit.." );
|
||||
Utils.Log( "Press any key to exit.." );
|
||||
Console.ReadKey( true );
|
||||
}
|
||||
|
||||
|
@ -156,18 +156,34 @@ namespace ClassicalSharp {
|
||||
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 ) {
|
||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||
Console.WriteLine( text );
|
||||
Console.ResetColor();
|
||||
}
|
||||
|
||||
public static void LogWarning( string text, params object[] args ) {
|
||||
LogWarning( String.Format( text, args ) );
|
||||
}
|
||||
|
||||
public static void LogError( string text ) {
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine( text );
|
||||
Console.ResetColor();
|
||||
}
|
||||
|
||||
public static void LogError( string text, params object[] args ) {
|
||||
LogError( String.Format( text, args ) );
|
||||
}
|
||||
|
||||
public static void LogDebug( string text ) {
|
||||
#if DEBUG
|
||||
Console.ForegroundColor = ConsoleColor.DarkGray;
|
||||
@ -176,14 +192,6 @@ namespace ClassicalSharp {
|
||||
#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 ) {
|
||||
#if DEBUG
|
||||
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>());
|
||||
}
|
||||
|
||||
public void Present() {
|
||||
Present(IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
|
||||
public Result Present() {
|
||||
return Present(IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
|
||||
}
|
||||
|
||||
public Result TestCooperativeLevel() {
|
||||
@ -99,9 +99,8 @@ namespace SharpDX.Direct3D9
|
||||
res.CheckError();
|
||||
}
|
||||
|
||||
internal void Present(IntPtr sourceRectRef, IntPtr destRectRef, IntPtr hDestWindowOverride, IntPtr dirtyRegionRef) {
|
||||
Result res = Interop.Calli(comPointer, sourceRectRef, destRectRef, hDestWindowOverride, dirtyRegionRef,(*(IntPtr**)comPointer)[17]);
|
||||
res.CheckError();
|
||||
internal Result Present(IntPtr sourceRectRef, IntPtr destRectRef, IntPtr hDestWindowOverride, IntPtr dirtyRegionRef) {
|
||||
return Interop.Calli(comPointer, sourceRectRef, destRectRef, hDestWindowOverride, dirtyRegionRef,(*(IntPtr**)comPointer)[17]);
|
||||
}
|
||||
|
||||
public Surface GetBackBuffer(int iSwapChain, int iBackBuffer, BackBufferType type) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user