Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (Nymphodora, AndrewAMD, TipmyPip, Quad, Imhotep), 847 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
D3D Device Reset Failure (Caused by UAC and Lock Screen) #478085
09/05/19 13:43
09/05/19 13:43
Joined: Jul 2007
Posts: 619
Turkey, Izmir
Emre Offline OP
User
Emre  Offline OP
User

Joined: Jul 2007
Posts: 619
Turkey, Izmir
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."

Last edited by Emre; 09/09/19 20:42. Reason: videos are no longer available
Re: D3D Device Reset Failure (Caused by UAC and Lock Screen) [Re: Emre] #478095
09/06/19 18:07
09/06/19 18:07
Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
Quad Online
Senior Expert
Quad  Online
Senior Expert

Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
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.


3333333333
Re: D3D Device Reset Failure (Caused by UAC and Lock Screen) [Re: Quad] #478097
09/06/19 21:29
09/06/19 21:29
Joined: Jul 2007
Posts: 619
Turkey, Izmir
Emre Offline OP
User
Emre  Offline OP
User

Joined: Jul 2007
Posts: 619
Turkey, Izmir
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.

Re: D3D Device Reset Failure (Caused by UAC and Lock Screen) [Re: Emre] #478106
09/07/19 20:40
09/07/19 20:40
Joined: Jul 2007
Posts: 619
Turkey, Izmir
Emre Offline OP
User
Emre  Offline OP
User

Joined: Jul 2007
Posts: 619
Turkey, Izmir
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

Re: D3D Device Reset Failure (Caused by UAC and Lock Screen) [Re: Emre] #481963
11/28/20 01:06
11/28/20 01:06
Joined: Apr 2002
Posts: 1,246
ny
jumpman Offline
Serious User
jumpman  Offline
Serious User

Joined: Apr 2002
Posts: 1,246
ny
Hi Emre, thanks for linking your solution. Here is what I've done so far, with advice and code snippets from both of you.

It currently isnt working 100%, but here is the major parts of the code that I believe help a lot, I think it completely got rid of the 3d Hardware Reset failure crash when waking up from a screensaver:

Code
#include <windows.h>  //----------include windows.h

...

function main()
{

var render_chain_destroy=0;
var render_chain_state=0;

while(1) ///--------------------put this in your main loop
{

BOOL bSaver;  //--------------------------------creates a BOOL flag that will be changed by the windows.h function SystemParametersInfo
SystemParametersInfo(114,0,&bSaver,0);  //---------114 is a specific parameter that tells gamestudio whether or not a screensaver is running

...


        //---------If bSaver is 1/true then it means the windows screensaver is running:

	if((bSaver)||(window_focus==0))  //-----------bSaver is a flag set by SystemParametersInfo above. I put window_focus in here as well 
	{

   render_chain_destroy=1;  //-------get ready to destroy the render chain

        }

       else
      {

      render_chain_destroy=0;  //-------if the screen saver isnt running, dont destroy the render chain

      }



if(render_chain_destroy==1)  //-----we are ready to destroy the render chain because the screensaver is on
{

if(render_chain_state==0)
{

destroy_render_chain();  //-------put your render chain destruction here (remove stages, remove bmaps, purge bmaps
render_chain_state=1;  //-----destroy the chain once
}


}


if(render_chain_destroy==0)  //-------if the system doesnt have a screensaver running
{

if(render_chain_state==1) //------and we recently destroyed the render chain because we destroyed it when a screensaver came on before
{
recreate_render_chain(); //--------recreate your render chain here
wait(-2); //------------I waited 2 seconds here, not sure if this helps or not
render_chain_state=0;  //-------we reset this var to 0, which is only set to 1 when a screensaver is on.

}


}


There some caveats to the above screensaver code. It only consistently works if gamestudio is running in a window. Obviously, if gamestudio is full screen, the screensaver will never trigger.

But lets work on the next hurdle. Locking your computer.

...
if (DeskHwnd != 0)
{
DesktopResult = SwitchDesktop(DeskHwnd);
}


if((DesktopResult==0)||(key_o))
{
...

With Emre's code, I can get gamestudio to recognize when the computer is locked! I destroy the render chain and remove the stages the moment gamestudio detects a lock.

However, when you log back in to a running windowed gamestudio exe, the game gave me a "cant create texture unnamed", but it didnt crash the game. When you select OK, the game seems to run ok in windowed mode after.

If you run the game in fullscreen, then lock, destroy the render chain in gamestudio, then log back in, the game looks like its frozen, however if you press alt+enter, the game seems to unfreeze and start working again.

Emre, have you tried to see if your game works when you run fullscreen, then lock, then log back into the desktop to see what a running gamestudio does?

Thank you two for your help so far.


Moderated by  old_bill, Tobias 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1