D3D Device Reset Failure (Caused by UAC and Lock Screen)

Posted By: Emre

D3D Device Reset Failure (Caused by UAC and Lock Screen) - 09/05/19 13:43

Hi guys,

D3D Device failure during screen lock and also failure during UAC. it's not a big problem for game engine but i made a desktop program with acknex. it's running always. so if i run any setup program, my application crashes by uac. if i locked the windows screen, it's crashes again.

Want to share two videos about problem:
crash after screen lock
crash by uac

it crashes randomly especially if project contain a view.stage. My opinion is the problem is related with render target. Just guessing, still not sure.

i wonder is there anything i can do. i really need to solve this problem. is there any way? Please share your idea and information with me.

Here is the test code which i use in first video:

Code
#include <acknex.h>
#include <default.c>

MATERIAL* test_mat1 = 
{
	effect="Texture TargetMap;
	sampler2D g_samSrcColor = sampler_state { texture = <TargetMap>; MipFilter = Linear;	};
	float4 postprocessing_negative( float2 Tex : TEXCOORD0 ) : COLOR0 
	{
		float3 Color = 1. - tex2D( g_samSrcColor, Tex.xy).xyz;
		return float4(Color,1.);
	}
	technique PostProcess 
	{
		pass p1 
		{
			AlphaBlendEnable = false;
			VertexShader = null;
			PixelShader = compile ps_2_0 postprocessing_negative();
		}
	}";
}

VIEW* post_view1 ={layer = 0; flags = PROCESS_TARGET; material=test_mat1;}
function d3dreset()
{
	diag("\n\nD3D DEVICE RESET!\n");
}
function d3dlost()
{
	diag("\n\nD3D DEVICE LOST!\n");
}
function main()
{
	on_d3d_reset=d3dreset;
	on_d3d_lost=d3dlost;
	wait(3);
	level_load("");
	camera.stage = post_view1;  
}




You can test it. i have A7. if you have A8 you will probably get different message like: "3D Hardware Reset Failure."
Posted By: Quad

Re: D3D Device Reset Failure (Caused by UAC and Lock Screen) - 09/06/19 18:07

I tried removing and and recreating materials and stage views manually after reset/load but no dice. (A8)

Someone else correct me if i am wrong but I'd say this is a bug that engine forgets to destroy/recreate some internal stuff when actual d3d lost/restore events occur(when you are using PP views.)

IF that's a bug, don't think it will ever get fixed, considering the state of engine development in the last couple of years.
Posted By: Emre

Re: D3D Device Reset Failure (Caused by UAC and Lock Screen) - 09/06/19 21:29

Originally Posted by Quad
Someone else correct me if i am wrong but I'd say this is a bug that engine forgets to destroy/recreate some internal stuff when actual d3d lost/restore events occur(when you are using PP views.)

IF that's a bug, don't think it will ever get fixed, considering the state of engine development in the last couple of years..


That's what i'm afraid of. Thank you for testing and sharing your knowledge,Quad.
Posted By: Emre

Re: D3D Device Reset Failure (Caused by UAC and Lock Screen) - 09/07/19 20:40

Okay i found a solution. I'm sharing it in case you need it.

Code
#include <acknex.h>
#include <windows.h>
#include <default.c>

#ifndef material_and_view
	#define material_and_view
	MATERIAL* test_mat1 = 
	{
		effect="Texture TargetMap;
		sampler2D g_samSrcColor = sampler_state { texture = <TargetMap>; MipFilter = Linear;	};
		float4 postprocessing_negative( float2 Tex : TEXCOORD0 ) : COLOR0 
		{
			float3 Color = 1. - tex2D( g_samSrcColor, Tex.xy).xyz;
			return float4(Color,1.);
		}
		technique PostProcess 
		{
			pass p1 
			{
				AlphaBlendEnable = false;
				VertexShader = null;
				PixelShader = compile ps_2_0 postprocessing_negative();
			}
		}";
	}

	VIEW* post_view1 ={layer = 0; flags = PROCESS_TARGET; material=test_mat1;}
#endif

#ifndef fps_counter
	#define fps_counter
	var temp_fps;
	var actual_fps;
	function check_fps()
	{
		while(1)
		{
			temp_fps = 0.9*temp_fps+0.1/time_frame;
			actual_fps=temp_fps*16;
			DEBUG_VAR(actual_fps,10);
			wait(1);
		}
		
	}
#endif

#define DESKTOP_SWITCHDESKTOP 0x0100L
#define DF_ALLOWOTHERACCOUNTHOOK 0x0001

int DesktopResult;
int is_stage_off=0;

HWND* DeskHwnd;

function onexit()
{
	CloseDesktop(DeskHwnd);// i don't know if it's necessary.
}
function main()
{
	video_mode=10;
	video_screen=2;
	wait(3);
	fps_max=500;
	check_fps();
	on_exit=onexit;
	level_load("");
	camera.stage = post_view1;  
	DeskHwnd = OpenDesktop("Default", DF_ALLOWOTHERACCOUNTHOOK, false, DESKTOP_SWITCHDESKTOP);
	while(1)
	{
		if (DeskHwnd != 0)
		{
			DesktopResult = SwitchDesktop(DeskHwnd);
		}
		
		if (DesktopResult == 0)//Desktop is locked via uac or lock screen
		{   
			
			//remove the stage immediatly
			if(is_stage_off==0)
			{
				diag("\n\n!LOCKED!\n");
				camera.stage=NULL;
				is_stage_off=1;
				/*
				"wait(actual_fps);" is important, because desktop is locked and unlocked two time at once. (i don't know why)
				e.g: when you locked your screen and open it again. Diag message must be "!Locked! !Unloked!" But it doesn't.
				instead, it's "!Locked! !Unloked! !Locked! !Unloked!"
				That my cause a crash when we use pp_add and pp_remove repeatedly.
				So wait for it. No problem with this way.
				*/
				wait(actual_fps);
			}
			
			
		}
		else//Desktop is UNlocked
		{
			
			//setup post effect again
			if(is_stage_off==1)
			{
				diag("\n\n!UNLOCKED!\n");
				camera.stage=post_view1;
				is_stage_off=0;
				wait(1);
			}
			
		}	
		wait(1);
	}
}



Cheers! laugh
© 2019 lite-C Forums