About Store Forum Documentation Contact
Donations:
345$/mo



Post Reply 
Custom area data and pointers to objects
Author Message
kulesz Offline
Member

Post: #1
Custom area data and pointers to objects
I'm trying to dynamically populate an area with trees, that I could eventually modify in future (scale, mesh etc.).
I'm setting my custom area data with:
Code:
struct CustomWorldAreaData: public Game::Area::Data
{
    CustomWorldAreaData(Game::Area &area) :
        Game::Area::Data(area)
    {
    }
    Memx<Game::Obj*> trees;

    virtual Bool customSaveWant()
    {
        return true;
    }
};

The trees container is for the pointers to the trees objects. Trees objects are in a:
Code:
Game::ObjMemx<Game::Static> Trees;

Then I set and populate the area with:
Code:
Game::World.setObjType(Trees, OBJ_TREE);
Game::World.setAreaData<CustomWorldArea> ();


Game::World.areaLoaded(VecI2(x, z))->getData();

CustomWorldAreaData * AreaData = CASTCustomWorldAreaData, Game::World.areaLoaded(VecI2(x, z))->data());

for (int u=0; u<100; u++)
{
    double xx = RandomF(0, 128);
    double zz = RandomF(0, 128);

    Game::ObjParamsPtr tree = Game::Objs.ptrRequire("Data/Obj/plant/Tree/0.obj");
    Matrix m(tree->scale(), Vec(x,y,z));
    m.rotateYVec(Random(0, 360));
    Game::Obj* treeObj = Game::World.objCreateNear(*tree, m);      

    Game::Obj * treePtr = AreaData->trees.New();
    treePtr = treeObj;
}

After these operations, when I do:
Code:
AreaData->trees.elms()

I get the correct number of trees.
However, when I try to reference to the stored pointers:
Code:
REPA(AreaData->trees)
{
    Game::Static * tr = CAST(Game::Static, AreaData->trees[i]);
}

The application crashes?
My questions are:
- what could cause the crash, if the container were non-empty?
- how to delete a certain object (tree), having only such pointer stored in container? [removeData?]
10-29-2011 01:28 PM
Find all posts by this user Quote this message in a reply
Post Reply