Home | AGI Documentation | AGI Tutorials | AGI Tools | AGI Wiki | Community

AGI Stack Overflow Error

By Nick Sonneveld

On the current AGI Messageboard there was a discussion about a "stack blown error" in the same thread where an author of a new AGI game (Pimp Quest) had just announced the release of a new demo and website.   Users of Windows were getting this error.

There were a lot of attempts to explain this error.  Most Sierra AGI games work just under Windows.  The reason why I think this stack error occurs is because (kinda obviously) the stack is being filled up.  The culprits are the AGI itself (because it is filling around a brushed object in the Pimp Quest title screen.. so there's lots of little lines to fill up and all these lines get pushed onto stack) and Windows.  I'm not quite sure, but I think Windows has some sort of timer running in DOS mode that is called and pushes a bit too much on the stack.

So while the picture fill routine has a lot of information pushed onto the stack, Windows pushes some extra stuff on and the stack overflows.  AGI actually checks if the head of the stack is overwritten and so trips this stack error in the middle of a screen write.


1) Don't create a stack heavy picture.

Don't fill around brushed objects.  In the Pimp Quest case, you should fill the screen first before drawing in the title with the brush.  Here's the actual modified picture file.

Bad Pic
Bad picture. (filled after)

Good Pic
Good picture. (filled before)


2) Don't use Windows

You could go straight into pure DOS if you *really* wanted to.  This isn't very helpful if you're using AGI Studio as your main editor.

3) Patch the Interpreter

This is what I kinda wrote myself.  I wrote a small patch program (that will only work in Windows.. I used MinGW as my compiler) that lets you change the stack size in the interpreter.  It's usually 0xA00 bytes (in all interpreter's I have checked).

The cool thing about this program is that it works with all the versions of Sierra's interpreter that I have checked. (including v3!)  The stack code didn't vary much over the different versions.

1) Get a working AGI file. Try Demo Pack 3 that you can get from The Ultimate AGI & SCI Web Site which is version 2.917 .  There is a later v2.936 interpreter which comes with some versions of SQ2 and KQ3 but isn't freely available without breaking some copyright law.

2) Uncompress AGI executable file. Sierra encrypted their interpreters most of the time and some (like the demo pack 3) aren't encrypted.  Use SUP (available from Ultimate AGI again) to insert a key into SIERRA.COM and the adecrypt (ditto) to decrypt the AGI file.

3) Run stackpatch.exe.   The proper way to run it is:

stackpatch agi.exe 0xA00

where agi.exe is the interpreter and 0xA00 is the stack size to change.  0xA00 is the AGI default.  If you get a stack error, try increasing it to 0xB00 or 0xC00

4) Play with your working game.

Anyway, if you want more information, check out this discussion that had all this information (except about the patch) and probably a bit more.


stackpatch try this stuff man
modified agi 2.936 with stack set to 0xC00.  Works with Pimp Quest on my computer.
modified PIC file for the title



by helping to defray some of the costs of hosting this site. If it has been of help to you, please consider contributing to help keep it online.
Thank you.

© 2013 to present The Sierra Help Pages. All rights reserved. All Sierra games, artwork and music © Sierra.