[.net] D3DX TextureLoader and FileStream issue.

Started by
8 comments, last by Etherstar 17 years, 9 months ago
Here's the issue. I'm using StreamWriter/StreamReader for my file I/O. If I use either of these classes to read or write to a file, and then call TextureLoader.FromFile() I am greeted by a nice spiffy invalid data exception. My theory is that somehow the StreamWriter/StreamReader classes are corrupting my buffers somehow, and when I go to load a texture the data gets corrupted (or at least doesn't reperesent what the Textureloader is looking for). I make sure to always call the Close() method of the StreamWriter/Reader finishes. My StreamWriter/Reader objects are also enclosed in a using block so they (theoretically) should get disposed after they fall out of scope. Any ideas?
Advertisement
Perhaps StreamWriter and StreamReader are overloading the functions used by the normal stream, thus causing it to get garbage data?

Also I think you want TextureLoader.FromStream not TextureLoader.FromFile.

Anyway my suggestion is that you pass StreamWriter.BaseStream or StreamReader.BaseStream into TextureLoader.FromStream.
Actually I've been loading textures directly from the .png files with TextureLoader.FromFile("myFilePath.png").
OK I reread you're post. You're using StreamWriter to create a PNG correct, then opening it with StreamReader and then using FromFile(while the stream is open), is that correct?

If that is the case then be aware that FromFile does not require that the file be open before it is called, it will do it itself(well my version will).
Sorry, I apologize for the ambiguity.

I am loading level data in string form using the StreamReader/StreamWriter classes.

I am loading Textures via the D3DX TextureLoader.FromFile() method.

When I call TextureLoader.FromFile() after using the StreamReader/StreamWriter classes to load level data I receive an invalid data exception from the TextureLoader.FromFile() call.
So do the StreamReader/StreamWriter classes even touch the PNG? Have you tried just loading the PNG by itself, no level data of StreamReader/StreamWriter?

Mabye D3D just doesn't like your PNG or the file name/directory is wrong?
StreamReader/Writer does not touch the .png in question. Application has loaded this particular file mutliple times in the past, and even does multiple times within the lifetime of the application. However, if I use the StreamReader/Writer classes and try it again, I receive invalid data exceptions.
Well I'm running out of solutions here [grin]. Last guess is that it is the GC. Have you tried actually creating stream objects rather than using "using" blocks?

Hopefully someone besides me chimes in and can answer your question.
I'll give it a shot in the morning, appreciate your help thus far.
Solved the problem by removing the using blocks. Must have been a strange GC issue. /boggle

This topic is closed to new replies.

Advertisement