Sign in to follow this  
Alerion

A problem I fixed, but I don't really know why it was broken =p

Recommended Posts

Maybe this stupid question will prove refreshing, as I've fixed it even though I'm not exactly sure what was happening. This is just me curious about exactly what had happened to cause this problem. I am using Microsoft Visual C++ Express, the latest version. In a project I was working on, when I added a simple float (or any new member variable) to a class it would crash when the destructor was called on this item. I spent a few hours crawling through the code trying to figure out what was wrong. I'll try and go through every step I went through (no matter how stupid) because I'm not sure what will prove useful XD I tried taking the destructor out. : Got a linker error. I put it back and took the float I added out : Compiled, ran, destructed fine. Put an int in: Crash on destructor. ... Put a bunch of other items in : Crash on destructor. Next I Cleaned Solution, Hit "Build Solution" in the menu, then Rebuild Solution, and now I can add whatever I like to my class and it works fine. So how did cleaning and rebuilding fix my problem? What was my problem? I'm just curious, because I don't like not knowing what was causing the error, lest it not be gone and just in hiding until I get closer to the release date =P I know it's kinda stupid, thanks for taking the time reading this. I appreciate it ^_^b -Ally

Share this post


Link to post
Share on other sites
When you build, there are intermediate files created. I've had situations where some of the files that include an altered header might rebuild and others won't--its like the build system didn't detect the dependency/inclusion correctly or something. Those items that did NOT rebuild will then have the old, incorrect "picture" of the types defined in the header, and it could crash at runtime.

That shouldn't happen often, and I'm not sure what you have to do to make it happen. But I've had it happen. And, as you noticed, a clean-rebuild will typically fix the problem.

Maybe someone else can give insight on how that scenario can come about.

Share this post


Link to post
Share on other sites
It's probably a buffer overrun bug, they can create weird crashes which seem to be "fixed" when something is added or removed.

Share this post


Link to post
Share on other sites
If it was fixed simply by rebuilding, it was most likely what smitty described. Then you could have different parts of code talking to each other, and one part thinks class Foo has 12 members, and the other one thinks it was 13 members, and chaos ensues (and a buffer overrun could very well be the result of that).

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