Jump to content
  • Advertisement
Sign in to follow this  
Etherstar

[.net] D3DX TextureLoader and FileStream issue.

This topic is 4371 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Actually I've been loading textures directly from the .png files with TextureLoader.FromFile("myFilePath.png").

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!