Private Class Member not Initialized

Hi Guys,
I have another problem, I have a class that is used for displaying a main menu in a game that seems to be having issues with it's privatized members not being initialized. Whenever I try to assign a value to one of these members, I get a SEG FAULT error.

Here is the Class (Menu.h):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#ifndef _MENU_H
#define _MENU_H

class Menu
{
public:
    Menu(int width, int height, bool isWide);
    ~Menu();

    void DrawMenu();
    void Resize(int width, int height);
    uint Click(int x, int y); //This returns the ID of the object clicked. IF nothing was clicked, return is 0

private:
    void LoadMenuTextures(bool isWide);

    GLuint tex[4]; //There are 4 textures total
    Quad bg; //The is the background quad
    Quad btns[3]; //There are three buttons: Start, Options, and Exit/Quit
};

#endif //_MENU_H 


Here is the Implementation (Menu.cpp)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#include "Menu.h"

Menu::Menu(int width, int height, bool isWide)
{
    Resize(width, height);
    LoadMenuTextures(isWide);
}

Menu::~Menu() {}

void Menu::Resize(int width, int height)
{
    //SETUP THE BACKGROUND
    bg.x1 = 0;
    bg.y1 = 0;
    bg.x2 = width;
    bg.y2 = height;

    //SETUP THE BUTTONS
    double btnStartX = (width * 0.66666);
    double btnStartY = (height * 0.25);
    double btnWidth = (width * 0.25);
    double btnHeight = (height * 0.125);

    //SET THE BUTTONS
    btns[0].x1 = btnStartX;
    btns[0].y1 = btnStartY;
    btns[0].x2 = btnStartX + btnWidth;
    btns[0].y2 = btnStartY + btnHeight;

    btns[1].x1 = btnStartX;
    btns[1].y1 = btnStartY + (btnHeight *2);
    btns[1].x2 = btnStartX + btnWidth;
    btns[1].y2 = btnStartY + (btnHeight *3);

    btns[2].x1 = btnStartX;
    btns[2].y1 = btnStartY + (btnHeight *4);
    btns[2].x2 = btnStartX + btnWidth;
    btns[2].y2 = btnStartY + (btnHeight *5);
}

uint Menu::Click(int x, int y)
{
    //COLLISION TEST ON THE BUTTONS
    for(int i = 0; i < 3; ++i)
    {
        if(x > btns[i].x1 && y > btns[i].y1)
        {
            if(x < btns[i].x2 && y < btns[i].y2)
            {
                return (i + 1);
            }
        }
    }

    return 0;
}

void Menu::DrawMenu()
{
    glPushMatrix();

    //DRAW THE BACKGROUND
    glColor4d(1.0, 1.0, 1.0, 1.0);
    glBindTexture(GL_TEXTURE_2D, tex[0]);
    glBegin(GL_QUADS);
        glTexCoord2d(0, 0);
        glVertex2d(bg.x1, bg.y1);

        glTexCoord2d(0, 1);
        glVertex2d(bg.x1, bg.y2);

        glTexCoord2d(1, 1);
        glVertex2d(bg.x2, bg.y2);

        glTexCoord2d(1, 0);
        glVertex2d(bg.x2, bg.y1);
    glEnd();


    //DRAW THE BUTTONS
    glColor4d(1.0, 1.0, 1.0, 1.0); //The Default Color of the Buttons is Cyan

    for(int i = 0; i < 3; ++i)
    {
        glBindTexture(GL_TEXTURE_2D, tex[(i + 1)]);

        glBegin(GL_QUADS);
            glTexCoord2d(0, 0);
            glVertex2d(btns[i].x1, btns[i].y1);

            glTexCoord2d(0, 1);
            glVertex2d(btns[i].x1, btns[i].y2);

            glTexCoord2d(1, 1);
            glVertex2d(btns[i].x2, btns[i].y2);

            glTexCoord2d(1, 0);
            glVertex2d(btns[i].x2, btns[i].y1);
        glEnd();
    }

    glPopMatrix();
}

void Menu::LoadMenuTextures(bool isWide)
{
    YsRawPngDecoder *png = new YsRawPngDecoder();

    glGenTextures(4, tex);

    for(int i = 0; i < 4; ++i)
    {
        glBindTexture(GL_TEXTURE_2D, tex[i]);

        switch(i)
        {
            case 0:
            {
                if(isWide)
                {
                    png->Decode("Data/Art/16by9/menubg.png");
                }

                else
                {
                    png->Decode("Data/Art/4by3/menubg.png");
                }
                
                gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, png->wid, png->hei, GL_RGBA, GL_UNSIGNED_BYTE, png->rgba);

                continue;
            }

            case 1:
            {
                if(isWide)
                {
                    png->Decode("Data/Art/16by9/menuStart.png");
                }

                else
                {
                    png->Decode("Data/Art/4by3/menuStart.png");
                }
                
                gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, png->wid, png->hei, GL_RGBA, GL_UNSIGNED_BYTE, png->rgba);

                continue;
            }

            case 2:
            {
                if(isWide)
                {
                    png->Decode("Data/Art/16by9/menuOpt.png");
                }

                else
                {
                    png->Decode("Data/Art/4by3/menuOpt.png");
                }
                
                gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, png->wid, png->hei, GL_RGBA, GL_UNSIGNED_BYTE, png->rgba);

                continue;
            }

            case 3:
            {
                if(isWide)
                {
                    png->Decode("Data/Art/16by9/menuExit.png");
                }

                else
                {
                    png->Decode("Data/Art/4by3/menuExit.png");
                }
                
                gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, png->wid, png->hei, GL_RGBA, GL_UNSIGNED_BYTE, png->rgba);

                continue;
            }
        }
    }

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

    free(png);
}


Here is how the custom data types are defined as so:
1
2
3
4
5
6
typedef unsigned int uint;

typedef struct _Quad
{
    double x1, y1, x2, y2;
}Quad;


(If it is an help, here is the disassembly):
1
2
3
4
5
    //SETUP THE BACKGROUND
    bg.x1 = 0;
004050A9  mov         eax,dword ptr [this] 
004050AC  fldz             
004050AE  fstp        qword ptr [eax+10h] 


Sorry about the MASSIVE post, I didn't want to leave any details out.

The issues isn't with just this class, but ALL my classes that use Quad. It didn't used to do this. I haven't actually changed any of this code since I wrote it. When I wrote it, it compiled fine and ran well. Now it compiles, but won't run.

Also, I am using MSVC 2008, Win32 API, OpenGL, OpenAL, libsndfile, and a PNG library called YsPng.
I see you're mixing new and free. That's bad. If you create using new, destroy using delete.
Ok,
I replaced free with delete.

I also fixed my own problem, It turned out that this code is perfectly fine. The problem used to lie in my main file where Menu::Resize was getting called before the constructor! So I fixed it there, now it works just fine!

Thank you for pointing out that I shouldn't mix new and free.
I'll use delete from now on.
Topic archived. No new replies allowed.