C++ altering the wrong class members

F

fake

What exactly does the line:
rGfxOptionsWnd* m_pGfxOptionsWnd;
do?

I have chased this bug and narrowed it down to something that I believe
should not happen and I don't even know what could possibly cause it to
happen.

My basic application structure is simple.

An Application Class,
An App Class derived from the Application Class

The application class has a member varible which is a Paramater class

e.g.
Application {

Public:
Param_class m_Params;

};

In it's constructor Application instalises m_Params values.
m_Params.Window.bWindowed = false;
m_Params.Window.width = 500;
m_Params.Window.height = 500;
m_Params.Window.icon = NULL;
m_Params.Window.title = "rDirectXApp Default Window Title";
m_Params.Window.wnd_type = RJM_WNDT2;
m_Params.Window.res_x = 0;
m_Params.Window.res_y = 0;
m_Params.Window.esc_to_quit = true;

In it's Constructor, App (Derived from Application) then alters some of the
values as nessecary.

m_Params.Window.icon = (const char *) IDI_ICON1;
m_Params.Window.title = "Super Game in this window!!!";
m_Params.Window.bWindowed = true;

m_Params.Window.wnd_type = RJM_WNDT5;
m_Params.Window.width = 600;
m_Params.Window.height = 300;
m_Params.Window.bWindowed = true;
m_Params.Window.res_x = 100;
m_Params.Window.res_y = 100;

Now I can compile and run this code perfectly. I have set break points on
each line shown here and I can watch the values as they go through this
process and change.

I have another completely empty class, just an empty constructor and
destructor.
RGfxOptions. I add the following line into Applications private section:

rGfxOptionsWnd* m_pGfxOptionsWnd;

With this line in the program I run the debug version of the program.

The Application constructor sets up m_Param exactly as it's supposed to.

Control then passes to App's constructor.
When: m_Params.Window.icon = (const char *) IDI_ICON1;
executes, m_Param.Height changes (nothing else)

when m_Params.Window.title = "Super Game in this window!!!";
executes, m_Params.title changes but the new value is corrupt

when m_Params.Window.bWindowed = true;
executes, nothing in m_Params alters

when m_Params.Window.wnd_type = RJM_WNDT5;
executes, nothing

when m_Params.Window.width = 600;
executes bWindowed alters

when m_Params.Window.height = 300;
executes, width alters

when m_Params.Window.bWindowed = true;
executes, nothing

when m_Params.Window.res_x = 100;
executes, wndtype alters but to an invalid value

and after m_Params.Window.res_y = 100;
the program crashes because of the invalid data.

But with the line:
rGfxOptionsWnd* m_pGfxOptionsWnd;
remmed out it all works perfectly.

Can anyone help? What does that line do? How is it possible that the
statement altering the height actually alters the width member variables? I
havn't used or refered to m_pGrgOptionsWnd anywhere at all in my code. How
can simply adding a pointer member varible to my class have this effect?

Thanks in advance for any suggestions. I have absoultly no ideas at the
moment at all!
 
T

Thomas Wintschel

What exactly does the line:
rGfxOptionsWnd* m_pGfxOptionsWnd;
do?

I have chased this bug and narrowed it down to something that I believe
should not happen and I don't even know what could possibly cause it to
happen.

My basic application structure is simple.

An Application Class,
An App Class derived from the Application Class

The application class has a member varible which is a Paramater class

e.g.
Application {

Public:
Param_class m_Params;

};

In it's constructor Application instalises m_Params values.
m_Params.Window.bWindowed = false;
m_Params.Window.width = 500;
m_Params.Window.height = 500;
m_Params.Window.icon = NULL;
m_Params.Window.title = "rDirectXApp Default Window Title";
m_Params.Window.wnd_type = RJM_WNDT2;
m_Params.Window.res_x = 0;
m_Params.Window.res_y = 0;
m_Params.Window.esc_to_quit = true;

In it's Constructor, App (Derived from Application) then alters some of the
values as nessecary.

m_Params.Window.icon = (const char *) IDI_ICON1;
m_Params.Window.title = "Super Game in this window!!!";
m_Params.Window.bWindowed = true;

m_Params.Window.wnd_type = RJM_WNDT5;
m_Params.Window.width = 600;
m_Params.Window.height = 300;
m_Params.Window.bWindowed = true;
m_Params.Window.res_x = 100;
m_Params.Window.res_y = 100;

Now I can compile and run this code perfectly. I have set break points on
each line shown here and I can watch the values as they go through this
process and change.

I have another completely empty class, just an empty constructor and
destructor.
RGfxOptions. I add the following line into Applications private section:

rGfxOptionsWnd* m_pGfxOptionsWnd;

With this line in the program I run the debug version of the program.

The Application constructor sets up m_Param exactly as it's supposed to.

Control then passes to App's constructor.
When: m_Params.Window.icon = (const char *) IDI_ICON1;
executes, m_Param.Height changes (nothing else)

when m_Params.Window.title = "Super Game in this window!!!";
executes, m_Params.title changes but the new value is corrupt

when m_Params.Window.bWindowed = true;
executes, nothing in m_Params alters

when m_Params.Window.wnd_type = RJM_WNDT5;
executes, nothing

when m_Params.Window.width = 600;
executes bWindowed alters

when m_Params.Window.height = 300;
executes, width alters

when m_Params.Window.bWindowed = true;
executes, nothing

when m_Params.Window.res_x = 100;
executes, wndtype alters but to an invalid value

and after m_Params.Window.res_y = 100;
the program crashes because of the invalid data.

But with the line:
rGfxOptionsWnd* m_pGfxOptionsWnd;
remmed out it all works perfectly.

Can anyone help? What does that line do? How is it possible that the
statement altering the height actually alters the width member variables? I
havn't used or refered to m_pGrgOptionsWnd anywhere at all in my code. How
can simply adding a pointer member varible to my class have this effect?

Thanks in advance for any suggestions. I have absoultly no ideas at the
moment at all!

It is as though the changes to 'Application' are not triggering a
fresh compilation of 'App'. If this is the case then the constructor
code
(in App) could be using the wrong offsets into the objects storage
location. You can try doing a clean build (or at least verifying that
the
App source code is recompiled each time you make changes to your
declaration of Application).

Tom
 
R

Ron Natalie

What exactly does the line:
rGfxOptionsWnd* m_pGfxOptionsWnd;
do?

Hard to tell in isolation, but it looks like it is probaby a definition of a member
variable of type pointer to rGfxOptionsWnd what ever that is.

rGfxOptionsWnd* m_pGfxOptionsWnd;

So, do you set this variable to anything?

What the hell is IDI_ICON1 and why are you bashing it with a cast?

Hard to tell, with the scant bit of info you provide. What is the type of
title? What the hell is the rest of the param definition?
 
D

dwrayment

What exactly does the line:
rGfxOptionsWnd* m_pGfxOptionsWnd;
do?

By itself no constructors will be called until a call to new. So it should
do nothing.

I have chased this bug and narrowed it down to something that I believe
should not happen and I don't even know what could possibly cause it to
happen.

My basic application structure is simple.

An Application Class,
An App Class derived from the Application Class

The application class has a member varible which is a Paramater class

e.g.
Application {

Public:
Param_class m_Params;

};

In it's constructor Application instalises m_Params values.
m_Params.Window.bWindowed = false;
m_Params.Window.width = 500;
m_Params.Window.height = 500;
m_Params.Window.icon = NULL;
m_Params.Window.title = "rDirectXApp Default Window Title";
m_Params.Window.wnd_type = RJM_WNDT2;
m_Params.Window.res_x = 0;
m_Params.Window.res_y = 0;
m_Params.Window.esc_to_quit = true;

In it's Constructor, App (Derived from Application) then alters some of the
values as nessecary.

m_Params.Window.icon = (const char *) IDI_ICON1;
m_Params.Window.title = "Super Game in this window!!!";
m_Params.Window.bWindowed = true;

m_Params.Window.wnd_type = RJM_WNDT5;
m_Params.Window.width = 600;
m_Params.Window.height = 300;
m_Params.Window.bWindowed = true;
m_Params.Window.res_x = 100;
m_Params.Window.res_y = 100;

Now I can compile and run this code perfectly. I have set break points on
each line shown here and I can watch the values as they go through this
process and change.

I have another completely empty class, just an empty constructor and
destructor.
RGfxOptions. I add the following line into Applications private section:

rGfxOptionsWnd* m_pGfxOptionsWnd;

Since any process can only have one application instance running id
recommand making the m_Params a static declaration. That may even
solve your problem since there will be one global copy of m_params for all
application classes. Worst case it may be easier to find out what the
problem
is.



With this line in the program I run the debug version of the program.

The Application constructor sets up m_Param exactly as it's supposed to.

Control then passes to App's constructor.
When: m_Params.Window.icon = (const char *) IDI_ICON1;
executes, m_Param.Height changes (nothing else)

when m_Params.Window.title = "Super Game in this window!!!";
executes, m_Params.title changes but the new value is corrupt
What exactly is "title" a char *, a string class of some kind?
 
M

Martijn Lievaart

What exactly does the line:
rGfxOptionsWnd* m_pGfxOptionsWnd;
do?

I have chased this bug and narrowed it down to something that I believe
should not happen and I don't even know what could possibly cause it to
happen.

Do a complete rebuild. Turn of precompiled headers. What you are seeing is
the effects of an incomplete build. Not all parts of your build have the
same view of the layout of your classes.

BTW, this is more of a question about your build-system, you'll get better
answers in a group devoted to that.

HTH,
M4
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,159
Messages
2,570,883
Members
47,414
Latest member
djangoframe

Latest Threads

Top