General way of solving Error: Stack around the variable 'x' was corrupted

Is there a general way to debug this error with VS2010?

No, there isn't. What you have done is to somehow invoke undefined behavior. The reason these behaviors are undefined is that the general case is very hard to detect/diagnose. Sometimes it is provably impossible to do so.

There are however, a somewhat smallish number of things that typically cause your problem:

  • Improper handling of memory:
    • Deleting something twice,
    • Using the wrong type of deletion (free for something allocated with new, etc.),
    • Accessing something after it's memory has been deleted.
  • Returning a pointer or reference to a local.
  • Reading or writing past the end of an array.

This can be caused by several issues, that are generally hard to see:

  • double deletes
  • delete a variable allocated with new[] or delete[] a variable allocated with new
  • delete something allocated with malloc
  • delete an automatic storage variable
  • returning a local by reference

If it's not immediately clear, I'd get my hands on a memory debugger (I can think of Rational Purify for windows).