Jump to content
  • Advertisement
Sign in to follow this  
Tim Lawton

DX11 Unhandle Exception During Release/Shutdown of a texture

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

Currently Writing a new system, and I've put a small box with a texture on it, with DirectX11 (which was previously working before I started adding more unrelated code).

 

Now for some unknown reason, I've receiving this unhandled exception:

 

http://img15.imageshack.us/img15/5666/textureunload.png

 

Continuing will loop the same problem. I'm probably missing something really stupid, but I'd really like some insight to why this is happening.. Thanks!

 

 

Texture.cpp

#include "Texture.h"

/* Constructor & Deconstructor */
Texture::Texture()
{
	m_texture = 0;
}
Texture::~Texture(){}

/* Initialize */
bool Texture::Init(ID3D11Device* device, CHAR* filename)
{
	HRESULT r;

	//Load texture
	r = D3DX11CreateShaderResourceViewFromFile(device, filename, NULL, NULL, &m_texture, NULL);
	if(FAILED(r))
	{return false;}

	return true;
}

/* Return objects we are using to higher level */
ID3D11ShaderResourceView* Texture::GetTexture()
{return m_texture;}

/* Shutdown/Release Objects we have used */
void Texture::Shutdown()
{
	if(m_texture)
	{
		m_texture->Release();
		m_texture = 0;
	}
	return;
}
Edited by Xuchilbara

Share this post


Link to post
Share on other sites
Advertisement

Your "this" pointer is bogus inside of Model::ReleaseTexture. 0xcdcdcdcdcd is the default fill pattern for memory allocated from the heap, so this means that you allocated something with a Model* pointer that was never initialized to anything. Then you tried to call ReleaseTexture on that initialized pointer, and your program crashed when it tried to follow access memory using that invalid pointer (in your case it tried to access m_texture member of Model which is located at an offset of 16 bytes from the start of your Model class, which is why it's complaining about accessing memory at an address off 0xcdcdcddd).

Share this post


Link to post
Share on other sites

Im not quite sure I follow, I have allocated m_modeltype to ModelType

 

		struct ModelType
		{
			float x, y, z;
			float tu, tv;
			float nx, ny, nz;
		};



ModelType* m_modeltype;

 

And then initialized in the LoadModel() function

 

//Create the model using the vertex count that was read in
	m_modeltype = new ModelType[m_vertexCount];
	if(!m_modeltype)
	{return false;}

Share this post


Link to post
Share on other sites

Does your texture work at runtime after you made your changes?

 

Also, I don't think I'm seeing enough code to accurately pinpoint what's going on.  Can you show us what you changed?

 

Shogun

Edited by blueshogun96

Share this post


Link to post
Share on other sites
In your screenshot, the error is occuring in the Model class, not your ModelType struct.
It looks like you're calling Model::ReleaseTexture on an object that hasn't been created, or on an object that has been deleted.
e.g.
Model* model;
model->ReleaseTexture();//crash
//or
Model* model = new Model();
delete model;
model->ReleaseTexture();//crash
Edited by Hodgman

Share this post


Link to post
Share on other sites

When the unhandled exception occurs, break into the debugger. Go to the call stack window, you'll be in Model::ReleaseTexture. Go down in the stack to the previous function that called ReleaseTexture. In this function it will be calling ReleaseTexture on a Model* pointer. This pointer variable is bogus, it was never initialized to any value.

Share this post


Link to post
Share on other sites

Here is the shutdown function of my model.cpp 

void Model::Shutdown()
{
	//Release the model texture
	ReleaseTexture();

	//Release the vertex and index buffers
	ShutdownBuffers();

	//Release the model
	ReleaseModel();

	return;
}

 

It seems that every single of these functions return a problem when it accesses them, starting with ReleaseTexture() as its at the top. Although after doing some debugging it turns out it's going straight for the Shutdown() method and not the Init() Method during compile, in fact it completely ignores the initialization in the top end class.

 

Application.cpp

	/* CUBE */
	m_Cube = new Model;
	if(!m_Cube)
	{return false;}

	r = m_Cube->Init(m_D3D->GetDevice(), "Shapes/Cube.txt", "Textures/blocktexture.jpg");
	if(!r)
	{
		MessageBox(hwnd, "Cube Failed to load!", "Error!", MB_OK);
		return false;
	}

 

Why is it skipping directly to the Shutdown() function in my Application class first?

 

void Application::Shutdown()
{
	if(m_Cube)
	{
		m_Cube->Shutdown();
		delete m_Cube;
		m_Cube = 0;
	}

...
}
Edited by Xuchilbara

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!