Sign in to follow this  
bugboy

GAH! WTF?

Recommended Posts

My programming life just went from fine to horrible in about 5 minutes. This is what happened. 1. Started MSVC7 and loaded my game. 2. Coded some new code. 3. Noticed that my new code gave me a weird asm error and took it out. 4. Tested my code in the state where it was a day ago when it worked and still got the error. 5. Pasted in my code from two days ago and still got the error. 6. Restarted and still got the error. And here's the error: First-chance exception at 0x00512a15 in shooter.exe: 0xC00000FD: Stack overflow. Unhandled exception at 0x00512a15 in shooter.exe: 0xC00000FD: Stack overflow. It then takes me to an asm file called chkstk.asm and gives me this code: The fourth line is the line it says is the error. probepages: sub ecx,_PAGESIZE_ ; yes, move down a page sub eax,_PAGESIZE_ ; adjust request and... test dword ptr [ecx],eax ; ...probe it cmp eax,_PAGESIZE_ ; more than one page requested? jae short probepages ; no I'm not very good at techinical things like this, I've only been programming in c++ for a few months, its just that I had 4+ years of prior experience in java, vb and basic so I've been able to make alot of progress.

Share this post


Link to post
Share on other sites
Try a clean rebuild from nothing. Sometimes that's all it takes.

Also, I would add that even if you're just working on a project by yourself, having some kind of source revision control can be a complete and total lifesaver. I put all my projects on sourceforge and use TortoiseCVS to manage it and I never have to worry about changes that may have broken something because I always have a revision history to look at. It's saved my bacon many, many times.

Share this post


Link to post
Share on other sites

your overflowing your stack, check your functions maybe one has a huge array defined or something (place it on the heap [global] or malloc it). Or try a complete rebuild.

Share this post


Link to post
Share on other sites
Rebuild didn't work. I did notice that when I changed the number of an array it worked up to the main loop instead of crashing before the window even appeared. But the array was tiny, I was changing it from 5 to 1.

Share this post


Link to post
Share on other sites
Try to make sure you're not using recursive functions that can go down to huge depths, and that you're not returning functions, as this is the same thing as recursion although people sometimes don't see it. Other than that all I can suggest is setting a few breakpoints to find out more about where things are going wrong.

Share this post


Link to post
Share on other sites
Using breakpoints it seems that the error is starting at the function that updates the enemies. I commented it out and now the error happens again at the function that updates bullets. So I kept on going and commented out a bunch of stuff and now it apparently does one loop before giving me the error somewhere else.

I'm pretty sure that none of my functions are recursive. Maybe I should try sending someone my code and seeing if it works on their comp.

I think the real question should be why does code that ran perfectly a few days ago give me a error today?

Share this post


Link to post
Share on other sites
Are you certain the compiler settings haven't been accidently or unexpectedly set to make the requested stack space smaller than usual? I would try your code, but I only have MSVC++ 6.0 and the 8.0 Express Beta.

Share this post


Link to post
Share on other sites
If the problem didn't arise before the code changes, then the new code is at fault. Check it. Check it for dangling pointers, array out-of-bounds etc. Debug. Step through your code section by section until the error occurs. Check the section.

Share this post


Link to post
Share on other sites
Gee, I think alot of you didn't even read my first post. I told you that I had a backup from 2 days ago that I know for a fact worked perfectly, I tried that and it gave me the same error.

I have a feeling that either my compiler or computer is f*cked up.

Mastaba, my code will most likely run on MSVC6, but I forgot to mention that the game uses Clanlib which I doubt you have.

Share this post


Link to post
Share on other sites
EVERY time have see something like this in my game it related to some other piece of code that I changed and overran a buffer, or used a wild pointer and generally destroyed my own stack. Here is the method I devised to work though the problem:

1) Backup your whole source tree every time you open the editor. Just replace the icon with a link to the batch file that later starts the ide. Backup on load is a pain but for me a life saver.

2) Write a small utility to add date to a filename(rename). So, Shooter.zip becomes Shooter Sun Jul 18 17_15_01 2004.zip. Add this to the batch file above.

I have a copy of my code from every time I have opened the game source dating back for about 3-4 years. I can rebuild the whole game to any point in that history. I have added a few tweaks like using 7zip's 7z.exe and excluding files I don't need. In total I only have about 40mb in my backup directory. Each backup costs me about 300k of disk.

Dir /s > New.txt on new source tree vs old source tree...etc. Use something like windiff to compare the differences. There is probably a better way to do this. This will tell you all the files that changes. My code has 627 small files, isolating changes. Then do a diff on the files that are different.

Ok. That’s helps isolating change to certain files. Other things to check:

-Ensure that you don't have bad data, ie include your data files in the above backups and version checking. I spent all day looking for a bug in my TTF code only to discover that my menu configuration file specified the wrong TTF file(which was not a ttf file :) )

-Binary search your code. Partition problematic code in half, if you can comment out the roots of great chunk of code. Once a section is found to fail, Copy the bits up smaller and smaller until you can work out what part of your game you can comment out without causing the crash. I do this second as it's less methodical and less likely to produce results. Occasionally just commenting out a big hunk of code will hide a problem rather than isolate it.

-Always leave your code in a compiling and running state before changing more stuff. I have a horrid habit of starting to fix something small and reengineering 3-4 critical subsystems at once at the end of it. My code will often not compile for weeks. Don't do this. I'm an idiot.

I didn't intend to solve your problem rather show you how to stop wasting time on this later, all learnt by wasting my time...

Share this post


Link to post
Share on other sites
Gimp, most of your suggestions just seemed too much effort or I didn't get them.

I did comment out large swaths of code and actually got some results.

First I commented out my entire main loop except where it flips the back buffer and cleared the screen. This actually got the program to work, but all I had was a blank screen. Then I uncommented the part where it draws the player and that worked too.

I uncommented the next line where it did a function call that checked if the player had collided with a tile and that brought back the error. The weird part is when I deleted everything in the function and had it return 0 it still gave me the error.

Just for the hell of it I'll post my functions code and see if anyone sees something wrong with it.

int tilecol(Csprite spr, int colt,float SCX, float SCY,bool ncol=false,bool bcol=false,bool youzs=false) {
CL_Rect sprRect;
CL_Rect tilerect;

int tx;
int ty;
int bob=0;
tx=int((spr.x)/32)+int(SCX/32);
ty=int((spr.y)/32)+int(SCY/32);
for (nx = tx-1; nx<=tx+int(spr.width/32)+1; nx++) {
for (ny = ty-1; ny<=ty+int(spr.height/32)+1; ny++) {
if (nx>-1 && ny>-1 && nx<=NUMX && ny<=NUMY) {
if (ncol && til[nx][ny].col!=colt) {goto gai;}
if (til[nx][ny].col==colt && ncol==false) {
gai:
sprRect.top=spr.y;
sprRect.left=spr.x;
sprRect.bottom=spr.y+spr.height;
sprRect.right=spr.x+spr.width;
if (youzs) {
sprRect.top=(sh/2)-32+you.vy;
sprRect.left=(sw/2)-32+you.vx;
sprRect.bottom=(sh/2)+32+you.vy;
sprRect.right=(sw/2)+32+you.vx;
}
tilerect.top=(ny*32)-SCY;
tilerect.left=(nx*32)-SCX;
tilerect.bottom=32+(ny*32)-SCY;
tilerect.right=32+(nx*32)-SCX;

if (tilerect.is_overlapped(sprRect)) {
bob=1;
if (bcol) {
if (til[nx][ny].id>1 && til[nx][ny].id<5) { til[nx][ny].id++; if (til[nx][ny].id==5) til[nx][ny].col=false;}
}
//if ((tilerect.left+16)+(32/1.5)>(sprRect.left+(spr.width/2)) && (tilerect.left+16)<(spr.width/1.5)+(sprRect.left+(spr.width/2))) {bob=2;}
//if ((tilerect.top+16)+(32/1.5)>(sprRect.top+(spr.height/2)) && (tilerect.top+16)<(spr.height/1.5)+(sprRect.top+(spr.height/2))) {bob=5;}
}
}
}
}
}
return bob;
}

Share this post


Link to post
Share on other sites
One thing does occur - you're passing your Csprite by value, not reference. How big (memory usage-wise) is the sprite? Does it dynamically allocate its image buffers or store them as class member arrays? If the latter, you're passing a fkukload of data on the stack every time you call this function - try passing it by reference instead (change it to "Csprite& spr, ..." instead).

Plus make sure that you've correctly implemented your 'equals' operator and copy constructor, they will be being called and may be recursing.

Share this post


Link to post
Share on other sites
Trying to grow the stack more than 4k at a time is a big nono, since that would touch the page after the guardpage in charge of growing the stack. And this is for some reason what seems to happen.
You could have a look at the prologue of the function, the first lines of it in asm, looking something like

push ebp
mov ebp,esp
sub esp,<some value here>

If you're subtracting a large value from esp, you'd better have a look around for large arrays or objects declared locally.
If nothing weird shows up there, you could try writing your own prologue.
Declare the function using __declspec(naked), and in the beginning add the following

_asm {
push ebp
mov ebp,esp
sub esp,__LOCAL_SIZE ; I think, it could be named something else, have a look at MSDN
}


and before you return from the function

mov esp,ebp
pop ebp
mov eax,[bob]
ret


An remove the return bob, since that's handled in the epilogue.

Oh, and another thing. Could you please show me the callstack when the exception is thrown?

Share this post


Link to post
Share on other sites
I've been using Vault from sourcegear lately. A single user instance is free, and it uses MSSQL Server as the backend (you can use MSDE if you want).

It has atomic commits, and is available over the internet if that sort of thing takes your fancy. I use it in a professional sense (I am an IT Consultant, and this allows me to access my repository from client sites) and have nothing but praise for it (at time of writing....).

P.S. Excuse any spelling mistakes. The footy is on, i've had a few beers, and I've got a new keyboard and it's hard to get used to!

Share this post


Link to post
Share on other sites
Quote:
Original post by d000hg
Are there any decent, totally free source control apps? Particularly ones which integrste with MSVC and include a difference tool?


Perforce is by far the best sourcecontrol i've ever tried.
And it's free for 2 users.

Share this post


Link to post
Share on other sites
Quote:
Original post by bgreen
I've been using Vault from sourcegear lately. A single user instance is free, and it uses MSSQL Server as the backend (you can use MSDE if you want).

It has atomic commits, and is available over the internet if that sort of thing takes your fancy. I use it in a professional sense (I am an IT Consultant, and this allows me to access my repository from client sites) and have nothing but praise for it (at time of writing....).

P.S. Excuse any spelling mistakes. The footy is on, i've had a few beers, and I've got a new keyboard and it's hard to get used to!


I hear Arild's AnkhSVN is good, but as my project uses neither MSVC++ nor subversion I haven't used it.

Share this post


Link to post
Share on other sites
Quote:
Original post by etothex
Quote:
Original post by bgreen
I've been using Vault from sourcegear lately. A single user instance is free, and it uses MSSQL Server as the backend (you can use MSDE if you want).

It has atomic commits, and is available over the internet if that sort of thing takes your fancy. I use it in a professional sense (I am an IT Consultant, and this allows me to access my repository from client sites) and have nothing but praise for it (at time of writing....).

P.S. Excuse any spelling mistakes. The footy is on, i've had a few beers, and I've got a new keyboard and it's hard to get used to!


I hear Arild's AnkhSVN is good, but as my project uses neither MSVC++ nor subversion I haven't used it.


I tried it, but it was taking so long to setup and get working properly, I changed direction - this probably was due to the bullshit that I went through in trying to get subversion working correctly - I'm the sort of person who doesn't have time to "play" with stuff to get it working. I want to be able to install it, configure it, and have a working solution now!

I'm not normally one to promote products or anything like that, but I really have to say that this Vault has worked flawlessly for me over recent months.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this