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

Author Topic: std::vector problem.  (Read 1881 times)

0 Members and 2 Guests are viewing this topic.

kidlovegamedev

  • Newbie
  • *
  • Posts: 3
    • View Profile
std::vector problem.
« on: November 25, 2010, 01:56:27 pm »
Hi guys. I have a little problem with my first C++ project.

I have this code:
Code: [Select]

    //creating vectors
    std::vector<float> pathX_0;
    std::vector<float> pathY_0;
    std::vector<float> pathX_1;
    std::vector<float> pathY_1;
    //fill vectors with values - vector 0
    pathX_0.push_back(420);
    pathY_0.push_back(147);
    pathX_0.push_back(610);
    pathY_0.push_back(265);
    pathX_0.push_back(210);
    pathY_0.push_back(470);
    // vector 1
    pathX_1.push_back(430);
    pathY_1.push_back(147);
    pathX_1.push_back(620);
    pathY_1.push_back(265);
    pathX_1.push_back(230);
    pathY_1.push_back(470);


And when compile there no error or warnings. But when game start give a error "An unhandled win32 exception occured in MyGameName.exe [1940].";

When I delete a second path's push_back and code become like this:
Code: [Select]

    //creating vectors
    std::vector<float> pathX_0;
    std::vector<float> pathY_0;
    std::vector<float> pathX_1;
    std::vector<float> pathY_1;
    //fill vectors with values - vector 0
    pathX_0.push_back(420);
    pathY_0.push_back(147);
    pathX_0.push_back(610);
    pathY_0.push_back(265);
    pathX_0.push_back(210);
    pathY_0.push_back(470);


And there no error. I will be happy if someone give me a little help.
EDIT: Sorry for that i post on wrong place.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
std::vector problem.
« Reply #1 on: November 25, 2010, 02:22:08 pm »
You should use a debugger to see what's happening and where. With Windows IDEs it's as simple as pressing F5.

You should also use structures
Code: [Select]
struct Point
{
    float X, Y;
};

struct PathElement
{
    Point P0, P1;
};

std::vector<PathElement> path;

(unless I misunderstood what your code is supposed to do).
Laurent Gomila - SFML developer

kidlovegamedev

  • Newbie
  • *
  • Posts: 3
    • View Profile
std::vector problem.
« Reply #2 on: November 25, 2010, 02:43:54 pm »
Thanks for your reply Laurent!

That is the result from debuging:
Code: [Select]
Starting debugger:
done
Registered new type: wxString
Registered new type: STL String
Registered new type: STL Vector
Setting breakpoints
(no debugging symbols found)
Debugger name and version: GNU gdb 6.8
Child process PID: 3212
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
Program received signal SIGSEGV, Segmentation fault.
In ?? () ()


I'm making a paths where object will move.

EDIT: That I understand is maybe I overwrite a memory?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
std::vector problem.
« Reply #3 on: November 25, 2010, 02:55:30 pm »
Quote
Program received signal SIGSEGV, Segmentation fault.
In ?? () ()

After this point, the debugger should point to the location of the crash in your source code. If it's happening in the std::vector class (or any class not written by you), you must walk back the callstack until you find a function which belongs to your code. The callstack window is available in the debug options, if it's not shown by default.

And make sure that you're compiling in debug configuration, otherwise the debugger won't be able to give you any relevant information.

In case you don't understand everything from my post, there are also tutorials for learning how to use the debugger ;)
In fact everyone should learn (and then use intensively) the debugger, I can't even imagine writing code without it.
Laurent Gomila - SFML developer

kidlovegamedev

  • Newbie
  • *
  • Posts: 3
    • View Profile
std::vector problem.
« Reply #4 on: November 25, 2010, 03:21:30 pm »
Really thanks for your answers Laurent.
I found the problem.

 

anything