February 25, 2005

And THIS is why I disliked developing...

For the last 8 days, I've been working on a Managed DirectX top-down shooter using Direct3D to render sprites on-screen. I used MD3D because using DirectDraw really killed performance. However, DirectDraw was at least somewhat consistant across platforms.

Like all Direct3D games, I use textures. I decided to store my textures in a Hashtable and load them on demand using a helper function. Once a texture had been loaded, any future calls to this helper function would return the texture. In addition, if the Direct3D device got lost and then reset, I'd just have to clear the Hashtable entries on device reset, and all textures would be reloaded as needed by the game.

I developed the system on an nVidia card. It actually worked quite nicely. The core consisted of these two functions:


Public Function GetTexture(ByVal name As String) As Direct3D.Texture
name = name.ToLower
If Textures.ContainsKey(name) Then
Return DirectCast(Textures(name), Texture)
Else
If Sprite_Load(name) Then
Return DirectCast(Textures(name), Texture)
Else
Return Nothing
End If
End If
End Function

Public Function Sprite_Load(ByVal name As String) As Boolean
name = name.ToLower
Debug.Write("Sprite_Load: ")
If Textures.ContainsKey(name) Then
Debug.WriteLine("Already have '" & name & "'. Aborting load.")
Return False
End If
Try
Debug.Write("Loading '" & name & "'...")
Dim tex As Texture = TextureLoader.FromFile(VideoDevice, BASEPATH + name)
Textures.Add(name, tex)
Debug.WriteLine("done.")
Return True
Catch ex As Exception
Debug.WriteLine("error: " & ex.Message)
Return False
End Try
End Function


On the nVidia card, this worked perfectly. On my ATI Radeon 9200 All-In-Wonder at home, however, it doesn't work at all. Each texture renders as a solid color or corrupt. If I skip pulling the textures from the Hashtable and casting them back, however, they render okay.

Config errors like this are horrible to figure out for ISV's. Most ISV's don't have access to large configuration labs. Home developers are even worse off, usually only having what is currently in their computers...and heaven forbid they make too many changes to their configuration in a short period of time and face the wrath of Windows Product Activation (now in refreshing mint Call-Your-OEM flavor).

Fact is, I'm using this as a proof-of-concept. I want to get my basic texture handling system down so that I can go to a full 3D system and reuse the texture routines. But if I can't put these managed objects in a standard .NET collection and retrieve them, what good are they?

1 comment:

Zman said...

Linked from http://www.thezbuffer.com News & Resources for managed directx