At the moment there isn't actually any code inside spawn, so it must be either m_vEntities isn't initialized, or m_vEntities isn't initialized. I think m_vEntities gets initialized automatically when CEntityController gets constructed. Here is where entities get added to m_vEntities:

>> I've looked around in my code, and I can't find any variables that have been assigned that address(0xccccccd0).

In MS VS debug builds, if you don't explicitly initialize a pointer that is on the stack, it gets initialized with the value 0xcccccccc. So make sure you don't use uninitialized pointers and watch out for pointers having the value 0xcccccccc rather than 0xccccccd0.

0xccccccd0 is rather a side-effect of the root cause (access through uninitialized pointer) i.e. most likely you won't be finding pointers with that value.

Bearing that in mind, have you tried using an iterator to dereference the vector, or perhaps even using .at() which is more type-safe than dereferencing the vector directly??
Might be worth a try, .at() should throw an exception if there's a problem with one of the items that you're dereferencing. That might shed some light on the problem.

You've also said that the CEntity::Spawn method doesn't do anything ATM, so we know that's not the problem. Plus CEntity::Spawn is not listed in the call stack, so we can definitely rule that out.

Which leaves the vector and the items it contains (Pointers to CEntity objects wasn't it?). I suspect it's most likely that one or more of the objects/pointers in the vector have not been initialised correctly.

I also noticed that the CEntityController::Start function is listed further up the stack-trace... Is there any chance that there is something going awry somewhere in the Start function which could be causing the problems you're seeing in the SpawnEntities function? It could even be something that gets set-up before the start function is called and that the start function is merely triggering the bug.

I'd say take a look at any code which deals with the vector of entities, starting with the very first bit of code that initialises the vector, and then any subsequent uses of the vector (adding entities to the vector etc.) right up until the code in the start function.

If need be, put breakpoints on any lines that do anything with the vector and keep checking the state of the vector and it's contents. That should give you all the answers you need.

With a little patience and some debugging prowess, I think you'll get to the bottom of this in no time! I have a feeling this is gonna be one of those bugs where you'll just want to kick yourself when you realise what it is. Most of my bugs tend to be of that variety! heh heh!

Hey Jason :)
Using .at( ) didn't work, it gave me the same error. Mabey I'm doing it wrong? This is how I did it: m_vEntities.at( i )->Spawn( ) All Start( ) does is call SpawnEntities( ) and ActivateEntities( ), and the one that gets called first is SpawnEntities( ) which is the one throwing the error, so I don't think it's in Start( ).

I don't know if m_vEntities is initialized or not, but doesn't the default constructor get called anyway if it's a member of a class that gets constructed? The constructor doesn't actually have anything in it about m_vEntities, so that might be the problem.

At the moment, I'm only adding one thing to the vector just to test it, with gpGlobalFunctions.Spawn( "debug_entity_test", "test" );
Here is that function:

EDIT: I looked at every part of code about the vector with the debugger, and when I hover over the m_vEntities with my mouse, it shows me that the entity has been put into the vector, then when I look into the entity, it says there's a variable called _vfptr(i didn't put that there) which has the value 0xcccccccc, and the member of the entity, "m_sEntityName" has a member called m_sValue which has the value <Bad Ptr>.

I don't know how to fix this or what it means, but it looks like it could be the source of the problem.

Well, I fixed it. I did it by making the variables inside gpGlobalFunctions.Spawn( ) pointers, and initializing them with new.

That sounds good i.e. you are not anymore storing pointers to stack-based objects in the vector. Actually you are allocating those objects with new .

Then regarding the errors ...
test.cpp ...

<snip>
CTestEntity::CTestEntity( )
{
// force the value to float (otherwise it would be double)
SetNextThink( gpGlobals.curtime + 1.0f);
}
<snip>
CTestEntity eRegEntity; // this line is OK
// But the following must be moved inside a function
gpGlobalFunctions.RegisterEntity( eRegEntity );

The header files you posted seem to be OK in terms of having #include guards, so the compiler probably got mixed up because of that outside-function usage of gpGlobalFunctions.RegisterEntity(...) you have there. So make the changes, re-compile and see what you get.

How will I be able to do entities like that if I have to put that inside a function? I planned to have the user enter all the class stuff into a .cpp file, then write that code so their entity is able to be spawned by gpGlobalFunctions.Spawn( ). I know this can be done, I've seen it before in the Source Engine.

How will I be able to do entities like that if I have to put that inside a function?

That's a difficult one to answer because there is a apparently a lot involved and not knowing the rest of code you already have.

But how about if you step back for a little while and start a new small project that involves a simple object hierarchy (say Base, Entity, TestEntity) and some global object storage.

- The global object storage would maintain/keep track of the objects of these classes (using e.g. vector<Base *> as you already seem to have).
- All of the objects would be allocated dynamically (that is, using new )
- Upon allocation of an object, a pointer to it would be stored in the global storage
- All of the objects would be deleted/destructed (using delete )
- Upon deletion of an object, the pointer to it in the global storage would be removed

I think that might be quite useful in realizing how to design this very basic object management scenario and have it work reliably. Because now it seems, that you are running into trouble because you don't yet know how to do that.

PS. In the previous post I commented that

CTestEntity eRegEntity; // this line is OK

However, that's actually not OK, if you store a pointer to it via the constructor and later on try to delete the object via the pointer. And moreover, you having that line there is in contradiction to what you said about initializing all the objects with new . That object is not allocated on the heap (using new), so you must not try delete it.

Hi. so this is actually a continuation from another question of mine[Here](https://www.daniweb.com/programming/software-development/threads/506795/dynamically-add-values-into-datagridview-cell-from-listbox-vb2010) but i was advised to start a new thread as the original question …

Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...

I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...