Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


#ActualSuperVGA

Posted 26 June 2013 - 10:19 PM

Hi guys, I wanted to post a response ~8 hours ago, when GD was having issues, but I'll read Eight and Triencos reply as soon as I get the time.

 

 

 

Are you creating a SceneElement object, or an object that in turn creates a SceneElement object, statically anywhere? In that case, that object may be constructed before the map constructors, and thus the SceneElement constructor is accessing a not-yet-constructed map object.

 

The first one. (Well, it's within another static function). Actually, I thought I was being clever with omitting that part:
I have a static function in SceneElement called SceneElement* SceneElement::Parse(). It's one of those times where I create on the heap:
 
    SceneElement* SceneElement::parse(const std::string &source_path, const pugi::xml_node &node)
    {
        bool visible = utility::string_to_bool( node.attribute("visible").as_string("true"), true);
        std::string name = node.attribute("name").as_string("Unnamed element");
        SceneElement* resulting_element = new SceneElement(name, visible);
 
        pugi::xml_node size_child = node.child("size");
        if(!size_child.empty())
        {
        }
 
        pugi::xml_node offset_point_child = node.child("offset_point");
        if(!offset_point_child.empty())
        {
        }
 
        pugi::xml_node offset_child = node.child("offset");
        if(!offset_child.empty())
        {
        }
 
        pugi::xml_node scale_child = node.child("scale"); /* add pixel scaling option/value or granularity value + support for descendance */
        if(!scale_child.empty())
        {
        }
 
        return resulting_element;
    }
 
This function is called from Grid* Grid::parse(), where Grid : public SceneElement
It behaves in the same way.
 
 

 

 

Are you creating a SceneElement object, or an object that in turn creates a SceneElement object, statically anywhere? In that case, that object may be constructed before the map constructors, and thus the SceneElement constructor is accessing a not-yet-constructed map object.

 

For details:  http://www.parashift.com/c++-faq/static-init-order-on-first-use.html.

 

 

 
Thanks, Elci. I'll read that now. I've got Cline at al's book, -I love how he describes best practices on parashift. Much appreciated.
 
Even if it looks like I've done something obviously wrong, I'd really appreciate if you'll further with feedback, in case I just don't get it.
But I'll read the parashift page.... I had no idea that "static initialization order fiasco" was a thing...

#2SuperVGA

Posted 26 June 2013 - 10:18 PM

Hi guys, I wanted to post a response ~8 hours ago, when GD was having issues, but I'll read Eight and Triencos reply as soon as I get the time.

 

 

 

Are you creating a SceneElement object, or an object that in turn creates a SceneElement object, statically anywhere? In that case, that object may be constructed before the map constructors, and thus the SceneElement constructor is accessing a not-yet-constructed map object.

 

Yes, I am. Actually, I thought I was being clever with omitting that part:
I have a static function in SceneElement called SceneElement* SceneElement::Parse(). It's one of those times where I create on the heap:
 
    SceneElement* SceneElement::parse(const std::string &source_path, const pugi::xml_node &node)
    {
        bool visible = utility::string_to_bool( node.attribute("visible").as_string("true"), true);
        std::string name = node.attribute("name").as_string("Unnamed element");
        SceneElement* resulting_element = new SceneElement(name, visible);
 
        pugi::xml_node size_child = node.child("size");
        if(!size_child.empty())
        {
        }
 
        pugi::xml_node offset_point_child = node.child("offset_point");
        if(!offset_point_child.empty())
        {
        }
 
        pugi::xml_node offset_child = node.child("offset");
        if(!offset_child.empty())
        {
        }
 
        pugi::xml_node scale_child = node.child("scale"); /* add pixel scaling option/value or granularity value + support for descendance */
        if(!scale_child.empty())
        {
        }
 
        return resulting_element;
    }
 
This function is called from Grid* Grid::parse(), where Grid : public SceneElement
It behaves in the same way.
 
 

 

 

Are you creating a SceneElement object, or an object that in turn creates a SceneElement object, statically anywhere? In that case, that object may be constructed before the map constructors, and thus the SceneElement constructor is accessing a not-yet-constructed map object.

 

For details:  http://www.parashift.com/c++-faq/static-init-order-on-first-use.html.

 

 

 
Thanks, Elci. I'll read that now. I've got Cline at al's book, -I love how he describes best practices on parashift. Much appreciated.
 
Even if it looks like I've done something obviously wrong, I'd really appreciate if you'll further with feedback, in case I just don't get it.
But I'll read the parashift page.... I had no idea that "static initialization order fiasco" was a thing...

#1SuperVGA

Posted 26 June 2013 - 10:17 PM

Hi guys, I wanted to post a response ~8 hours ago, when GD was having issues, but I'll read Eight and Triencos reply as soon as I get the time.

 

 

 

Are you creating a SceneElement object, or an object that in turn creates a SceneElement object, statically anywhere? In that case, that object may be constructed before the map constructors, and thus the SceneElement constructor is accessing a not-yet-constructed map object.

 

Yes, I am. Actually, I thought I was being clever with omitting that part:
I have a static function in SceneElement called SceneElement* SceneElement::Parse(). It's one of those times where I create on the heap:
 
    SceneElement* SceneElement::parse(const std::string &source_path, const pugi::xml_node &node)
    {
        bool visible = utility::string_to_bool( node.attribute("visible").as_string("true"), true);
        std::string name = node.attribute("name").as_string("Unnamed element");
        SceneElement* resulting_element = new SceneElement(name, visible);
 
        pugi::xml_node size_child = node.child("size");
        if(!size_child.empty())
        {
        }
 
        pugi::xml_node offset_point_child = node.child("offset_point");
        if(!offset_point_child.empty())
        {
        }
 
        pugi::xml_node offset_child = node.child("offset");
        if(!offset_child.empty())
        {
        }
 
        pugi::xml_node scale_child = node.child("scale"); /* add pixel scaling option/value or granularity value + support for descendance */
        if(!scale_child.empty())
        {
        }
 
        return resulting_element;
    }
 
This function is called from Grid* Grid::parse(), where Grid : public SceneElement
It behaves in the same way.
 
 

 

 

Are you creating a SceneElement object, or an object that in turn creates a SceneElement object, statically anywhere? In that case, that object may be constructed before the map constructors, and thus the SceneElement constructor is accessing a not-yet-constructed map object.

 

For details: http://www.parashift.com/c++-faq/static-init-order.html and http://www.parashift.com/c++-faq/static-init-order-on-first-use.html.

 

 

 
Thanks, Elci. I'll read that now. I've got Cline at al's book, -I love how he describes best practices on parashift. Much appreciated.
 
Even if it looks like I've done something obviously wrong, I'd really appreciate if you'll further with feedback, in case I just don't get it.
But I'll read the parashift page.... I had no idea that "static initialization order fiasco" was a thing...

PARTNERS