BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Help with Error Message "EAccessViolation".

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage)
View previous topic :: View next topic  
Author Message
Roberto Gomez Torres
Guest





PostPosted: Tue Apr 20, 2004 10:40 pm    Post subject: Help with Error Message "EAccessViolation". Reply with quote



Hello List.
Hope you can help me.

I am using Borland C++ Builder 5.0 Pro with the Update Pack 1 installed.

I have an application that was working just fine for a good time.
Then I recompiled it and no errors or warnings were reported.

But everytime I close the program (running from the IDE or as an EXE alone)
I got the following errors:

This one when running directly from Borland C++ Builder IDE and shows when I
close the app :
http://www.tiempo-digital.com/gallery/error.gif

These others when running the EXE from the Windows Explorer :
http://www.tiempo-digital.com/gallery/error1.gif
http://www.tiempo-digital.com/gallery/error2.gif


Have you seen something like this before ?
Any hints on how to fix it ?

Thanks a lot in advance.
======================
Roberto Gómez Torres
Tiempo Digital
Mexico City, Mexico
www.tiempo-digital.com
[email]roberto (AT) tiempo-digital (DOT) com[/email]
======================


Back to top
KL Chin
Guest





PostPosted: Wed Apr 21, 2004 2:52 am    Post subject: Re: Help with Error Message "EAccessViolation". Reply with quote



Hi Roberto,

Look like one of your component/package have bugs in side, mean it
did not check for NULL pointer.

Regards
KL Chin

"Roberto Gomez Torres" <roberto (AT) tiempo-digital (DOT) com> wrote

Quote:
Hello List.
Hope you can help me.

I am using Borland C++ Builder 5.0 Pro with the Update Pack 1 installed.

I have an application that was working just fine for a good time.
Then I recompiled it and no errors or warnings were reported.

But everytime I close the program (running from the IDE or as an EXE
alone)
I got the following errors:

This one when running directly from Borland C++ Builder IDE and shows when
I
close the app :
http://www.tiempo-digital.com/gallery/error.gif

These others when running the EXE from the Windows Explorer :
http://www.tiempo-digital.com/gallery/error1.gif
http://www.tiempo-digital.com/gallery/error2.gif


Have you seen something like this before ?
Any hints on how to fix it ?

Thanks a lot in advance.
======================
Roberto Gómez Torres
Tiempo Digital
Mexico City, Mexico
www.tiempo-digital.com
[email]roberto (AT) tiempo-digital (DOT) com[/email]
======================





Back to top
JD
Guest





PostPosted: Wed Apr 21, 2004 9:01 am    Post subject: Re: Help with Error Message "EAccessViolation". Reply with quote




"Roberto Gomez Torres" <roberto (AT) tiempo-digital (DOT) com> wrote:
Quote:
[...] But everytime I close the program (running from the
IDE or as an EXE alone) I got the following errors:

KL is correct in that a 3rd party component may be the cause
but I doubt it. What kind of application is it? What does it
do and how are you doing it?

In a nut shell, 'undefined behavior' - a noun - occures when
one violates the rules as defined by the standards. Once
encountered, the program is unstable from that point on
because the compiler is free (according to the standards)
to deal with it any way that it wants - including formatting
your hard drive.

An Access Violation is generated by a program attempting to
access invalid memory but not all attempts to access invalid
memory generate an AV. That's because of the way that memory
is managed by the VCL and the OS. A block a memory can be in a
state of flux where your program sees it as free but it hasn't
yet been released back to the OS. In this case, the OS doesn't
complain if you access it but according to the standards, the
program has just encountered undefined behavior.

In my experiance, the behavior you described: that it only
showed up after a recompile; has always lead back to poor
memory management.

Tracking down this problem is not going to be difficult but
it's a PITA because it's tediouse work. The first thing that
you should do is to assign NULL to all pointers as they are
defined:

char* Buffer = NULL;

If the pointer is defined as global, assign NULL to it in the
constructor:

__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
Buffer = NULL;
}

Then test all pointers before you access them:

if( Buffer ) Buffer[ 99 ] = '?';
else throw( "Buffer was invalid" );

You also need to make sure that you don't access pointers after
they have been deleted. If you set them to NULL after deletion:

delete [] Buffer;
Buffer = NULL;

the intergrity of testing the pointer before it's accessed is
maintained. It also takes care of another potential problem of
deleting a pointer twice. This works because it legal to delete
a NULL pointer. While it doesn't reveal the err of your ways,
it serves the compiler well. However, being consistant with
tracking down the offending line(s) of code, change the delete
to:

if( Buffer ) delete [] Buffer;
else throw( "Invalid deletion of Buffer" );
Buffer = NULL;

Then you need to match up all of your 'new'(s) with 'delete'(s)
and 'new[]'(s) with 'delete[]'(s):

TStringList* pList = new TStringList;
....
delete pList;

char* Buffer = new char[ 100 ];
....
delete [] Buffer;

and make sure that you aren't accessing beyond the pointers
allocated block:

char c = Buffer[ 100 ];

is undefined behavior and *might* cause and AV where as:

Buffer[ 100 ] = '?';

is destructive and worse than the first. Remember that once
your program encounters undefined behavior, all bets are off.

Keep in mind that just because are particulare compile doesn't
break, it doesn't mean that the program isn't still broken -
as demonstrated by your experiance where it was working but
now isn't. Once you start, to be sure that you've cleared the
problem, you need to complete the entire process because it's
possible that there is more than one problem.

~ JD


Back to top
Roberto Gomez Torres
Guest





PostPosted: Wed Apr 21, 2004 6:01 pm    Post subject: Re: Help with Error Message "EAccessViolation". Reply with quote

KL, JD,

Thank you so much for the help and pointers.
This problem is strange since I did not change a single line of code.

Yesterday I recompiled the same project on a Windows ME machine, with all
the same Borland C++ Builder Environment.
And the problem when I close the program is not there !!!

Will look in detail today on the Windows 2000 Pro Machine.

Thanks a lot guys.
======================
Roberto Gómez Torres
Tiempo Digital
Mexico City, Mexico
www.tiempo-digital.com
[email]roberto (AT) tiempo-digital (DOT) com[/email]
======================


Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.