Original Post
I''m in the middle of creating a DirectX (version 8.1) wrapper, and I was adding a texture class. Its the same layout I always use, a static IDirect3DDevice8 pointer. The only difference is the addition of a static D3DFORMAT variable. The problem is when I run the program, I get no errors, no output (from my error checking), but the program closes. If I remove the file, the program works right. It starts, clears the screen, and writes to a file that: Could not create texture, please make sure that "Data\TreeTownExt.bmp" exists. And it continues to run until I press escape. Here is my code:
// Texture.h
#ifndef _THE_CORE__TEXTURE_H_
#define _THE_CORE__TEXTURE_H_
#include <d3d8.h>
#include <d3dx8.h>
#include <dxerr8.h>
#include <fstream.h>
#include <stdio.h>
class CTexture
{
public:
static IDirect3DDevice8* m_pDevice;
static D3DFORMAT m_fmtFormat;
IDirect3DTexture8* m_pTexture;
char* m_pFilename;
CTexture();
~CTexture();
HRESULT Create(char* pFilename);
void Destroy();
HRESULT LoadFromFile(char* pFilename);
void SetDevice(IDirect3DDevice8* pDevice);
void SetFormat(D3DFORMAT fmtFormat);
void LogText(char* pString, ...);
};
#endif // #ifndef _THE_CORE__TEXTURE_H_
// Texture.cpp
//##############################################################################
// Texture.cpp
//##############################################################################
#include "Texture.h"
//##############################################################################
// Static member variables
//##############################################################################
IDirect3DDevice8* CTexture::m_pDevice = NULL;
D3DFORMAT CTexture::m_fmtFormat = D3DFMT_UNKNOWN;
//##############################################################################
// Constructor / Destructor
//##############################################################################
CTexture::CTexture()
{
m_pTexture = NULL;
}
CTexture::~CTexture()
{
Destroy();
}
//##############################################################################
// Create() / Destroy()
//##############################################################################
HRESULT CTexture::Create(char* pFilename)
{
HRESULT hResult = LoadFromFile(pFilename);
if(FAILED(hResult))
LogText("Failed to create texture.");
return hResult;
}
void CTexture::Destroy()
{
SafeRelease(m_pTexture);
}
//##############################################################################
// SetDevice() / SetFormat()
//##############################################################################
void CTexture::SetDevice(IDirect3DDevice8* pDevice)
{
m_pDevice = pDevice;
}
void CTexture::SetFormat(D3DFORMAT fmtFormat)
{
m_fmtFormat = fmtFormat;
}
//##############################################################################
// LoadFromFile()
//##############################################################################
HRESULT CTexture::LoadFromFile(char* pFilename)
{
m_pFilename = pFilename;
HRESULT hResult = D3DXCreateTextureFromFileEx(m_pDevice, pFilename, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, m_fmtFormat, D3DPOOL_DEFAULT, D3DX_FILTER_NONE, D3DX_FILTER_NONE, 0x00ff00ff, NULL, NULL, &m_pTexture);
if(FAILED(hResult))
{
LogText("Error creating texture. Please make sure %s exists.", pFilename);
return hResult;
}
return hResult;
}
//##############################################################################
// LogText()
//##############################################################################
void CTexture::LogText(char* pString, ...)
{
char Text[1024];
va_list valist;
va_start(valist,pString);
vsprintf(Text,pString,valist);
va_end(valist);
ofstream fout("TheCore_ErrorLog.txt",ios::app);
fout<<Text<<endl;
fout.close();
}
Then I use this my project''s source code:
// After setting Direct3D up // g_Texture defined globally // g_Gfx: Global instance of my Direct3D wrapper g_Texture.SetDevice(g_Gfx.m_pDevice); g_Texture.SetFormat(D3DFMT_A8R8G8B8);It can''t be my loading function, since I don''t get any output (or errors from Microsoft), so what could it be?
