Jump to content
  • Advertisement
Sign in to follow this  
AKofSpades

loading images from path

This topic is 3714 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

Right now I have all the files used by the program im making in the same folder. I want to orgainze the images into different files. When I do this, the program crashes even though I specified the path in this function: D3DXCreateTextureFromFileEx(). However, it runs fine if everything is in the same folder.

Share this post


Link to post
Share on other sites
Advertisement
Ok. What's your question? What have you found the problem to be? Are you using the Debug runtimes? Are you checking the return values for all of your D3D functions? Is D3DXCreateTextureFromFileEx failing? If so, what error code? Can we see the code where you load the textures?

Share this post


Link to post
Share on other sites
Can you post a code-snippet for how you generate the new filename? I suspect this is just a regular straight-up bug on your part - it's easy enough to do. Especially forgetting to escape the '\' if you use it - something like "\textures\texture.bmp" will get mangled by the compiler...

Step through your code in VS and inspect the variable immediately before the call to D3DX. Chances are it'll be immediately obvious why its not working [smile]

hth
Jack

Share this post


Link to post
Share on other sites
I have an enumeration to identify the images (prefixed CR_). TEXTURE_LIST is a custom array of a class containing this struct:

struct glLoadedTexture
{
LPDIRECT3DTEXTURE9 texture; //The texture
glString sFilename; //The filename of the texture
glInt width; //Width of the texture
glInt height; //Height of the texture
glTEXTURES img;
};


Next, an example of two images being loaded. The first, CR_Cobblestone, is contained in the folder "Pictures" which is in the folder containing everything else for the program (main folder). The next picture, CR_Water, is located in the main folder.


TEXTURE_LIST[CR_Cobblestone].sFilename = "\Pictures\Cobblestone.png";
TEXTURE_LIST[CR_Water].sFilename = "Water.png";


D3DXCreateTextureFromFileEx (DEVICE, TEXTURE_LIST[CR_Cobblestone].sFilename, D3DX_DEFAULT, D3DX_DEFAULT,
D3DX_DEFAULT, NULL,
D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT,
colorkey, NULL, NULL, &TEXTURE_LIST[CR_Cobblestone].texture);

D3DXCreateTextureFromFileEx (DEVICE, TEXTURE_LIST[CR_Water].sFilename, D3DX_DEFAULT, D3DX_DEFAULT,
D3DX_DEFAULT, NULL,
D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT,
colorkey, NULL, NULL, &TEXTURE_LIST[CR_Water].texture);

Share this post


Link to post
Share on other sites
Also, the program works if I just put the CR_Cobblestone picture in with the rest like I did with CR_Water.

But when the time comes to load the file in game from another path, a run-time error occurs, specifically,

Unhandled exception at 0x4fe5798b in ChaosRealm.exe: 0xC0000005: Access violation writing location 0xcdcdcd7d.

Share this post


Link to post
Share on other sites
Quote:
Original post by AKofSpades
TEXTURE_LIST[CR_Cobblestone].sFilename = "\Pictures\Cobblestone.png";



This has nothing to with Direct3D. You need to learn about strings and escape characters.

The above should be:

TEXTURE_LIST[CR_Cobblestone].sFilename = "\\Pictures\\Cobblestone.png";

Stepping through your debugger and looking at the string would have alerted you to that, as was said previously.

Of course, that is one bug I found in 5 seconds or less, there may be others...

Share this post


Link to post
Share on other sites
Quote:
Original post by AKofSpades
Also, the program works if I just put the CR_Cobblestone picture in with the rest like I did with CR_Water.

But when the time comes to load the file in game from another path, a run-time error occurs, specifically,

Unhandled exception at 0x4fe5798b in ChaosRealm.exe: 0xC0000005: Access violation writing location 0xcdcdcd7d.
One of your functions is failing, and not giving you a pointer like you expect, probably D3DXCreateTextureFromFileEx(). You're completely ignoring the return value; if it fails you blithely ignore it and act as if everything is fine. You absolutely must use the SUCCEEDED and FAILED macros to check the return values of all important D3D functions; where "important" means the function returns a pointer, or fills in a data structure you rely on.

As it is, using backslashes in filenames like that isn't a good idea - Windows supports forward slashes too. If you must use backslashes, make sure to escape them. If you path is "c:\foo\new.png", then "\n" is a newline character, not a backslash and a letter 'n'. If part of your path contains any control characters, they'll get stripped. In this example, you'd need to use "c:/foo/new.png" or "c:\\foo\\new.png".

Share this post


Link to post
Share on other sites
Quote:
But when the time comes to load the file in game from another path..

Not sure why you would be using another path to the texture file.

When "the time comes," do you change the path in your code?

Quote:
Access violation writing location 0xcdcdcd7d

What line of code is executing when you get that error?

Usually, 0xcdcdcd.. indicates an unallocated variable.

Reread Evil Steve's post about using the Debug Runtime.

If you're not sure where to begin with that, take a look at introduction to debugging.

Share this post


Link to post
Share on other sites
Thanks for the replies,

Ok. I didnt realy know anything about escape characters until now (I have used /n but now it realy makes sense).

When I specify the complete path now, it works but what if someone else was using the program, how would it know where to look?

Share this post


Link to post
Share on other sites
Quote:
Original post by AKofSpades
When I specify the complete path now, it works but what if someone else was using the program, how would it know where to look?
You probably want to use a relative path instead.

For instance, if you have:
Folder/Bin/App.exe
Folder/Data/Foo.png
And you want to load Foo.png, you'd use the path "../Data/Foo.png" to go "up one level, then into 'Data', then get 'Foo.png'".

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!