Noob: How Would I Trap This DX Error?

BlitzMax Forums/BlitzMax Beginners Area/Noob: How Would I Trap This DX Error?

MGE(Posted 2008) [#1]
This first code does not trap. It throws a weird DX error in the console screen:
"DXERROR err=UNKNOWN:-2005531925 747"
SetGraphicsDriver D3D7Max2DDriver()
If Graphics(1680,1050,32,-1) = Null
 Print "Trapped!" ' <<< never gets trapped!
 End
EndIf

But this works, for test purposes I'm just throwing something obvious at it.
SetGraphicsDriver D3D7Max2DDriver()
If Graphics(32,32,32,-1) = Null
 Print "Trapped!" ' <<<< Works!
 End
EndIf


This came about when I purchased a new widescreen monitor. But I'm still using a crappy GPU. So I'm assuming there isn't enough VRAM to handle the large screen. But since control isn't coming back to the program I can't trap for it? Or can I doing something else? Thanks for any suggestions.


Gabriel(Posted 2008) [#2]
Does GraphicsModeExists() say your chosen resolution is available then?


MGE(Posted 2008) [#3]
Yes sir. I'm falling a logic path looking for compatible modes first.

I reinstalled DirectX, same error.

In OpenGL mode, there is no error reported in the console, no trapping either.


MGE(Posted 2008) [#4]
Still no luck...

SetGraphicsDriver D3D7Max2DDriver()
'SetGraphicsDriver GLMax2DDriver()
Global Ok:Int
'
ok = GraphicsModeExists(1680,1050,32,0)
'
If ok
 If Graphics(1680,1050,32,-1) = Null
  Print "Error creating Graphics Screen!" ' <<< never gets trapped!
  End
 EndIf
Else
 Print "Mode Not Available"
EndIf



tonyg(Posted 2008) [#5]
This might help


Gabriel(Posted 2008) [#6]
Then there's not much you can do. I think the error code you're getting relates to this error message (as far as I can tell anyway)

"The device could not be created because the render target surface is not located in video memory."

Which would indeed suggest that there might be unsufficient VRam available to create the graphics context. I don't know that there's anything you can do to trap it though. It seems like something that Max2D should be trapping.


MGE(Posted 2008) [#7]
Thanks for the replies. I did do a DX re-install. Looks like the problem is Max2D in both OpenGL and DX mode, is simply not handling the error correctly. So Gabriel you're correct. This is nothing I can do in this scenario other than having the program bomb out.

This sucks.


MGE(Posted 2008) [#8]
I've created a thread in the bug forum. Because alot of programmers are deafulting to desktop resolutions, and in the case where this happens, we will not be able to trap for it.


Grey Alien(Posted 2008) [#9]
Yeah I have code in place that check to see if a video mode is available before creating it yet some users still reported the game bombing on loading so I'd love to see a solution to this too.

Also based on this info, maybe it is *not* the best solution for widescreen games to use the desktop res and scale up the game graphics after all due to lots of VRAM use, so perhaps a lower matching aspect ratio res should be chosen instead. I guess it's possible that that mode could generate the same error (or a different error) too... Plus it would be interpolated on TFTs if that was not their natural res.


MGE(Posted 2008) [#10]
I'm glad I bought this new widescreen monitor, otherwise I never would have realized the bug. So now what I'm doing is building 2 arrays of graphics modes that my game can run best in. One for widesreen and one for standard. The arrays are constructed in order of best case to worse case.
Global widescreenmodes:Int[] = [1280, 800, 1440, 900, 1280, 768, 1280, 720]
Global standardmodes:Int[] = [1024, 768, 800, 600,640,480]

Depending on desktop aspect ratio, the program loops through the suitable array checking to see If GraphicsModeExists(), the first one it finds a match with, it uses it.

If no matches found, it defaults to the desktop res. But at least this way, I can hopefully find a better suited res for the game depending on my games resolution and aspect ratio. The key thing is to make sure you build the arrays with enough realistic info on resolutions past, present and future.

But since my games are wide screen to begin with, I hopefully wouldn't run into the situation that some games have, where the game res is 800x600 and it ends up being stretched on wide screen monitor. eek...


Grey Alien(Posted 2008) [#11]
So you are not worried about TFT interpolation due to not running at the natural res? I guess that's better than having a very slow game running at full desktop res.


MGE(Posted 2008) [#12]
I'm somewhat of a noob on the whole TFT, LCD stuff, I've been a CRT user forever. Perhaps you could explain what TFT interpolation is? If that means the monitor scaling the image to run in a resolution it does not support, then I havn't seen a problem yet.

I've tested my game which uses the projection matrix to scale to the device, on over 12 LCD monitors now. (I'm taking my game demo on a flash drive to several stores) And it looks fine. Perhaps since it appears it's always going to scale up and not down, there's not a problem? I could understand if it has to scale down, there could be more graphic issues.

So...what TFT interpolation problems have you come across? Thanks.


Grey Alien(Posted 2008) [#13]
Oh OK, so a TFT has a "natural" resolution which is the actual number of physical pixels it has across and down. So for laptops that is normally the desktop resolution they come pre-installed with. So of course if you set a TFT to use a lower resolution, then every pixel you want to draw will be spanning 1 point something physical TFT pixels. In the old days some TFTs had none or very poor "interpolation" which basically means scaling, so it looked really naff when you displayed graphics and text at the non-natural TFT res (all blocky and weird). Nowadays TFTs are a lot better but still if you use a non-natural res you'll get some scaling and thus the image will not be perfect. I'm on my Macbook Pro right now using a lower res than the natural one (because it's plugged into my plasma TV) and the text looks a little blurry compared to it's natural res.

So basically there is a choice of say: a) using desktop res and scaling the gfx with the GPU - the GPU is probably good at scaling b) using the exact game res with no GPU scaling - so the TFT does the scaling and it may not be so good c) using a res which is neither that of the game or the natural TFT res thus the GPU does scaling and then to make matters worse the TFT scales the result!

Make sense yet?


MGE(Posted 2008) [#14]
Thanks for the info, greatly appreciated. Yah, that makes perfect sense. Guess I'm going to have to look for an even older lcd monitor, because so far the game images are coming up fine.

This frickin bug really makes me not want to resort to desktop mode as the default. !#@#$^%^