Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

glassJAw

Weird problem (D3DXCreateTextureFromFileEx())

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

Okay, in one of my classes I load 3 .dds image files using D3DXCreateTextureFromFileEx(). The first is 256x256, the second is 512x512 and the third is 1024x1024. On the third, I get a memory read error in the load texture call. So first order of business: make sure the file is not corrupt, or using some bad compression or something. I remade the file with all the settings as they should be, same error. Next: See if I can load the file elsewhere. I can O_O (using the same texture loading procedure) Next: See if another texture works. It does. I remake the same image as a 512x512 .dds (which I can''t use, I need it to be 1024x1024) and load it no problem. So maybe I''m corrupting something with the first two textures I load? Nope: I changed the loading order, same thing. Also, I can safely load the texture AFTER I call that particular function anyways. So my card can definitely support the texture, (my card''s max texture size is 2048x2048). Does anybody have even the faintest idea why it only works with a smaller texture in that particular location alone? I don''t really want to have to load this texture elsewhere.

Share this post


Link to post
Share on other sites
Advertisement
Here's the (simplified) texture loading code:

CTexture::Init()

int CTexture::Init (string sFilename)
{
HRESULT hr;
D3DSURFACE_DESC surfaceDesc;
LOADEDTEXTURE* newTexture;
D3DXIMAGE_INFO imageDesc;

//Make sure texture is not already loaded

if (bLoaded)
return RERR_ALREADY_INITIALIZED;

//Convert filename to lowercase letters

sFilename = strlwr((char *)sFilename.c_str ());

//Check if texture is in the loaded list

//REMOVED FOR SIMPLICITY AS TEXTURE WILL NOT BE IN THE LIST


//Texture was not in the list, make a new texture

newTexture = new LOADEDTEXTURE;

//Load texture from file

hr = CGraphics::LoadTexture (sFilename, &newTexture->texture);

//Make sure texture was loaded

if (FAILED(hr))
return hr;

//Get texture dimensions

newTexture->texture->GetLevelDesc(0, &surfaceDesc);

//SOME ERROR CHECKING REMOVED


//Set new texture parameters

newTexture->referenceCount = 1;
newTexture->sFilename = sFilename;
newTexture->width = surfaceDesc.Width;
newTexture->height = surfaceDesc.Height;

//Push new texture onto list

loadedTextures.push_back (newTexture);

//Setup current texture instance

texture = loadedTextures.back();
bLoaded = TRUE;

//LOGGING REMOVED


//Successfully loaded texture

return TRUE;
}


CGraphics::LoadTexture()

//Load a texture from a file

int CGraphics::LoadTexture (const string& sFilename, IDirect3DTexture8** texture)
{
D3DXIMAGE_INFO srcInfo;
HRESULT hr;

//ERROR CHECKING REMOVED


//Use a magenta colourkey

D3DCOLOR colorkey = 0xFFFF00FF;

//Load image from file (CRASHES HERE)

hr = D3DXCreateTextureFromFileEx (d3dDevice, sFilename.c_str (), 0, 0, 1, 0, D3DFMT_A8R8G8B8,
D3DPOOL_MANAGED, D3DX_FILTER_NONE, D3DX_DEFAULT, colorkey, &srcInfo, NULL, texture);

//Make sure texture loaded correctly

//ERROR CHECKING REMOVED


//Successfully loaded texture

return TRUE;
}


The error checking/logging stuff I removed is pretty trivial and very likely not the source of the problem.

I didn't post CFont::Init() (the function where the call crashes) because, as of now, the first line in the function is the call to CTexture::Init(), and it never gets past that (unless, of course, I make the texture smaller).

EDIT: That's curious. It also crashes if I try to load the texture before CFont::Init() is called, but not after.
Of course, I only try to load it after Direct3D is started up.

Also, it works if I use a 1024x1024 TGA instead O_O

[edited by - glassJAw on August 18, 2003 1:48:37 AM]

Share this post


Link to post
Share on other sites
- No relevant debug output? Link d3dx8d.lib (the debug version).
- Tried the REF device (to make sure the driver's not involved in this)
- If no relevant output is found, write a small reproduction application for this beaviour (crash).
If the app crashes on HAL and/or REF, send it to directx@microsoft.com AND the IHV.

Peace,
Muhammad Haggag

[edited by - Coder on August 18, 2003 3:20:59 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by Coder
- No relevant debug output? Link d3dx8d.lib (the debug version).
- Tried the REF device (to make sure the driver''s not involved in this)
- If no relevant output is found, write a small reproduction application for this beaviour (crash).
If the app crashes on HAL and/or REF, send it to directx@microsoft.com AND the IHV.

Peace,
Muhammad Haggag



Nothing particularly interesting outputted:

First-chance exception at 0x004a1905 in Reaper.exe: 0xC0000005: Access violation reading location 0x00abd000.
Unhandled exception at 0x004a1905 in Reaper.exe: 0xC0000005: Access violation reading location 0x00abd000.

And it does indeed crash the REF device. I''m not sure I can write a small application as it only crashes in that particular function in my code.

Share this post


Link to post
Share on other sites
Weird. The REF generally isn''t bug-free, but it''s very rare that one bumps in one.
Anyway:
- Attempt making a reproduction app. If it crashes, then cool, send it to them.
- If it doesn''t crash, try to mimic the steps taken by Reaper up to the crash in a repro-app.
- If this repro-app doesn''t crash, then most probably you''re doing something wrong in Reaper; one of those sneaky bugs that are so hard to spot. Revise your code.
- If revising your code doesn''t solve it, send the app to other people on this forum to run it and see whether it crashes or not (maybe it''s some weird combo of installed devices and/or OS''s)
- If it crashes on them, and if you can send the source to someone on this forum to revise after you, do it.
- If you can''t do that, send it to microsoft and your IHV.

Share this post


Link to post
Share on other sites

  • 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!