Skip to main content
gamedev.net
🔒 Locked

PhysX - using NxActor

Started by speciesUnknown 0 replies 1.2k views
Original Post
speciesUnknown
speciesUnknown
I have this issue with NxActor. I want to have this structure to my logic system: The problem is, the NxActor * becomes null at some point that the NxScene decides upon. I want the entity classes (Thing, Vehicle, Character etc) to delegate functionality such as getPosition() and isSleeping() to their appropriate NxActor. I do not want to be scanning through the contents of the NxScene to figure out what is happening, since this means I need my World class to be aware of api specific stuff in PhysX. I'm "spawning" the Thing like this:

void World::spawnThing(const std::string& name, VectorMaths::Mat44<float>& pos)
{
    ThingEntity * e = (ThingEntity *)things.instance(name);
    physics.addThing(e,pos);
    queue.push(new ThingSpawnEvent(t,e->getObjectID(),e->getModelName()));	
}

void Physics::addThing(ThingEntity *& thing, VectorMaths::Mat44<float>& pos)
{
    NxActor * newActor = mScene->createActor(thing->getNxActorDesc());
    thing->spawn(pos,newActor);
    actors.push_back(newActor);
    // newActor is currently valid.
}

void ThingEntity::spawn(VectorMaths::Mat44<float> pos, NxActor * actor)
{
    position = pos;
    actor = actor;
    mode = ESpawned;
}




But when I do stuff like this, I get a crash:

bool ThingEntity::isActive()
{
    if(mode == ESpawned)
        return (!actor->isSleeping()); // crash here, since actor is now mysteriously NULL
    else
        return false;
}


Is there any other way of implementing this design? Or perhaps my design is flawed and I should abandon it.
Don't thank me, thank the moon's gravitation pull! Post in My Journal and help me to not procrastinate!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.