Board index » delphi » Weird floating point exception

Weird floating point exception

Anyone have any ideas why using a showmessage('iter '+inttostr(i)) would
cause a floating point error in a numerical subroutine called a few
statements later?  commenting out that showmessage causes the error not to
happen.

Thanks!

JS

 

Re:Weird floating point exception


On 03 Jun 2003, "J Smith" <nerdcomm...@yahoo.com> wrote:

Quote
> Anyone have any ideas why using a showmessage('iter '+inttostr(i))
> would cause a floating point error in a numerical subroutine called a
> few statements later?  commenting out that showmessage causes the
> error not to happen.

If commenting out a showmessage call fixes a bug there are at least two
possibilities:

1) Your program has a memory overwrite or uninitialized pointer that just
happens to not crash depending on what's in memory

2) It's timing related.  The extra time and message processing that happens
because the user has to press a button masks or causes the problem

--
-Mike (TeamB)

Re:Weird floating point exception


Quote
> > Anyone have any ideas why using a showmessage('iter '+inttostr(i))
> > would cause a floating point error in a numerical subroutine called a
> > few statements later?  commenting out that showmessage causes the
> > error not to happen.

> If commenting out a showmessage call fixes a bug there are at least two
> possibilities:

> 1) Your program has a memory overwrite or uninitialized pointer that just
> happens to not crash depending on what's in memory
>>>>>>>>>>>>>>> this problem would be my fault and I have to hunt that down

and fix.

Quote

> 2) It's timing related.  The extra time and message processing that
happens
> because the user has to press a button masks or causes the problem
>>>>>>>>>>>>>>>  why would timing matter here?  processing is stopped while

the app waits for user feedback.

Re:Weird floating point exception


Quote
"J Smith" <nerdcomm...@yahoo.com> wrote:
>> <snip>
>> If commenting out a showmessage call fixes a bug there are
>> at least two possibilities:

>> 1) Your program has a memory overwrite or uninitialized
>> pointer that just happens to not crash depending on what's
>> in memory

> this problem would be my fault and I have to hunt that down
> and fix.

My first guess would be that 'i' is an iterator that was used
as an index to move data to while it pointed to the end of the
vector which in fact is actually past the end of the vector.

Quote
>> 2) It's timing related. The extra time and message
>> processing that happens because the user has to press a
>> button masks or causes the problem

> why would timing matter here?  processing is stopped while
> the app waits for user feedback.

Timing is always an issue with dealing with threads. I'm sure
that Mike was speaking in general terms based on his
experiance with this type of problem and he included it to
provide you with a complete answer.

In my experiance however, this behavior has always lead back
to Mikes 1st probable cause. Then again, I use threads
sparingly.

~ JD

Re:Weird floating point exception


But I am not using threads in this app...

JS

Quote
"JD" <nos...@nospam.com> wrote in message

news:3eddbdde$1@newsgroups.borland.com...
Quote

> "J Smith" <nerdcomm...@yahoo.com> wrote:
> >> <snip>
> >> If commenting out a showmessage call fixes a bug there are
> >> at least two possibilities:

> >> 1) Your program has a memory overwrite or uninitialized
> >> pointer that just happens to not crash depending on what's
> >> in memory

> > this problem would be my fault and I have to hunt that down
> > and fix.

> My first guess would be that 'i' is an iterator that was used
> as an index to move data to while it pointed to the end of the
> vector which in fact is actually past the end of the vector.

> >> 2) It's timing related. The extra time and message
> >> processing that happens because the user has to press a
> >> button masks or causes the problem

> > why would timing matter here?  processing is stopped while
> > the app waits for user feedback.

> Timing is always an issue with dealing with threads. I'm sure
> that Mike was speaking in general terms based on his
> experiance with this type of problem and he included it to
> provide you with a complete answer.

> In my experiance however, this behavior has always lead back
> to Mikes 1st probable cause. Then again, I use threads
> sparingly.

> ~ JD

Re:Weird floating point exception


Quote
"J Smith" <nerdcomm...@yahoo.com> wrote:
> But I am not using threads in this app...

Read the post again. No said that you were but you should be aware that certain processes do use seperate threads. To be clear, I said:

Quote
>> Timing is always an issue with dealing with threads. I'm sure
>> that Mike was speaking in general terms based on his

                             ^^^^^^^^^^^^^
Quote
>> experiance with this type of problem and he included it to
>> provide you with a complete answer.

                      ^^^^^^^^

~ JD

Re:Weird floating point exception


So what would cause a thread to be used where I am not aware of one?  how
would I find out?

JS

Quote
"JD" <nos...@nospam.com> wrote in message

news:3eddee51$1@newsgroups.borland.com...
Quote

> "J Smith" <nerdcomm...@yahoo.com> wrote:
> > But I am not using threads in this app...

> Read the post again. No said that you were but you should be aware that

certain processes do use seperate threads. To be clear, I said:
Quote

> >> Timing is always an issue with dealing with threads. I'm sure
> >> that Mike was speaking in general terms based on his
>                              ^^^^^^^^^^^^^
> >> experiance with this type of problem and he included it to
> >> provide you with a complete answer.
>                       ^^^^^^^^

> ~ JD

Re:Weird floating point exception


Quote
"J Smith" <nerdcomm...@yahoo.com> wrote:
> So what would cause a thread to be used where I am not aware
> of one?  how would I find out?

Please allow me one more try to clearify the issue for you:

Your post did not say if you were or were not using threads. I
believe that Mike included the timing issue only because in
his experiance, in addition to it being caused by invalid
memory access, he has seen similar behavior when threads were
used.

As for what processes do use seperate threads - the first that
comes to mind is a database event like TIBEvent but don't
worry about them. You'd know if you used the help to get the
syntax and I think that you're chasing your tail looking here.

If you're not using threads, I'd bet my life that it's a
memory access problem. You need to check all access to all
memory that is explicitly allocated/deallocated.

It's either that you have used a pointer before it's been
allocated or you have used it after it has been deleted or you
have run past the end of the allocated space or you have
deleted an invalid pointer. The later can happen if you have
derefrenced the pointer (changed the value of the pointer
while it pointed to a valid block to be freed) or if the
allocated pointer has already been freed.

To help find the problem, where ever you have a pointer
defined, before you allocate/create for it, set it to nil and
after you deallocate/destroy it, set it to nil again.

If you have allocated any memory to be used as a sort of
buffer, check your code carefully to make sure that you're not
reading/writing past the end of allocated space.

Finally, since you didn't comment on my guess about you using
vectors, I'm again assuming that you are. A common mistake is
using the entry pointed to by the end() iterator. end()-1 is
the last allocated entry.

HTH

~ JD

Other Threads