#passing object into constructor, and then modifying the data. But is null.

9 messages · Page 1 of 1 (latest)

pallid cliff
#

Hey

void create_tree (Entity_data& entity_data, int id /* position */ )
{
    std::vector<float> vertices = 
    {
        -0.8f, -0.8f, 0.0f, 1.0f, 0.0f, 0.0f, // Vertex 1 (position and color)
        0.0f,  0.8f,  0.0f, 0.0f, 1.0f, 0.0f, // Vertex 2 (position and color)
        0.8f,  -0.8f, 0.0f, 0.0f, 0.0f, 1.0f  // Vertex 3 (position and color)
    };
    entity_data.entity_vec.push_back ( id );
    RenderObject obj = RenderObject ( vertices );
    entity_data.render_map.emplace ( id,  obj );
}
int main ( )
{
    Entity_data entity_data;
    
    Engine engine = Engine ( entity_data ) ;
    create_tree ( engine.get_entity_data() ,  1 /* id */ );
    engine.run ( ); 
}
Engine::Engine ( Entity_data& entity_data ) : entity_data(entity_data)
{
    for ( auto& a : this->entity_data.render_map[1].get_vertices() )
    {
        std::cout << a << std::endl; 
    }
}

So from the above, when i use the create tree function, i expect in the constructor (and any call after calling the engine constructor) to print the data i emplace in the map.

but for some reason its null and idk why??

any more info i can give lmk.

just trying to figure out what the loop in constructor ( ii have also made loops after the c onstructor example in main after the create_tree with a get_entity_data from the engine function and nothing still.

thanks.

versed nebulaBOT
#

When your question is answered use !solved or the button below to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

inland robin
#

You are putting data into the map after constructing the Engine.

pallid cliff
inland robin
#

the constructor runs first, then you add data to the map

#

so how should the constructor print the data that is added later?

pallid cliff
#

yeah its working now

#

im an idiot

#

thank you for pointing that out