The value of ESP was not properly saved across a function call.........

이라는 ERROR가 Visual Studio를 사용하면서 발생하는 경우가 생긴다.

 

위의 문제 점은 클래스의 맴버가  Static영역에 초기화 되면서 메모리에 올라갈때 생긴다.(배열들)

Microsoft Knowledge Base Article

상에서의 자료를 일단 살펴 보면,

위의 증상은, 탬플릿 클래스 상에서 컴파일러는 정확한 어셈블러로 컴파일하려 하면서 위의 에러가 발생한다고 한다.

메세지 내용은 아래와 같다

Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.

만약 탬플릿 클래스가 Default 생성자나 Default private 데이터 멤버가 하나도 없을 경우 위와 같은 에러가 나온다고 한다.

현재 해결방법은 없고, .net 2003버전에서 업글되어 나오는 서비스팩을 설치해야만 가능 ~!

즉시 해결하고자 한다면 Microsoft 사에 전화해서 HOTFIX서비스팩 UPDATE받아서 업글~!

 

코드 상의 해결방법은 없는 상태이고,

많은 양의 데이터 클래스 멤버 들이 아니라면, 클래스 멤버 전역변수를 현재 클래스가 아닌 다른 클래스에서 선언 사용해야 하며,

굳이 사용하고자 한다면, 멤버 사이즈(전역)를 최소화 해서 사용할 수 있다. 전역변수 배열 사이즈를 최소화시킨후 일정량이 찼을경우 작업실시후 다시 초기화 하는 방법을 사용하는 코딩 방법으로 해결은 가능하다.

(test결과 대략 한번에 잡을수있는 2차원배열 3000개짜리 4개가 Class멤버배열 최대SIZE)

지역변수들을 통한 호출 및 포인터 변수대체 사용 등이 있다.

Visual studio service Pack 최소 2.0 이상 업글을 해야만 한다.

 

 

=========================================================================================

 

Leave / Read
Community Feedback

Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005
Microsoft Corporation. All rights reserved. Terms of Use | Trademarks

BUG: You receive a run-time exception error message when you run the debug build of your application with the /RTCs compiler option enabled

Article ID : 822039
Last Review : January 12, 2006
Revision : 1.1

SYMPTOMS

When you run the debug build of your application with the /RTCs compiler option enabled, you may receive the following exception error message:
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.
You receive this error message when the following conditions are true:
You call a function that does not use the __cdecl modifier.
The function contains parameters that are larger than 64 kilobytes (KB).
You compile your application in the Debug mode and with the /RTCs compiler option enabled.

CAUSE

When you pass a parameter that is 64 KB or larger to a function that does not use the __cdecl modifier, the compiler generates incorrect code. When the function that is called tries to return control to the calling function, the compiler triggers the error that is mentioned in the "Symptoms" section. The compiler generates a 16-bit immediate return (RET) that has an operand that is limited to 64 KB. If the parameters that are passed to the function are larger than 64 KB, the stack becomes corrupted when the function returns.

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.

MORE INFORMATION

Steps to reproduce the behavior

1. Start Visual Studio .NET.
2. On the File menu, point to New, and then click Project. The New Project dialog box appears.
3. Under Project Types, click Visual C++ Projects, and then click Win32 Project under Templates.
4. In the Name box, type MyProject, and then click OK. The Win32 Application Wizard - MyProject dialog box appears.
5. On the Welcome to the Win32 Application Wizard page, click Application Settings. The Application Settings page appears.
6. Click Console application, and then click Finish.
7. In Solution Explorer, right-click MyProject.cpp, and then click Open.
8. Locate the following code in the MyProject.cpp file:#include "stdafx.h"
9. Add the following code after the code that you located in step 8:struct MyStruct { unsigned char MyData[65535]; }; void __stdcall MyFunc(MyStruct m_MyStruct) { m_MyStruct.MyData[0] = 'G'; return; }
10. Replace the existing code in the _tmain procedure with the following code: MyStruct m_Temp; MyFunc(m_Temp); return 0;
11. In Solution Explorer, right-click MyProject, and then click Properties. The MyProject Property Pages dialog box appears.
12. In the left pane of the MyProject Property Pages dialog box, click Configuration Properties.
13. Under Configuration Properties, click C/C++, and then click Code Generation.
14. Set the Basic Runtime Checks property to Stack Frames (/RTCs).
15. Click Configuration Manager. The Configuration Manager dialog box appears.
16. In the Active Solution Configuration list, click Debug, and then click Close.
17. In the MyProject Property Pages dialog box, click OK.
18. On the File menu, click Save All to save all the files.
19. On the Build menu, click Build Solution to build the application.
20. On the Debug menu, click Start to run the application.

REFERENCES

For more information, visit the following Microsoft Developer Network (MSDN) Web sites:
__cdecl
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang/html/_core___cdecl.asp (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang/html/_core___cdecl.asp)
/RTC (Run-time error checks)
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vcce4/html/evlrffsRTClpRundshtimeerrorchecksrp.asp (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vcce4/html/evlrffsRTClpRundshtimeerrorchecksrp.asp)

APPLIES TO
Microsoft Visual C++ .NET 2003 Standard Edition
Microsoft Visual C++ .NET 2002 Standard Edition
Keywords: 
kbcompiler kbdebug kberrmsg kbtshoot kbbug KB822039
안정적인 DNS서비스 DNSEver DNS server, DNS service
Posted by 키르히아이스
,