Allegro.cc - Online Community

Allegro.cc Forums » Installation, Setup & Configuration » difficult bug...meaning of "Run-Time Check Failure #0 - The value of ESP.."

This thread is locked; no one can reply to it. rss feed Print
difficult bug...meaning of "Run-Time Check Failure #0 - The value of ESP.."
Fred58
Member #11,939
May 2010

He,

with MSVC 10 / Windows 7,
in debug mode what is the meaning of this error ?

"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."

i get it in the above program with the call of: al_map_rgb al_draw_text and al_draw_textf

In release mode the program crash at the end with the second call of al_destroy_font

al_destroy_font(arial18);
al_destroy_font(arial24); // here
al_destroy_font(arial36);

here is the program :

/********************************
#include <allegro5\allegro.h>
#include <allegro5\allegro_native_dialog.h>

#include <allegro5\allegro_font.h>
#include <allegro5\allegro_ttf.h>

void erreur(const char*txt)
{
ALLEGRO_DISPLAY *display;

display = al_is_system_installed() ? al_get_current_display() : NULL;
al_show_native_message_box( display, "Erreur", txt ,NULL, NULL, 0);
exit(EXIT_FAILURE);
}

int main()
{
ALLEGRO_DISPLAY*display;

if(!al_init())
erreur("init allegro");

display=al_create_display(800,600);
if (!display)
erreur("create display");

al_init_font_addon();
al_init_ttf_addon();

ALLEGRO_FONT*arial24 = al_load_ttf_font("arial.ttf", 24, 0);
ALLEGRO_FONT*arial36 = al_load_ttf_font("arial.ttf", 36, 0);
ALLEGRO_FONT*arial18 = al_load_ttf_font("arial.ttf", 18, 0);
if(!arial24||!arial36||!arial18)
erreur("load fontes");

al_draw_text( arial24,al_map_rgb(255, 0, 255),50, 50,0,"Salut 24 point : éàùàâêï");
al_draw_text(arial36, al_map_rgb(255, 127, 127), 800 / 2, 600 / 2, ALLEGRO_ALIGN_CENTRE, "centre et 36 point");
al_draw_text(arial18, al_map_rgb(15, 240, 18), 780, 450, ALLEGRO_ALIGN_RIGHT, "aligné à droite et 18 point");

int scrx = al_get_display_width(display);
int scry = al_get_display_height(display);

al_draw_textf(arial18, al_map_rgb(255, 255, 255), scrx/2, scry-200, ALLEGRO_ALIGN_CENTRE,"TEXT formaté: largeur et hauteur écran = %i / %i" , scrx, scry);

al_flip_display();

al_rest(5.0);

al_destroy_font(arial18);
al_destroy_font(arial24);
al_destroy_font(arial36);
al_destroy_display(display);

return 0;

}

jmasterx
Member #11,410
October 2009

I tested it without the unicode characters and it does not crash.

#SelectExpand
1#include <allegro5\allegro.h> 2#include <allegro5\allegro_native_dialog.h> 3#include <allegro5\allegro_font.h> 4#include <allegro5\allegro_ttf.h> 5 6void erreur(const char*txt) 7{ 8 ALLEGRO_DISPLAY *display; display = al_is_system_installed() ? al_get_current_display() : NULL; 9 al_show_native_message_box( display, "Erreur", txt ,NULL, NULL, 0); 10 exit(EXIT_FAILURE); 11} 12 13int main() 14{ 15 ALLEGRO_DISPLAY*display; if(!al_init()) 16 erreur("init allegro"); display=al_create_display(800,600); 17 if (!display) 18 erreur("create display"); al_init_font_addon(); 19 al_init_ttf_addon(); ALLEGRO_FONT*arial24 = al_load_ttf_font("res/font.ttf", 24, 0); 20 ALLEGRO_FONT*arial36 = al_load_ttf_font("res/font.ttf", 36, 0); 21 ALLEGRO_FONT*arial18 = al_load_ttf_font("res/font.ttf", 18, 0); 22 if(!arial24||!arial36||!arial18) 23 erreur("load fontes"); 24 25 al_draw_text( arial24,al_map_rgb(255, 0, 255),50, 50,0,"Salut 24 point : PAS DE UNICODE XD"); 26 al_draw_text(arial36, al_map_rgb(255, 127, 127), 800 / 2, 600 / 2, ALLEGRO_ALIGN_CENTRE, "centre et 36 point"); 27 al_draw_text(arial18, al_map_rgb(15, 240, 18), 780, 450, ALLEGRO_ALIGN_RIGHT, "aligné à droite et 18 point"); int scrx = al_get_display_width(display); 28 int scry = al_get_display_height(display);al_draw_textf(arial18, al_map_rgb(255, 255, 255), scrx/2, scry-200, ALLEGRO_ALIGN_CENTRE,"TEXT formaté: largeur et hauteur écran = %i / %i" , scrx, scry); 29 al_flip_display(); 30 al_rest(5.0); 31 al_destroy_font(arial18); 32 al_destroy_font(arial24); 33 al_destroy_font(arial36); 34 al_destroy_display(display); 35 36 return 0; 37}

I suspect maybe you're not using the correct unicode encoding for your cpp and it becomes not UTF-8. This maybe causes Allegro to crash.

I suggest instead that you load your Unicode text from a UTF-8 encoded text file. I do this and it works great. Some text editors get confused with encoding.

Fred58
Member #11,939
May 2010

he,

the code is correct, so it's certainly something with text encoded but i don't know that very well.

i try to save my source file with le notepad encoded in UTF-8 and after load it in MSVC : same result always in debug mode "Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call..."

i also add in "Advanced save options" entry in the File menu to change the encoding to "Unicode (UTF-8 without signature)"

but i have always the same result and a crash in release mode.

is it possible the problem is coming because i have a french installation of MSVC10 ?

Thank you very much for our help.
If i can't find a solution i will continue to learn allegro5 with Mingw32 and cobeBlocks for the moment, but it is very hassle for me.

Arthur Kalliokoski
Second in Command
February 2005
avatar

You might play with this little console program:

#SelectExpand
1#include <stdio.h> 2#include <string.h> 3 4char s[] = "éàùàâêï"; 5 6int main(void) 7{ 8 int i,l; 9 l = strlen(s); 10 for(i=0;i<l;i++) 11 { 12 printf(" 0x%X",(unsigned char)s[i]); 13 } 14 printf("\n"); 15 return 0; 16}

and compile it as regular C. When I saved it as code page 1252 it came out as

 0x3F 0x3F 0x3F 0x3F 0x3F 0x3F 0x3F

but saving as UTF8 it came out as

0x82 0x85 0x97 0x85 0x83 0x88 0x8B

Until it comes out as the latter sequence, your editor isn't saving it right.
BTW, when I changed the type to save as, the string 's' changed as well, so repaste the "éàùàâêï" as necessary.

They all watch too much MSNBC... they get ideas.

Fred58
Member #11,939
May 2010

i get :

0xE9 0xE0 0xF9 0xE0 0xE2 0xEA 0xEF

in both cases : saving as code page 1251 and saving as "UTF-8 (without signature)code page 65001 (i take care to repaste "éàùàâêï")

i try other code but if it works the result is always
0xE9 0xE0 0xF9 0xE0 0xE2 0xEA 0xEF

have this a meaning for you ?

Arthur Kalliokoski
Second in Command
February 2005
avatar

I tried this:

#include <stdio.h>

char t[] = {0xE9,0xE0,0xF9,0xE0,0xE2,0xEA,0xEF,0};
char u[] = {0x82,0x85,0x97,0x85,0x83,0x88,0x8B,0};

int main(void)
{
  printf("%s\n",t);
  printf("%s\n",u);
  return 0;
}

and your sequence now prints out the "éàùàâêï" but the sequence I posted gets ignored (!)

I don't know what's going on here.

They all watch too much MSNBC... they get ideas.

Fred58
Member #11,939
May 2010

to summarize:

char s[]="éàùàâêï"; // printf("%s\n",s); give some symbols

char u[]={0x82,0x85,0x97,0x85,0x83,0x88,0x8B,0}; // printf("%s\n",u); give éàùàâêï

with saving as UTF8 (code 65001) or saving as occidental langage (code 1252)

glouk???

Dennis
Member #1,090
July 2003
avatar

MSVC2010 Express, Windows 7, Allegro 5.1.x (from GIT)

your code file saved with ""UTF-8 (without signature)code page 65001"

screenshot:
{"name":"606290","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/5\/951202a002139973069318d60bc2acac.png","w":799,"h":599,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/5\/951202a002139973069318d60bc2acac"}606290

No crashes here, meaning your code is fine.
Maybe your problem is caused by some compiler/linker setting?

Fred58
Member #11,939
May 2010

I use allegro 5.0.7 and not allegro5.1.x but i know that the code is correct : it works perfectly compiled under mingw32.

Yes the problem is probably caused by some compiler/linker setting. But witch parameter and where find it!?

I try to repair MSVC and reinstall it. It's a Visual studio 2010 pro FR version for education.

But i still have the same problem. May be it's because of the module for the French language ?

Later i'll try to uninstall and test vith MSVC2010 Express without french module.

it's probably not much but find it is not easy for one starting in Visual studio. If some body has an idear i still listen to.

Thank you very much for all help.
F

Dennis
Member #1,090
July 2003
avatar

Fred58 said:

Yes the problem is probably caused by some compiler/linker setting. But witch parameter and where find it!?

Based on your original error message..:

Fred58 said:

"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."

.., I'd check the setting for "Calling Convention" first. Make sure it says __cdecl.

Fred58
Member #11,939
May 2010

yes "calling convention says __cdecl (/Gd)

Dennis
Member #1,090
July 2003
avatar

Are you linking to the correct versions of the .lib files?
When you compiled the dependencies(especially Freetype) and Allegro itself, did you use __cdecl as well?

It's hard to tell what could be wrong here but I doubt it is at all related to it being a french version of MSVC, so re-installing is not going to solve the problem.

Fred58
Member #11,939
May 2010

in fact i didn't compile allegro myself i download the pachage given here, at http://www.allegro.cc/files/

may i compile allegro5 myself (i'm a little afraid about that) ?

I never meet that kind of problem with allegro 4.

But i made a new test with the same visual studio installed on another PC (an eepc, HP mini !) with 32bits Windows 7 basic and no problem. My first program about using fonts with allegro 5 works perfectly.

my big PC i use with the problem is a 64 bits ... Perhaps a track ?

Dennis
Member #1,090
July 2003
avatar

Quote:

char s[]="éàùàâêï";

What would be interesting here is how those characters appear in memory at runtime because that's the only way to see if "saving as UTF-8 (without signature)code page 65001" leads to a correct encoding of the string literal in UTF-8.

If correctly encoded as UTF-8, the memory pattern should be: C3A9 C3A0 C3B9 C3A0 C3A2 C3AA C3AF (the bit-octets per char may be switched depending on the machines endianness).

Quote:

char u[]={0x82,0x85,0x97,0x85,0x83,0x88,0x8B,0};

The compiler does not translate those (non standard ASCII character numbers) into a UTF8-encoded string, it will just keep those as an array of those numbers, so you can't ever expect any function that only accepts correctly encoded UTF-8 to make sense of those values.

Quote:

E9 E0 F9 E0 E2 EA EF

Those are in fact the unicode numbers for the characters éàùàâêï but they're not the UTF8 bytes for those unicode numbers, because in UTF8 the maximum code to be encoded in a single bit-octet is 7F, everything else needs to be encoded in more than one (up to four) bit-octets.

---

Back to the runtime problem though, please post the contents of your solution/project files (you can open them in notepad and copy the text) so we may see if there are any odd setting which need fixing.

append
Ah, you edited. :P

Fred58 said:

my big PC i use with the problem is a 64 bits ... Perhaps a track ?

Make sure to set the compiler to compile for 32bit architecture if those Allegro binaries you downloaded were compiled for that as well.

Fred58
Member #11,939
May 2010

Where could i find if the compiler compile for 32bit architecture ? Is it Win32 in the configuration manager ?

Thank you very very much for explanation about unicode/UTF8, i know nothing about that.
The problem seems to be that my code page is never in UTF8 ever if i have option "saving as UTF-8 (without signature)code page 65001"

but i'm not sure to well understand that you tell me to do : i open my source file with the notepad and i copy the text ... but where ? Here ?

Also i convert the file with the notepad in UTF-8 and load it after in the visual project, compile with option "saving as UTF-8 (without signature)code page 65001" but i always have the same result "Run-Time Check Failure #0..."
/forums/smileys/cry.gif

#include <allegro5\allegro.h>
#include <allegro5\allegro_native_dialog.h>

#include <allegro5\allegro_font.h>
#include <allegro5\allegro_ttf.h>

void erreur(const char*txt)
{
ALLEGRO_DISPLAY *display;

display = al_is_system_installed() ? al_get_current_display() : NULL;
al_show_native_message_box( display, "Erreur", txt ,NULL, NULL, 0);
exit(EXIT_FAILURE);
}

int main()
{
ALLEGRO_DISPLAY*display;

if(!al_init())
erreur("init allegro");

display=al_create_display(800,600);
if (!display)
erreur("create display");

al_init_font_addon();
al_init_ttf_addon();

ALLEGRO_FONT*arial24 = al_load_ttf_font("arial.ttf", 24, 0);
ALLEGRO_FONT*arial36 = al_load_ttf_font("arial.ttf", 36, 0);
ALLEGRO_FONT*arial18 = al_load_ttf_font("arial.ttf", 18, 0);
if(!arial24||!arial36||!arial18)
erreur("load fontes");

int scrx = al_get_display_width(display);
int scry = al_get_display_height(display);


al_draw_text( arial24,al_map_rgb(255, 0, 255), 50, 50, 0, "Salut 24 point : éàùàâêï");
al_draw_text(arial36, al_map_rgb(255, 127, 127), scrx / 2, scry / 2, ALLEGRO_ALIGN_CENTRE, "centre et 36 point");
al_draw_text(arial18, al_map_rgb(15, 240, 18), scrx-10, scry-200, ALLEGRO_ALIGN_RIGHT, "aligne à droite et 18 point");

al_draw_textf(arial18, al_map_rgb(255, 255, 255), scrx/2, scry-100, ALLEGRO_ALIGN_CENTRE,
"TEXT formaté: largeur et hauteur écran = %i / %i" , scrx, scry);

al_flip_display();

al_rest(5.0);

al_destroy_font(arial18);
al_destroy_font(arial24);
al_destroy_font(arial36);
al_destroy_display(display);

return 0;

}

Dennis
Member #1,090
July 2003
avatar

Dennis said:

Back to the runtime problem though, please post the contents of your solution/project files (you can open them in notepad and copy the text) so we may see if there are any odd setting which need fixing.

Fred58 said:

but i'm not sure to well understand that you tell me to do : i open my source file with the notepad and i copy the text ... but where ? Here ?

Not the source file. We already have your source. I said solution/project files. Those have a .sln/.vcxproj ending. The compiler/linker settings are stored in those files.

Quote:

Is it Win32 in the configuration manager?

Yes and make sure that is the active target when you start building.

Fred58
Member #11,939
May 2010

I try to reinstall MSVC. And after with the same source code saved as UTF-8 on file i havn't crash and i have not "Run-Time Check Failure #0...". but i havn't éèàâêïù !

As i lost page layout (i'm very sorry : another thing i have to learn) i give you the two solution/project files.

However this is the solution file :

-------------------------------------------------------------
Microsoft Visual Studio Solution File, Format Version 11.00

  1. Visual Studio 2010

Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "alleg5_font_text3", "alleg5_font_text3\alleg5_font_text3.vcxproj", "{88138076-89DC-4178-95A2-EAF90200848A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{88138076-89DC-4178-95A2-EAF90200848A}.Debug|Win32.ActiveCfg = Debug|Win32
{88138076-89DC-4178-95A2-EAF90200848A}.Debug|Win32.Build.0 = Debug|Win32
{88138076-89DC-4178-95A2-EAF90200848A}.Release|Win32.ActiveCfg = Release|Win32
{88138076-89DC-4178-95A2-EAF90200848A}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

-------------------------------------------------

And the project file :

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{88138076-89DC-4178-95A2-EAF90200848A}</ProjectGuid>
<RootNamespace>alleg5_font_text3</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>allegro-5.0.7-monolith-mt-debug.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>allegro-5.0.7-monolith-mt.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="alleg5_fontes_textes.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

Dennis
Member #1,090
July 2003
avatar

Fred58 said:

<CharacterSet>MultiByte</CharacterSet>

There are two lines in your project file which look like that.

Change them both to:
<CharacterSet>NotSet</CharacterSet>

Save and reopen the project.

Fred58
Member #11,939
May 2010

YES !!!!!!!

i do that and by chance i discovered something else : there is two unicode UTF-8 !
unicode (UTF-8 with signature) page coding 65001
unicode (UTF-8 without signature) page coding 65001

BE CAREFULL : the good one is the second "UTF-8 WITHOUT signature". Do you know the difference between the two ?

I try with an other solution/project test and this seems to solve the problem even with <CharacterSet>MultiByte</CharacterSet> in file project

Thank you very very very much for your help.

Dennis
Member #1,090
July 2003
avatar

Did you clean and recompile after those changes?

Frankly, I am running out of ideas.
I have MSVC2010 Express(English) with all updates and service packs here and for me, your code works without problems with the settings described earlier.

The only other difference is that I'm using Allegro 5.1.3.

Fred58
Member #11,939
May 2010

While you answer me: I found the answer. Look at my previous message

Audric
Member #907
January 2001

I think it's about the presence of the byte order mark at the beginning of the file.

Dennis
Member #1,090
July 2003
avatar

Yes, that's what I think as well.

Fred58
Member #11,939
May 2010

NOOOOOooo.... it wasn't the solution and i'm not alone with this problem on web.

So i find the solution on http://www.gamedev.net/. Somebody named "Markus" told :

"This error is most often caused by mismatching header (*.h) and library (*.lib, *.dll) files. It tells you that you have called a function with another signature as the compiled function expects.

Here's an example which causes this exact error:

class A {
public:
virtual int foo(int x, int y) { return x + y; }
};

class B {
public:
virtual int foo(int x) { return x; }
};

int main() {
A a;
reinterpret_cast<B *>(&a)->foo(123);
}

So check for outdated library files, include path search order (maybe it finds a newer version of some library headers but you're still linking against the older one) and that your project doesn't have old binaries left over somewhere which are being used accidently."

Actually i used the MingW DLL in place of the MSVC DLL... This time it is the solution (i hope !)

Go to: