DXERROR err = WRONGMODE

Archives Forums/BlitzMax Bug Reports/DXERROR err = WRONGMODE

Grey Alien(Posted 2007) [#1]
I'm getting this with BMax V1.26 when I run my game in full-screen mode then I call some code to minimise it (works fine) then I click the game on the task bar and it goes full-screen again but the screen is black and I have to do an End Task on it. That error appears in the IDE Output window when I'm running in Debug mode.

btw, Alt+Tab works, so does pressing the windows key.

Oh and it works if I use OpenGL.

Got some code to duplicate the problem, you need a title.jpg and a paused.png to replicate it yourself:

Strict

Extern "win32"
	Function GetActiveWindow%()
End Extern

Graphics 800,600,32

Const SW_MINIMIZE = 6 'used with ShowWindow
Global WindowHandle = GetActiveWindow() 'need this to set icon, even in full screen mode.
Global image:TImage = LoadImage("Title.jpg")
Global paused:TImage = LoadImage("paused.png")

'DrawImage(Paused,200,200) 'uncomment this and crash will not occur

While Not KeyHit(Key_ESCAPE)
	Cls
	SetBlend SOLIDBLEND
	DrawImage image,0,0
	DrawText "Press Escape to Exit",10,10
	DrawText "Press M to Minimise",10,30
	SetBlend ALPHABLEND
	If AppSuspended() Then
		DrawImage(Paused,200,200)
	EndIf
	Flip
	
	If KeyHit(Key_M) Then
		ccMinimiseWindow(WindowHandle)
	EndIf
Wend

' -----------------------------------------------------------------------------
' ccMinimiseWindow: Windows API call to minimise a window
' -----------------------------------------------------------------------------
Function ccMinimiseWindow(hWnd%)
	?Win32
		ShowWindow(hWnd, SW_MINIMIZE)					
	?
EndFunction



I've figured out what's happening. When the game is suspended the code tries to draw Paused on the screen. Because Paused has NOT been sent to VRAM yet, the first time it tries to draw DX generates an error because the game is no longer full-screen it's minimised. If you uncomment the 'DrawImage(Paused,200,200) near the top, this sends Paused to VRAM and then later when the game tries to draw Paused when the game is minimised it works fine.

Basically DX (or BMax's implementation of DX) doesn't like it if you sent a graphic to VRAM when the game is minimised in this fashion. But it handles it if the game is alt+tabbed or Windows key is pressed. Some other Windows apps sometimes force a game to minimise when they have completed some task, I've seen this, and maybe they'll crash out the video driver in such a case.

Of the 800+ people that beta tested my latest game some of them did get some weird behaviour after the game had been running for a while, something about a severe driver error (windows error dialog). Wonder if it was caused by this?

Sure I could fix it my end by ensuring that no NEW graphics are drawn when the game is suspended but as this works in OpenGL it would be nice if it worked in DX.

Any ideas for a fix?


Grey Alien(Posted 2007) [#2]
I'm pretty sure this didn't NOT used to happen because I wrote some code for a Boss Key in my game framework which used to work and no longer works. So this looks like a problem that has been introduced recently. I'll check this out by finding an old version of something I compiled and running that...yep just confirmed, old version of my game work so this has been introduced at some point. Probably during the DX rewrite or subsequent fixes.


marksibly(Posted 2007) [#3]
Hi,

I get different symptoms here - it dies immediately after minimizing.

Adding a Flip after the ShowWindow fixes it, give that a go.


Grey Alien(Posted 2007) [#4]
Will try, thanks. Yep that worked. It's a bit ugly as you see the windows desktop and the game minimising whilst the screen mode is still full-screen, then it flicks back to the normal desktop res, but it no longer crashes. Thanks.