Problem loading texture

Started by
6 comments, last by Mastaba 18 years, 10 months ago
I have a problem loading the texture tiger.bmp ( the tiger.x texture ). The D3DXCreateTextureFromFile function returns D3DXERR_INVALIDDATA. And after this error in the function HandleDXError the application crashes with an access violation at 0x0000000c, or something like that. And the output spew is: First-chance exception at 0x7c91416a in Leviathan.exe: 0xC0000005: Access violation reading location 0x0000015b. First-chance exception at 0x7c912ba3 in Leviathan.exe: 0xC0000005: Access violation reading location 0x0000013f. D3DX: tiger.bmp: (null) First-chance exception at 0x7c80b2af in Leviathan.exe: 0xC0000005: Access violation reading location 0x0000000c. Unhandled exception at 0x7c80b2af in Leviathan.exe: 0xC0000005: Access violation reading location 0x0000000c. The thread 'Win32 Thread' (0xf90) has exited with code -1073741819 (0xc0000005). The program '[2420] Leviathan.exe: Native' has exited with code -1073741819 (0xc0000005).
[source lang=cpp]
        HRESULT hr = 0;
        mFileName = _FileName;

        IDirect3DDevice9* Device = C_DisplayManager::mGetInstance()->mGetDevice();
        
        hr = D3DXCreateTextureFromFile( Device,
                                        (LPCWSTR)mFileName.c_str(), 
                                        &mpTexture );
		if( FAILED(hr) )
		{
			HandleDXError(hr, L"D3DXCreateTextureFromFile()", SHOWMESSAGEBOX);
            return;
	    }


//                        HandleError.cpp file


#include "dxstdafx.h"
#include "HandleError.h"
#include <dxerr9.h>
#include <sstream>
#include <windows.h>

    void HandleDXError( HRESULT _Error, std::wstring _Message, uint8 _DisplayOptions ) 
    {
        std::wostringstream OutStrStream;
        OutStrStream << L"Error: " << DXGetErrorString9(_Error) << std::endl
                     << L"Description:" << std::endl
                     << DXGetErrorDescription9(_Error) << std::endl
                     << L"Other:" << std::endl
                     << _Message << std::endl;
        
        if( _DisplayOptions & SHOWMESSAGEBOX )
        {
            std::wstring str = OutStrStream.str();
            LPCWSTR str2 = str.c_str();
            ::MessageBox( 0, str2, L"DirectX Error Message!", MB_OK | MB_ICONERROR );
        }
        if( _DisplayOptions & LOGMESSAGE )
        {
            // ************* INSERT LOGFILE CODE **********************
        }
        OutStrStream.clear();
    }


I have checked the device and its valid. The string is all fine. And the tiger.bmp is located in the right folder. Any ideas?
------------------------------- Zalthar -Joakim Karlsson------------------------------
Advertisement
Quote:Original post by zalthar
I have a problem loading the texture tiger.bmp ( the tiger.x texture ).


What do you mean with tiger.x texture?
Do you load tiger.bmp or tiger.x? You can load only the first as texture.
tiger.x is not a texture!
Maybe the error is this.
Try stepping through this code with your debugger. That way, you will know *exactly* where the crash occurs. Hopefully, that will help you to fix it, too [smile]

If you don't usually use the debugger for crashes like this, it would be best to start now. It is undoubetdly one of the best and most helpful tools a programmer can have. You just have to know how to use it.
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
Quote:
What do you mean with tiger.x texture?
Do you load tiger.bmp or tiger.x? You can load only the first as texture.
tiger.x is not a texture!
Maybe the error is this.


Well i mean the tiger.x that comes with the DirectX API. And I know the .x file is a mesh. I mean that I load the texture for the tiger mesh, tiger.x.

Quote:
Try stepping through this code with your debugger. That way, you will know *exactly* where the crash occurs. Hopefully, that will help you to fix it, too

If you don't usually use the debugger for crashes like this, it would be best to start now. It is undoubetdly one of the best and most helpful tools a programmer can have. You just have to know how to use it.


I have stepped through the code many times. Thats how I checked that the filename and device was correct. And the lines that failes are as said before,

[source lang=cpp]hr = D3DXCreateTextureFromFile( Device,                                        (LPCWSTR)mFileName.c_str(),                                         &mpTexture );


returns D3DXERR_INVALIDDATA and ...

[source lang=cpp]::MessageBox( 0, str2, L"DirectX Error Message!", MB_OK | MB_ICONERROR );


renders to a access violation.

------------------------------- Zalthar -Joakim Karlsson------------------------------
Ah, okay. Looking at the documentation for MessageBox(), it says that it's okay if the first parameter is 0 (or NULL). Check to make sure str2 is a valid LPCSTR. Everything else looks perfectly fine.
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
I'd put a breakpoint on the line that loads the file, and then debug the program. When the program breaks, examine the values that are about to be passed to the function to see if they are all sane.
.
Quote:
Ah, okay. Looking at the documentation for MessageBox(), it says that it's okay if the first parameter is 0 (or NULL). Check to make sure str2 is a valid LPCSTR. Everything else looks perfectly fine.


Well since the new DirectX framework uses Unicode the str2 is a LPCWSTR. And yes the compiler is set to unicode.

Quote:
I'd put a breakpoint on the line that loads the file, and then debug the program. When the program breaks, examine the values that are about to be passed to the function to see if they are all sane.


I have done that I said that before. The values are all sane. But the function fails.
------------------------------- Zalthar -Joakim Karlsson------------------------------
You didn't say anything about checking to see if &mpTexture was sane. And I can't tell it is in the source you posted as it appears to come from nowhere.
.

This topic is closed to new replies.

Advertisement