Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: rectangle shape problem  (Read 1260 times)

0 Members and 1 Guest are viewing this topic.

EGYPTIAN CODER

  • Newbie
  • *
  • Posts: 32
    • View Profile
    • Email
rectangle shape problem
« on: April 24, 2017, 05:26:27 pm »
hello every one ;
for the past two days I was working on a very simple project
that allow me to draw and modify rectangle shapes
the program save the vector of rectangle shape very easily but when it comes to loading them
then odd exceptions thrown  when drawing them
so what is the problem here

                std::ifstream reader(file_name.c_str(),std::ios::binary|std::ios::ate);
               

                unsigned int bytes=reader.tellg();
               
                reader.close();
                reader.open(file_name.c_str(),std::ios::binary);

               
                for(unsigned int ds=0;ds<(bytes/sizeof(sf::RectangleShape));ds++)
                        rectangles.push_back(sf::RectangleShape(sf::Vector2f(1,1)));

                reader.read((reinterpret_cast<char*> (&rectangles[0])),bytes);

               
                reader.close();
 

 
« Last Edit: April 24, 2017, 05:39:50 pm by EGYPTIAN CODER »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: rectangle shape problem
« Reply #1 on: April 24, 2017, 06:43:55 pm »
Serializing and deserializing data structures is a little more complicated than making raw copies of objects from memory to file and vice versa. They may contain pointers (addresses) that mean nothing once you quit the application or even destroy the objects. You must decompose what makes a sf::RectangleShape (a position, a size, a color, etc.), and explicitly read/write these values one by one using your own format, either binary or text.

I really suggest that you read some good documentation on serialization.
Laurent Gomila - SFML developer

EGYPTIAN CODER

  • Newbie
  • *
  • Posts: 32
    • View Profile
    • Email
Re: rectangle shape problem
« Reply #2 on: April 24, 2017, 06:59:39 pm »
thanks

 

anything