Board index » cppbuilder » Resize, How to Keep Borland from Crashing

Resize, How to Keep Borland from Crashing

Our users have been very annoyed at us engineers for creating an application
that crashes when a window is closed.  And so, yesterday, two of us devoted
the entire day to finding the bug.  We checked every single allocation and
deallocation, all of our DC handling, and general flow of our application,
to no avail.

Out of sheer desperation, we decided to check the behavior of the default
MDI application supplied by Borland.  To our amazement, it crashes as
consistently and vehemently as our own application.

To duplicate this behavior do the following:

1) Select MDI Application from the Projects page of the New Items dialogue
in Borland C++ Builder,
2) In the ChildWin Unit, supply an OnResize function, we used the default
FormResize function that is created for you when you double click in the
OnResize Event field,
3) Place a line of code in the FormResize function such as bool stop = true;
and put a break point on that line,
4) Run the application,
5) Open two new windows,
6) Maximize a window,
7) Close the window.

At this point you will experience the crash of Borland and should re-boot
your computer to restore your ram.

As far as we can determine, what has happened is the OnResize event was
called after the window was destroyed.  Hence, the memory containing the
code for FormResize has already been de-allocated, yet there is a pointer to
it somewhere, and execution is jumping to that point.  This is only a guess.
We have not devoted time to debugging the assembly.

This is important to us because in our application, FormResize uses data and
functions to handle re-rendering of an image in the window.  When the window
is maximized and then closed, it appears that FormResize is called after the
window is destroyed, and the application crashes because the data and
functions are no longer valid.

Our question is, how can we prevent this from crashing our application?

 

Re:Resize, How to Keep Borland from Crashing


<DAB> said,
Quote

> To duplicate this behavior do the following:

> 1) Select MDI Application from the Projects page of the New Items dialogue
> in Borland C++ Builder,
> 2) In the ChildWin Unit, supply an OnResize function, we used the default
> FormResize function that is created for you when you double click in the
> OnResize Event field,
> 3) Place a line of code in the FormResize function such as bool stop = true;
> and put a break point on that line,
> 4) Run the application,
> 5) Open two new windows,
> 6) Maximize a window,
> 7) Close the window.

> At this point you will experience the crash of Borland and should re-boot
> your computer to restore your ram.

I didn't.  What version of bcb are you using?
--
liz

Re:Resize, How to Keep Borland from Crashing


Borland C++ Builder Professional Version 5.0 (Build 12.34) Update Pack 1
Windows 98 (Build 4.10.2222 A)

Quote
"liz albin" <lizalbinNotT...@yahoo.comNOT> wrote in message

news:MPG.1702b1be175eb58298993c@forums.borland.com...
Quote
> <DAB> said,

> > To duplicate this behavior do the following:

> > 1) Select MDI Application from the Projects page of the New Items
dialogue
> > in Borland C++ Builder,
> > 2) In the ChildWin Unit, supply an OnResize function, we used the
default
> > FormResize function that is created for you when you double click in the
> > OnResize Event field,
> > 3) Place a line of code in the FormResize function such as bool stop =
true;
> > and put a break point on that line,
> > 4) Run the application,
> > 5) Open two new windows,
> > 6) Maximize a window,
> > 7) Close the window.

> > At this point you will experience the crash of Borland and should
re-boot
> > your computer to restore your ram.

> I didn't.  What version of bcb are you using?
> --
> liz

Re:Resize, How to Keep Borland from Crashing


Quote
DAB wrote:

> Out of sheer desperation, we decided to check the behavior of the default
> MDI application supplied by Borland.  To our amazement, it crashes as
> consistently and vehemently as our own application.

I do not have crashes, but found peculiar things.

To trach down the behaviour I placed a TMemo on the MDI mainform.

Then in the OnClose event of the childwindow I placed the following code:

MainForm->Memo1->Lines->Add ( "Close " + Caption );

and in the OnResize event of the childform

MainForm->Memo1->Lines->Add ( "OnResize " + Caption);
// don't forget to include main.h

Now if you follow the steps as you indicated you will
find, closing a window for the first time, an  "OnRize"
for the closing window and three OnResize's for the other
window.

Upon closing the other window, no OnResize is triggered.

So something is out of control.

You can easily prevent code in an OnResize event not to
execute after OnClose() if you declare a private int closing
and make it TRUE in OnClose().

Add as first statement in OnResize():

if ( closing ) return;

Hans.

Re:Resize, How to Keep Borland from Crashing


I tried but could not duplicate the problem. It worked as expacted.

CB5 PRO, dual p3 933mhz

Tom Woodrow

Re:Resize, How to Keep Borland from Crashing


I'm also on Win98 and it crashed here also.

Quote
<DAB> wrote in message news:3c98e34a$1_2@dnews...
> Our users have been very annoyed at us engineers for creating an
application
> that crashes when a window is closed.  And so, yesterday, two of us
devoted
> the entire day to finding the bug.  We checked every single allocation and
> deallocation, all of our DC handling, and general flow of our application,
> to no avail.

> Out of sheer desperation, we decided to check the behavior of the default
> MDI application supplied by Borland.  To our amazement, it crashes as
> consistently and vehemently as our own application.

> To duplicate this behavior do the following:

<snip>

Re:Resize, How to Keep Borland from Crashing


Thank you all for looking into this.

For those of you that are getting the crash, you can imagine how difficult
it is to debug this problem, because Borland locks up and you cant check
anything; no values, stacks, nothing.  You are forced to shut down Borland,
and usually need to reboot because this crash seems to wipe portions of ram.

For those who are not getting the crash, you have an opportunity to verify
my guess.  Set breakpoints in the child windows destructor, and in the
resize handler.  Look at the value of the this pointer when the destructor
is called, and in the subsequent call to resize.  I would be very interested
in what the value is in resize after the destructor was called.  And then if
you could inspect the call stack from resize.

We are currently using the flag method to determine if the window has been
destroyed.  But something about checking a flag in code that should not even
be in ram anymore bothers me.  What if another process comes along and
overwrites that code before Borland gets to it?

Re:Resize, How to Keep Borland from Crashing


Quote
DAB wrote:

> For those who are not getting the crash, you have an opportunity to verify
> my guess.

It would be nice if you replied to the suggestions I did first.

Do you use OnCreate()/OnDestroy() ?

Hans.

Re:Resize, How to Keep Borland from Crashing


Quote
> Now if you follow the steps as you indicated you will
> find, closing a window for the first time, an  "OnRize"
> for the closing window and three OnResize's for the other
> window.

Does the closing windows OnResize happen after the windows destructor?
If it does, then the following code will be run with a 'this' pointer that
is not valid...
Quote
> You can easily prevent code in an OnResize event not to
> execute after OnClose() if you declare a private int closing
> and make it TRUE in OnClose().

> Add as first statement in OnResize():

> if ( closing ) return;

Re:Resize, How to Keep Borland from Crashing


Quote
> Now if you follow the steps as you indicated you will
> find, closing a window for the first time, an  "OnRize"
> for the closing window and three OnResize's for the other
> window.

Does the closing windows OnResize happen after the windows destructor?
If it does, then the following code will be run with a 'this' pointer that
is not valid...
Quote
> You can easily prevent code in an OnResize event not to
> execute after OnClose() if you declare a private int closing
> and make it TRUE in OnClose().

> Add as first statement in OnResize():

> if ( closing ) return;

Re:Resize, How to Keep Borland from Crashing


is this thread dead??
Quote
<DAB> wrote in message news:3c9a8bda$1_1@dnews...

> > Now if you follow the steps as you indicated you will
> > find, closing a window for the first time, an  "OnRize"
> > for the closing window and three OnResize's for the other
> > window.

> Does the closing windows OnResize happen after the windows destructor?
> If it does, then the following code will be run with a 'this' pointer that
> is not valid...

> > You can easily prevent code in an OnResize event not to
> > execute after OnClose() if you declare a private int closing
> > and make it TRUE in OnClose().

> > Add as first statement in OnResize():

> > if ( closing ) return;

Other Threads