Jump to content
  • Advertisement
Sign in to follow this  
-justin-

Release with Sprites in a class

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

Hey everyone, I'm working on yet another game. This'll be my fourth. However, this is my first time working with classes and DirectX, as well as linked lists (not my first time with the material itself, just in the DirectX sense). I'm getting an error saying this: an unhandled exception of type 'System.NullReferenceException' occurred. Additonal Information: Object reference not set to an instance of an object. Now basically, I have broken my class structure into a hierarchy or three things. Level, Scene,Entity (which represents a character or something). Each Scene and Entity have a Sprite and Texture associated with it. The debugger marks this as the error: [this is in Entity's deconstructor]
if(entityTexture != NULL)
{
  entityTexture->Release();
}

I also have a method inside Entity that "loads the graphic" which just looks like this:
void Entity::loadEGraphics(char *filename)
{
	if(FAILED(D3DXCreateSprite(g_pd3dDevice, &entitySprite)))
	{
		MessageBox(NULL, "Error", "Entity sprite load error!", MB_OK);
	}

	if(FAILED(D3DXCreateTextureFromFile(g_pd3dDevice, filename, &entityTexture)))
	{
		MessageBox(NULL, "Error", "Entity Texture load error!", MB_OK);
	}
}

Why am I getting a NULL exception when I'm filling my EntityTexture?

Share this post


Link to post
Share on other sites
Advertisement
Don't mind me, I'm just an average idiot :P

Deconstructors get called everytime your object goes outta scope, so it was throwing an error.

Silly me...

Share this post


Link to post
Share on other sites
Hmm, well I thought that would fix it, however now it is saying the sprite object is a NULL value.

The only thing I can think of is that maybe my copy constructor and/or overload operator = isn't working. :/

here's the beginning of my Scene's operator overload; e is an entity with the SPRITE object and TEXTURE object

later scene calls a draw method that calls individual entity.draw methods

this is why i didn't work with classes b4 :P


Scene& Scene::operator = (Scene &other) throw(exception)
{
if(this != &other)
{
delete []e;
e = new Entity[other.numEntities];
if(e == NULL)
{
throw exception("Scene = error!");
}
else
{
for(int i = 0; i < other.numEntities; i++)
{
e = other.e;
}
}




If any1 has any ideas I'd be really happy... or some example code of what you've done. This is probably really easy and I'm over-complicating it.

Also, not sure if I should use one sprite object / texture for each entity or not. Seems kinda wasteful!

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!