Re: C++ altering the wrong class members

From: Thomas Wintschel (thomas_at_portal.ca)
Date: 01/02/04


Date: Fri, 02 Jan 2004 00:28:22 GMT


<fake@reply-address.com> wrote in message
news:bt2ank$jb8$1@news6.svr.pol.co.uk...
> 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



Relevant Pages

  • Re: C++ altering the wrong class members
    ... > In it's constructor Application instalises m_Params values. ... > executes, m_Params.title changes but the new value is corrupt ... > executes, nothing in m_Params alters ... > the program crashes because of the invalid data. ...
    (comp.lang.cpp)
  • C++ altering the wrong class members
    ... rGfxOptionsWnd* m_pGfxOptionsWnd; ... In it's constructor Application instalises m_Params values. ... App then alters some of the ... executes, m_Params.title changes but the new value is corrupt ...
    (comp.lang.cpp)
  • Re: Finding heigth and widthof image
    ... That will produce a syntax error. ... closing parenthesis following the arguments list for the constructor. ... expression, with optional Identifier, as a constructor. ... fnname and the second executes it. ...
    (microsoft.public.scripting.jscript)
  • Re: performance Winxp vs Linux
    ... Re: 'low' CPU consumption ... A benchmark app we use executes in a given time on a new Win2K box. ... Long story short - Under XP, drivers from the motherboard driver CD had ...
    (comp.lang.tcl)
  • Re: DAMAGE after client block
    ... you are causing memory damage. ... I could post the whole contents of the CProgressWnd class, ... said I've slimmed it down to the point that none of the code executes. ... The constructor is effectively "empty" because its first statement is ...
    (microsoft.public.vc.mfc)