Jump to content

  • Log In with Google      Sign In   
  • Create Account


Unhandle Exception During Release/Shutdown of a texture


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 Xooch   Members   -  Reputation: 179

Like
0Likes
Like

Posted 17 February 2013 - 09:31 PM

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, 17 February 2013 - 09:32 PM.


Sponsor:

#2 MJP   Moderators   -  Reputation: 8828

Like
2Likes
Like

Posted 17 February 2013 - 10:00 PM

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).



#3 Xooch   Members   -  Reputation: 179

Like
0Likes
Like

Posted 17 February 2013 - 10:13 PM

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;}


#4 blueshogun96   Crossbones+   -  Reputation: 678

Like
0Likes
Like

Posted 18 February 2013 - 01:13 AM

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, 18 February 2013 - 01:14 AM.

Follow Shogun3D on the official website: http://shogun3d.net

 

blogger.png twitter.png tumblr_32.png facebook.png


#5 Hodgman   Moderators   -  Reputation: 24193

Like
2Likes
Like

Posted 18 February 2013 - 01:23 AM

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, 18 February 2013 - 01:25 AM.


#6 MJP   Moderators   -  Reputation: 8828

Like
2Likes
Like

Posted 18 February 2013 - 04:52 AM

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.



#7 Xooch   Members   -  Reputation: 179

Like
0Likes
Like

Posted 18 February 2013 - 05:35 PM

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, 18 February 2013 - 05:45 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS