01-16-2008 03:37 PM
01-16-2008 06:29 PM
01-17-2008 08:48 AM
Hi, Jonathon,
Thanks for the quick response. I am happy to give you more info, including tests I've done already, and to try your suggestions. Here are anwers to your points:
- Yes, everything worked fine in 6.0. When it came time to upgrade, I first tried to build it under Visual Studio 2005 with the original Meas. Studio 6.0 headers and libs but it wanted to link the old MFC libs and could not find them. So I installed Meas. Studio 8.1.1 (I was afraid to install 8.1.2 from the December CD set because of "risk of bodily injury") and deleted the old headers and libs from the project. It recompiled and linked just fine.
- Yes, the stack corruption breakpoints happened the first time I ran in debug mode. When I turned off the stack checker, I got some bogus failures warning of using uninitialized variables. I say "bogus" because when I step through the code, the variables are clearly initialized. I suspect that the unchecked stack corruption is confusing the variable checker. When I turned that off as well, the debug code worked correctly. However, the release build still failed. I added some tracing dumps to the release build and saw that a local variable called "bRet" was being clobbered by this unrelated line of code:
m_graph.GetAxes().Item(1).SetMinMax(m_dXAxisMin, m_dXAxisMax);
but only in release mode - the debug build did not change the value of bRet! I took that as more evidence of stack corruption.
- Yes, the stack check breakpoints always occur in the three places I mentioned in the first post and the release mode failure always occurs as above (given the same app test conditions). Another interesting test result is that, if I turn on speed optimization, then the release build does not fail as above. Rather, it causes the LabView app to abruptly exit completely without any dialog or warning!
- I will try to build and run a similar NI example. If that works fine, I'll try to strip down my project and demonstrate the failure.
- The error says "Run-Time Check Failure #2 - Stack around the variable 'pointers' was corrupted." The local variable declaration is:
CNiPointers pointers = m_sliderWnd.GetPointers();
If I stick a "return;" just after that line, I get the same message but if I put "return;" just before that line, I get no error there!
- I am calling the debug DLL from LabView. And the debug DLL is calling release builds of the Meas. Studio libraries. Is there any way to link in debug versions of these libs? It would be great to step through some of the NI code (at least the top, non-proprietary layers) like you can with MFC libraries.
So I hope you can see why I suspect true stack corruption within the calls into those NI classes. Maybe I have some build setting wrong. This project was automatically converted by Visual Studio 2005 from the old one. I also tried creating a new Meas. Studio project and compared its settings with mine. I then changed some of my settings to match but to no avail. The only one I did not change was the "Struct Member Alignment". The new project used "8 Bytes" but mine requires "1 Byte" because it must parse LabView arrays and clusters.
Thank you for your attention.
Claus
01-17-2008 09:14 AM
For clarity, here are declarations for the 2 lines of code in the previous post:
CNiGraph m_graph;
CNiSlide m_sliderWnd;
01-17-2008 09:46 AM
Bingo!
I modified the NI example "Advanced Slide" to use a local CNiPointers object as below:
void
CAdvancedSlideDlg::OnPointerValueChangedSlide2(long Pointer, VARIANT FAR* Value){
double Low = 20.0; double Hi = 60.0; double Val;Val = CNiVariant(Value);
CNiPointers pointers = m_Slide2.GetPointers();
if (Val > Hi){
pointers.Item(1).Value = Low;
m_Slide2.GetPointers().Item(2).Value = Hi;
m_Slide2.GetPointers().Item(3).Value = Val;
}
....When I run the debug build, it works fine. If I change the project setting "Struct Member Alignment" to "1 Byte" and rebuild, I get the same stack corruption breakpoint. So it looks like I have to fix the alignment in my project. I'll post my result.
Thanks for the suggestion.
Claus
01-17-2008 11:09 AM
01-17-2008
12:23 PM
- last edited on
06-18-2025
06:01 PM
by
Content Cleaner
The thing is, the project's alignment was set to 1 on NI's advice, as per this doc:
http://zone.ni.com/reference/en-XX/help/371361A-01/lvhowto/building_library_project/
but the new Meas. Studio seems to require 8. It's a contradiction, no? I think I can use a pragma to get around it, but is that the right solution?
01-17-2008 12:52 PM
OK, I changed the project's alignment to 8 to make Meas. Studio happy and I used a #pragma pack(1) in the header for the LabView structs to make LabView happy. Both debug and release builds work and I'm happy. Everybody's happy! Except, maybe, the documentation person who should qualify the advice to set the DLL project alignment to 1.
Thanks, Jonathon, for your help.