Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

colinisinhere

Wierd problem.....

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

I just started working on an entity manager for my first person shooter just to make things a bit easier to work with.... but i ran into a strange problem very early.
///////////////////////////////////////

//CEntityManager.h

///////////////////////////////////////


#ifndef __CENTITYMANAGER_H_INCLUDED__
#define __CENTITYMANAGER_H_INCLUDED__

#include "CEntity.h"

class CEntityManager {
private:
	CEntity* entList[100];
	s32 entCount;

public:
	s32 getEntityCount();
	void newEntity(s32 type);
};

#endif

///////////////////////////////////////

//CEntityManager.cpp

///////////////////////////////////////


#include "CEntityManager.h"

s32 CEntityManager::getEntityCount() {
	return this->entCount;
}

void CEntityManager::newEntity(s32 type) {
	switch (type) {
	case ENT_NULL:
		break;
	case ENT_PLAYER:
		//!!!!this->entList[this->entCount] = new CPlayer;

		break;
	}
	//!!!!this->entCount++;

}
Notice the lines with the //!!!!. Whenever i uncomment either or both of those lines out and i execute the program... the program will just quit once it hits either or both of those lines?!? Whats up with that?!

Share this post


Link to post
Share on other sites
Advertisement
hmm, I tried that and it did the same thing


///////////////////////////////////////

//CEntityManager.h

///////////////////////////////////////


#ifndef __CENTITYMANAGER_H_INCLUDED__
#define __CENTITYMANAGER_H_INCLUDED__

#include "CPlayer.h"

///////////////////////////////////////////////////

// The entity manager is just a class that handles

// all of the entities to make things simpler

///////////////////////////////////////////////////

class CEntityManager {
public:
// Constructors

CEntityManager(): entCount(0) {}
~CEntityManager() {}

void newEntity(s32 type);

// Accessers

s32 getEntityCount();

private:
CEntity* entList[100];
s32 entCount;
};

#endif

///////////////////////////////////////

//CEntityManager.cpp

///////////////////////////////////////


#include "CEntityManager.h"

s32 CEntityManager::getEntityCount() {
return this->entCount;
}

void CEntityManager::newEntity(s32 type) {
switch (type) {
case ENT_NULL:
break;
case ENT_PLAYER:
//this->entList[this->entCount] = new CPlayer;

break;
}
this->entCount++;
}


that still will quit once it hits the line ''this->entCount++;''!!

I''ve never run into this problem before! does enyone know what the problem might be?

Share this post


Link to post
Share on other sites
Well, first of all, why are all of your member variables
accessed with a ''this'' pointer? I may be wrong, but that
probably will slow it down a bit.

-Hyatus
"da da da"

Share this post


Link to post
Share on other sites
quote:
Original post by Hyatus
Well, first of all, why are all of your member variables
accessed with a ''this'' pointer? I may be wrong, but that
probably will slow it down a bit.

-Hyatus
"da da da"


No, that is what happens anyways.




-the dev dan

Share this post


Link to post
Share on other sites
I use this-> just for readability, just so i know for a fact that the variable is a part of that class.... But still im getting the same wierd problem... anyone know what might be the case?

Share this post


Link to post
Share on other sites
I honestly don't know exactly where to begin, however in your newEntity() method, I don't think you should increment the entCount variable for both cases, only the ENT_PLAYER one. Also to perhaps save yourself some errors later down the track, you should initialize entList[n] = NULL in the constructor, and then to prevent memory leaks, free each entity from memory by using delete entList[n] in the destructor.

Oh also be sure to try rebuilding the entire app again - not just recompiling the current cpp file.

[edited by - wavarian on June 4, 2004 10:07:50 PM]

Share this post


Link to post
Share on other sites
Thanks a lot for the tips! I added the stuff in the constructor and deconstructor... but obvioulsy that didn''t help the problem.

I rebuilt the whole app and it still quits on either line!

Man... what can possibly be happening

Share this post


Link to post
Share on other sites
a few words:

you might consider making ''s32 CEntityManager::getEntityCount()'' const, just good form in my opinion

dumb question maybe, but I''m assuming CPlayer is a type of CEntity? just making sure

as for the error with ''this->entCount++'', I''m somewhat stumped. One suggestion (although I don''t see how a compiler could make this oversight) would be to put some parentheses in there, or get rid of the ''this->'' part, so one of the following instead to remove ambiguity:

(this->entCount)++; or
entCount++;

gcc handles it correctly in either case, but I''m don''t know what you''re using.

Another quick debuging idea for the other line that is still commented out: try doing something like ''this->entList[0] = new CPlayer;'' and see if it will run at least the once (obviously you''ll be stepping on memory problems if you try it over and over). Take what wAVaRiaN said to heart and consider his memory management technique early on to save yourself a headache.

One more suggestion: turn on all possible compile-time warnings, and maybe you''ll gain some insight.

Anyway, good luck with this, I''m thinking there''s a chance that your problem may not be isolated with this code you''ve supplied us, the bug may be somewhere else and creeping in.

Elijah

Share this post


Link to post
Share on other sites
Thanks for the tips!

CPlay is a part of CEntity through inheritance:

//
class CPlayer : public CEntity
//

But still the problem exists...

But.. I was messing around a bit, and I have come to the conclusion that this happends any time I change a variable within the class.... I was writting a class CConsole today and I ran into the same problem...

(*wierded out!)

It might be my framework (which is actualy based on somebody elses)... the whole program is based around one class (CGame)... There really not too much code to post, I could post the whole shibang. I will spend some more time messing around, and If I have no luck, I will come crawling back here....

(*runs to his room and sheds a tear)

Share this post


Link to post
Share on other sites

  • 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!