vector push back runtime crashing

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Counter = 0;
        int counter2 = 0;

        GreenBox = al_load_bitmap("Media/Images/GreenBox.png");

        int Xincrement = 270;
        int Yincrement = 50;

        while(counter2 != 99)
        {
            while(Counter != 9)
            {
                LevelOne.boxes.push_back(Box(Xincrement, Yincrement, 40, 20, GreenBox)); 
//debugger says this is the line thats causing it (the one above)

                Xincrement += 45;
                Counter++;
            }

            Xincrement = 270;
            Yincrement += 50;

            Counter = 0;
        }


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
class rectangle
{
    private:

    int x,y,brx,bry,w,h;

    public:

    rectangle(int xpos , int ypos , int width , int height): 
x(xpos), y(ypos), brx(xpos + width - 1), bry(ypos + height - 1), w(width), h(height){}

    inline bool Overlaps(const rectangle& r);
    int X() {return x;}
    int Y() {return y;}
    int BRX() {return brx;}
    int BRY() {return bry;}
    int W() {return w;}
    int H() {return h;}
};

    inline bool rectangle::Overlaps(const rectangle& r)
    {
        return !(((x > r.brx) || (brx < r.x)) || ((y > r.bry) || (bry < r.y)));
    }

class Box
{
    public:

    rectangle area;
    ALLEGRO_BITMAP* Image;
    bool IsBroken;

     Box(int xpos , int ypos , int width , int height , ALLEGRO_BITMAP* Image):
 area(xpos,ypos,width,height), Image(Image), IsBroken(false){}
};


class Level
{
    public:

    vector<Box> boxes;

};

Level LevelOne;


why is this crashing? I've been trying to figure out for a couple days but I'm confused. I was using the same exact line before and it worked fine but i just changed the loop around. and now its saying it doesnt work anymore. heres the debugger errors if anyone can decipher what that mean exactly:

#0 00000000 0x00402260 in __cxa_throw() (??:??)
#1 00000000 0x00403275 in operator new() (??:??)
#2 00420766 __gnu_cxx::new_allocator<Box>::allocate(this=0x22ff04, __n=33554432)
#3 004510A2 std::_Vector_base<Box, std::allocator<Box> >::_M_allocate(this=0x22ff04, __n=33554432)
#4 00467AE9 std::vector<Box, std::allocator<Box> >::_M_insert_aux(this=0x22ff04, __position={_M_current = 0x46270020}, __x=@0x22faa8)
#5 00467E24 std::vector<Box, std::allocator<Box> >::push_back(this=0x22ff04, __x=@0x22faa8)
#6 0041D05D Core::SetupLevelOne(this=0x22fb78)
#7 0041CC75 Core::LoadResources(this=0x22fb78)
#8 004013BC main()
The outer loop is a while true. You run out of memory
I switched it to a for loop and now it works. but all my while loops are crashing now.
Topic archived. No new replies allowed.