# Texture From File In Memory

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

## Recommended Posts

Why does this constantly fail?
if(FAILED(D3DXCreateTextureFromFileInMemoryEx(
pD3DDevice,
Raw,
Size,
D3DX_DEFAULT,
D3DX_DEFAULT,
D3DX_DEFAULT,
NULL,
D3DFMT_A8R8G8B8,
D3DPOOL_MANAGED,
D3DX_DEFAULT,
D3DX_DEFAULT,
D3DCOLOR_XRGB(255, 2, 255),
&ImageInfo,
NULL,
&(Texture) )))
{
// Always Fails
}


Raw and Size are straight out of an ifstream. The raw data is in the PNG format.

##### Share on other sites
Without seeing your file loading code it's really difficult to say. Common mistakes can include not opening the file in binary mode or not getting the size correctly. If it's not one of those problems, you'll probably need to post your code.

##### Share on other sites
I've worked out what the problem was...

I didn't call ResourceFile::LoadHeader(); and thus size was of an undefined length.

I think I should call that from ResourceFile::Open(); prevent future head aches.

Thank you.

##### Share on other sites
I hope you learned a lesson.
Never assume anything...
you must always check in the debugger what you actually pass to a function when it fails. You should have also looked at the return value instead of just using the FAILED macro on it. A HRESULT tells you what type of error happened.

##### Share on other sites
If you were using the Debug Runtimes, you'd be given a nice error message in your debug output, so you wouldn't have to guess the bug.