Board index » cppbuilder » Inside IDE no problems, outside IDE exception generated

Inside IDE no problems, outside IDE exception generated


2004-11-09 05:42:51 PM
cppbuilder11
Hi,
I have a problem running the executable outside of my Borland C++ Builder
IDE. Within the IDE, there's no problem and the program runs flawlessly, but
outside the IDE I get a "floating point overflow" exception.
Background info:
I wrote a piece of code too large to fit in here, but summarizing it's code
that performs matrix operations on fairly large matrices, all with double
precision floating point. Matrices are inverted, multiplied, determinants
calculated etc. The size of the matrices are anywhere between 6,000 x 1 and
60,000 x 1, and some smaller ones.
I log the calculation results to a text file and I can clearly see that the
results are perfect and nothing has gone wrong when I run it from within the
IDE. Believe me, if anything would go wrong but I would never see an
exception, I could ALWAYS tell by the results something had gone wrong.
Now when run the executable produced by CPP Builder from Windows Explorer
(IDE open or closed, doesn't matter), I get a "floating point overflow"
exception!! This program is exactly the same as in the IDE, so I have
absolutely NO IDEA why this is happening.
Sure, I suspected that during the matrix operations I'm probably causing the
overflow, but why doesn't that seem to be a problem when running within the
IDE, moreover it produces the right results?? Did anyone experience this
before??
Thanks...
 
 

Re:Inside IDE no problems, outside IDE exception generated

#include <fastmath.h>instead of #include <math.h>everywhere you use it.
--
Mark Jacobs
DK Computing
www.dkcomputing.co.uk
"Ivar Meijer" < XXXX@XXXXX.COM >wrote in message
| I have a problem running the executable outside of my Borland C++ Builder
| IDE. Within the IDE, there's no problem and the program runs flawlessly, but
| outside the IDE I get a "floating point overflow" exception.
 

Re:Inside IDE no problems, outside IDE exception generated

Thanks for the suggestion Mark... this at least caused the exception to stay
away, but looking at my calculation results, it still produces the wrong
results.
I read in a file that contains about 64,000 (N) points and put them in a
array of doubles (N*4). I perform multiplications and additions (and a lot
of them when determining determinants of a 4x4 matrix for example) and do
stuff like multiply the (N*4) matrix with the (4x4) one. To cut a long story
short, the problem is within these parts.
However, it still doesn't explain why there is absolutely no problem
whatsoever when running inside the IDE....
Does the IDE have a different kind of memory management or something?
Thanks,
Ivar
"Ivar Meijer" < XXXX@XXXXX.COM >schreef in bericht
Hi,
I have a problem running the executable outside of my Borland C++ Builder
IDE. Within the IDE, there's no problem and the program runs flawlessly, but
outside the IDE I get a "floating point overflow" exception.
Background info:
I wrote a piece of code too large to fit in here, but summarizing it's code
that performs matrix operations on fairly large matrices, all with double
precision floating point. Matrices are inverted, multiplied, determinants
calculated etc. The size of the matrices are anywhere between 6,000 x 1 and
60,000 x 1, and some smaller ones.
I log the calculation results to a text file and I can clearly see that the
results are perfect and nothing has gone wrong when I run it from within the
IDE. Believe me, if anything would go wrong but I would never see an
exception, I could ALWAYS tell by the results something had gone wrong.
Now when run the executable produced by CPP Builder from Windows Explorer
(IDE open or closed, doesn't matter), I get a "floating point overflow"
exception!! This program is exactly the same as in the IDE, so I have
absolutely NO IDEA why this is happening.
Sure, I suspected that during the matrix operations I'm probably causing the
overflow, but why doesn't that seem to be a problem when running within the
IDE, moreover it produces the right results?? Did anyone experience this
before??
Thanks...
 

{smallsort}

Re:Inside IDE no problems, outside IDE exception generated

Try using CodeGuard to find the problem.
It works outside the IDE (but it may use a different memory manager again
and thus not show up the problem)
But it's still worth a try as it often finds bugs like this.
HTH Pete
"Ivar Meijer" < XXXX@XXXXX.COM >wrote in message
Quote
Thanks for the suggestion Mark... this at least caused the exception to
stay
away, but looking at my calculation results, it still produces the wrong
results.

I read in a file that contains about 64,000 (N) points and put them in a
array of doubles (N*4). I perform multiplications and additions (and a lot
of them when determining determinants of a 4x4 matrix for example) and do
stuff like multiply the (N*4) matrix with the (4x4) one. To cut a long
story
short, the problem is within these parts.

However, it still doesn't explain why there is absolutely no problem
whatsoever when running inside the IDE....
Does the IDE have a different kind of memory management or something?
 

Re:Inside IDE no problems, outside IDE exception generated

Check if you have some local variables (stack) not initialized
 

Re:Inside IDE no problems, outside IDE exception generated

Perhaps you can try to debug the application after it has started. This
might give you a chance to see what's happening. Launch the application
from outside the IDE then open your project in BCB. Choose "Run | Attach to
Process" from the menu and locate your app in the dialog.
HTH,
- Clayton
 

Re:Inside IDE no problems, outside IDE exception generated

On Tue, 9 Nov 2004 10:42:51 +0100, "Ivar Meijer"
< XXXX@XXXXX.COM >wrote:
Quote
Hi,

I have a problem running the executable outside of my Borland C++ Builder
IDE. Within the IDE, there's no problem and the program runs flawlessly, but
outside the IDE I get a "floating point overflow" exception.
Hi Ivar,
AFAIK the IDE does catch / handle some exceptions for you. Look under
Tools | De{*word*81} Options
Of the 4 pages 2 are related to exceptions: Language- & OS exceptions.
You can control which of the language exceptions should be ignored and
how the OS exceptions should be handled.
I remember that I never quite understood the description in the help
text, but you might want to try some of the options Builder offers you
there.
HTH
Helmut Giese
 

Re:Inside IDE no problems, outside IDE exception generated

Thanks for all your great help guys. I will try one thing at a time and post
another message when I have some results...
Thanks a lot!!!
Ivar
"Ivar Meijer" < XXXX@XXXXX.COM >schreef in bericht
Hi,
I have a problem running the executable outside of my Borland C++ Builder
IDE. Within the IDE, there's no problem and the program runs flawlessly, but
outside the IDE I get a "floating point overflow" exception.
Background info:
I wrote a piece of code too large to fit in here, but summarizing it's code
that performs matrix operations on fairly large matrices, all with double
precision floating point. Matrices are inverted, multiplied, determinants
calculated etc. The size of the matrices are anywhere between 6,000 x 1 and
60,000 x 1, and some smaller ones.
I log the calculation results to a text file and I can clearly see that the
results are perfect and nothing has gone wrong when I run it from within the
IDE. Believe me, if anything would go wrong but I would never see an
exception, I could ALWAYS tell by the results something had gone wrong.
Now when run the executable produced by CPP Builder from Windows Explorer
(IDE open or closed, doesn't matter), I get a "floating point overflow"
exception!! This program is exactly the same as in the IDE, so I have
absolutely NO IDEA why this is happening.
Sure, I suspected that during the matrix operations I'm probably causing the
overflow, but why doesn't that seem to be a problem when running within the
IDE, moreover it produces the right results?? Did anyone experience this
before??
Thanks...
 

Re:Inside IDE no problems, outside IDE exception generated

Actually, if you are only getting the problem of inaccurate calculation when
the number of elements is large, then it could be stack overflow issues. These
can easily be addressed by going to Project, Options and go to the Linker Tab.
Under PE file options, you can set assorted heap and stack sizes. I set these
and let them be the default settings for all future projects (I never get
stack problems with these!) :-
Min Stack Size 0x00004000
Max Stack Size 0x01000000
Min Heap Size 0x00001000
Max Heap Size 0x01000000
Image Base 0x00400000
HTH,
--
Mark Jacobs
DK Computing
www.dkcomputing.co.uk
"Ivar Meijer" < XXXX@XXXXX.COM >wrote in message
| Thanks for all your great help guys. I will try one thing at a time and post
| another message when I have some results...
 

Re:Inside IDE no problems, outside IDE exception generated

Thanks for the suggestion Mark. It happens in both cases, small or large
number of points....
I've tried the settings you suggested and they didn't make a difference. I
will keep them like this however, because
if you say you never have any problems with them it can't do any harm to
leave it like this...
Ivar
 

Re:Inside IDE no problems, outside IDE exception generated

OK then (I'm not one to give up easily!) - Under Project, Options, Linker tab,
there is a section called Linking. Make sure "Use Debug Libraries" is checked,
and try that. If that does not help, then go to the Compiler tab, turn off
Code Optimizations, or check all 3 checkboxes in the "Debugging" section. Or
try any combination of said measures. If none of that works, pull your hair
out!
P.S. Try truning off Code Optimization first - that is the cause of many
strange problems - I *ALWAYS* disable optimisation, having seen it change my
code sequences into code that doesn't do the same thing!!! Let us know how you
get on. TIA,
--
Mark Jacobs
DK Computing
www.dkcomputing.co.uk
"Ivar Meijer" < XXXX@XXXXX.COM >wrote in message
| Thanks for the suggestion Mark. It happens in both cases, small or large
| number of points....
| I've tried the settings you suggested and they didn't make a difference. I
| will keep them like this however, because
| if you say you never have any problems with them it can't do any harm to
| leave it like this...
|
| Ivar
|
|
 

Re:Inside IDE no problems, outside IDE exception generated

Ok.... I've tried all suggestions to be able to visualize the error for
myself:
--------------------------------------------------------------------------
Pete: I was running CodeGuard outside and inside of the IDE, but it
didn't catch the problem (did catch something else that I fixed :P)
Paolo: I didn't have un-initialized (stack) variables
Clayton: The Run | Attach to process seems to work. When I start the
program outside of the IDE and attach the IDE to the process, it actually
indicates the line in the code where things go wrong. I already knew where
it went wrong because of my own logging, but at least now I'm able to step
through it.... I will proceed my investigation using this option.
Helmut: I tried to switch on the OS exceptions (everything that had to to
with floating point and overflow) but that didn't help.
Mark: I've kept the <fastmath.h>and stack/heap setting suggestions as
they don't see to do any harm...
---------------------------------------------------------------------------
All: I am aware the problem is a direct result of memory management, but of
course I should also try to look for ways to modify the calculations in such
a way that this will not be a problem in the future, no matter which
compiler or compiler settings are used...
Will keep you all updated...
Ivar
 

Re:Inside IDE no problems, outside IDE exception generated

Hi Mark,
Thanks for{*word*154} in there with me.... :-) Appreciate it...
Code optimization was switched off already, debug libraries were already
used and the debugging section had all 3 checkboxes selected...
So I'm ready to pull my hair out.... hehe.
Your answer came just after I answered all of the people that helped me,
thus this addition...
Will keep you posted for SURE....
Greetz,
Ivar
 

Re:Inside IDE no problems, outside IDE exception generated

Hi all,
After some time of debugging I can't put my finger on it yet. The place
where the error occurs (when I attach Builder to the running process) is
different everytime, which indicates a "randomness" caused by the OS memory
management. In Builder everything still works fine.
It will probably take me ages to find out why (if I even find it) so I
decided to try and modify the memory allocation within my functions.
Right now I was using my own array classes which use GlobalAlloc... I will
circumvent them now. Any suggestions which would be best to use for big
arrays of doubles?
Greetings,
Ivar Meijer
Software Engineer
DeguDent
"Mark Jacobs" <www.jacobsm.com/mjmsg?Borland%20Newsgroup>schreef in
bericht news: XXXX@XXXXX.COM ...
Actually, if you are only getting the problem of inaccurate calculation when
the number of elements is large, then it could be stack overflow issues.
These
can easily be addressed by going to Project, Options and go to the Linker
Tab.
Under PE file options, you can set assorted heap and stack sizes. I set
these
and let them be the default settings for all future projects (I never get
stack problems with these!) :-
Min Stack Size 0x00004000
Max Stack Size 0x01000000
Min Heap Size 0x00001000
Max Heap Size 0x01000000
Image Base 0x00400000
HTH,
--
Mark Jacobs
DK Computing
www.dkcomputing.co.uk
"Ivar Meijer" < XXXX@XXXXX.COM >wrote in message
| Thanks for all your great help guys. I will try one thing at a time and
post
| another message when I have some results...
 

Re:Inside IDE no problems, outside IDE exception generated

When Borland's allocator sees a very large sized allocation
request it already bypasses the internal buffering and goes
out to Windows for the allocation. So if you are allocating
large arrays of doubles, it's probably alreay rigged to do
what you want by using new, malloc or calloc. Since it is
a C++ program I recommend new (and delete []). However,
if you can get comfortable with it, consider using
vector<double>instead.
. Ed
Quote
Ivar Meijer wrote:
...
It will probably take me ages to find out why (if I
even find it) so I decided to try and modify the memory
allocation within my functions.
Right now I was using my own array classes which use
GlobalAlloc... I will circumvent them now. Any
suggestions which would be best to use for big
arrays of doubles?