Corrupted method parameter (do not match the calling parameter)
Hi,
I have an anoying and very strange problem with a particular method :
public
void UpdateRenderGeometry(double length,double width){
... blah blah ...
}
When I call UpdateRenderGeometry(800, 150), at the begining of the method, length is not 800 but 2.37151510003798E-322 !!! width is 150.
Any idea of what could cause a such problem ?
There is not local length variable in the method or in the class.
And when I comment few lines of code (randomly) in this method, the length parameters is correct.
[873 byte] By [
Bumper] at [2008-1-8]
Are you sure your debuging correctly ?
Print or check the variable value right before and after the function call
Yes, before the call, the value is correct and in the method it is not.
I think it is stack or heap related.. but there is no warning and no compiler message at runtime.
There is nothing critical in the function, just basic WPF PathGeometry manipulation.
And changing few lines in the method have consequence to make the value ok or corrupted..
for example: commenting the 3 lines below can make the length value ok or corrupted (its just an empty elseif).
else
if (segment.GetType() == typeof(QuadraticBezierSegment)) {
}
For the moment, I had splitted my method into smaller ones and that works fine.. but I am still interrested to get out the bug.
Hi, Bumper
If you could give us some code for reproduction, the result would be clear.
In some other cases, user may make mistakes to use double do some precise required computing, keep it in mind that double is 64-bit represented and accurate to only 15-16 digits(Approximate range: ±5.0 × 10?324 to ±1.7 × 10308)
See: Double type in C#
Thanks
Hi Figo Fei,
Here's an archive with the reproduction solution. It require VS2005 and .NET3 (WPF).
http://www.epsilongd.com/pub/ReproParameterBug.rar
I removed as much code as possible to keep the bug alive (the method is now ~130 line long) but the method does nothing correctly anymore (at least it do not crash).
In the repro code, I pass 800 to the first parameter of UpdateRenderGeometry2 (the bugged method) and at the begining of the method, the first parameter value is : 3.40049894832243E-311
Try to comment random lines in the method and you should see length = 800 (length is the first parameter).
There is nothing critical in my code, I just use framework class so I don't know why there is problem in that particular method.. hope someone could found what's wrong.
Thanks in advance.
David
Hi, David
I moved the thread to WPF forum for better answer.
Thanks
Just executed the code on xp sp2 with vs2008 and .net 3.5 targetting 3.0 and it works fine. Are you saying the bug only happens when the method has that many instructions?
Have you tried runnin gthe code on another machine to see if the problem comes from the CLR (which is unlikely) or from your environment?
Hi Seb,
Hum, so on your machine, with the provided code, the first parameter 'length' is 800 and not 3.40049894832243E-311? Interresting...
I made few tests :
- I compiled with optimizations : 3.40049894832243E-311
- I runned the program outside of visual studio : 800
- I runned the program from visual studio but for x86 instead of CLR : 800
So its probably an evil bug in my version of visual studio (2005 sp1 on vista). I had that kind of anoying bug with c++ on pre-sp1 vs2005 and that was fixed in sp1.
Well, since it work after having splitted my method, I will not search longer...
Thanks a lot for the tests!
It seems to me you end up with a stack corruption when in debug mode. If you want to debug more, you can test what gets injected in your exe using process explorer. Things like profilers, and even sometimes malware.
Check all the add-ins you may have installed on vs too.
Best of luck 