GOT IT!
Now that I know what the problem is, its blindingly obvious. I'll leave it up to you to fix, but this is what is happening.
Everything im talking about here currently lives in your loadEntity() function.
1> This NEW chunk works fine because it is a pointer, and doesnt get emptied when this function finishes.
But you'll need to remember to use "free(hero);" when you're completely done with the object.
function loadEntity()
{
...
entity3d* hero = malloc(sizeof(entity3d));
zero(*hero);
hero.model = ent_create("player.mdl", vector(70,120,20), NULL);
act_player(hero);
...
}
2> This chunk works of yours fine because its globally defined so doesnt need "free()" to be used, but is ugly to look at.
entity3d npc[5];
function loadEntity()
{
...
zero(npc[0]);
npc[0].model = ent_create("maddog.mdl", vector(270,100,20), NULL);
act_enemy(npc[0]);
...
}
3> This chunk fails because it is a local object only, and causes a crash about one frame after it finishes.
function loadEntity()
{
...
entity3d gangsta;
zero(gangsta);
gangsta.model = ent_create("gangst1.mdl", vector(270,140,20), NULL);
act_enemy(gangsta);
...
}
The reason chunk 3> causes a crash is because once this function (loadEntity) is completed and finishes,
the object "gangsta" is removed, and its space in memory can be overwritten by anything else at any time.
BUT, act_enemy(..) or act_player(...) are still using a pointer to this 'empty' space !!
Next time you try to access the contents of what WAS gangsta, you're going to get random data. CRASH...F%%k!
It may even work for several frames, but eventually something will use the empty space and then go splat.
So unless you use code chunks like 1> or 2>, you MUST make sure the function containing the declaration of
"
entity3d SomeEntity;" keeps running until act_enemy(..) or act_player(...) have been closed off,
and
SomeEntity can be destroyed.
I hope Ive made it understandable, and if youve got any questions, fire away.
Best of luck.