Run Time Check Failure #0 - The Value of ESP error
kalvin123

When trying to debug my game I consistently get this error and with being quite a noob to Allegro and c++ I don't really have much knowledge to figure out a solution on my own.

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.
on these 2 lines

*ALLEGRO VARIABLES*
ALLEGRO_COLOR blk = al_map_rgb(0, 0, 0); /* al_map_rgb_f(0.0, 0.0, 0.0);*/
ALLEGRO_COLOR wht = al_map_rgb(0, 0, 0);

I also get a memset.asm not found error.

Here is a pastebin for my main.cpp
http://pastebin.com/fkwa0whH

Michael Moffitt

I don't know what the deal is with your error, but I have two questions:

1) Where are screenW and screenH being defined?

2) Is there a reason everything is in the main function? Splitting up different routines into functions is more desirable than using gotos.

EDIT: Your AddonCheck logic is broken. You need to check the return value of the init functions. Only if it is nonzero should you add to AddonCheck.

A more typical way of doing it is like this:

if (!al_init_acodec_addon())
{
  fprintf(stderr,"Error: Failed to initialize audio codec addon.\n");
  al_show_native_message_box(0, "Error", "Failed to initialize audio codec addon", "Press OK to terminate.", 0, ALLEGRO_MESSAGEBOX_ERROR);
  return -1;
}

Doing something like this for each addon will make it very clear if one has had a problem, and which one.

I recommend first at least breaking out your system initialization into its own set of functions. Something like,

// Return zero on failure, nonzero on success
int game_addon_setup(void)
{
  if (!al_init_acodec_addon())
  {
    fprintf(stderr,"Error: Failed to initialize audio codec addon.\n");
    al_show_native_message_box(0, "Error", "Failed to initialize audio codec addon", "Press OK to terminate.", 0, ALLEGRO_MESSAGEBOX_ERROR);
    return 0;
  }
// so on and so forth for other addons
  return 1;
}

Elias

Which compiler are you using and how did you compile Allegro (i.e. with the same compiler version or a different one)?

bamccaig

Definitely take Michael's advice and split your program into several functions. You have created much too large of a program to have it all in one function. That becomes incredibly difficult to read, incredibly difficult to understand, and therefore impossible to get working properly.

He's also right about the error detection. Allegro is a C library. If something fails it isn't going to terminate your program by throwing an exception. It's just going to return an integer or a NULL pointer to the caller that needs to explicitly check the return value and handle it appropriately.

http://wiki.allegro.cc/index.php?title=Return_value

goto is often a sign that you're doing it wrong. Less so in C. Especially so in C++. I'm not even going to attempt to understand that massive main function. You should aim for your functions to be 25 to 50 characters in an ideal world. The shorter your functions are the easier it is to understand them and prove that they work.

relpatseht

ESP is the stack pointer register on x86. If it isn't saved properly across a function that typically means, as the error suggests, you are using a different calling convention than the one you compiled with.

For instance, you may have compiled Allegro using the CDECL calling convention, but in your program, you are treating the functions as though they were compiled with STDCALL.

As Elias mentioned, we'll need to know what options you used when compiling Allegro. Or are you using pre-built binaries? Which?

Thread #615668. Printed from Allegro.cc