Day 19: Stack is corrupted after closing program

Newcomer here. I followed Casey's coding sessions from Day 1 through Day 19 along using Visual Studio 2013 Professional Update 4 as a Microsoft Dreamspark student.

Upon 30 to 50 minutes in into the Day 19 session, I received this error when closing the window (by clicking on the red X button, and sending out the WM_CLOSE message):

Run-Time Check Failure #2 - Stack around the variable 'DebugTimeMarkers' was corrupted.

It only happens when I close the window, but not when I stop the program from debugging. Maybe the check didn't detect the error when stopping the program.

I am wondering if Casey and others had ever come across this error, or it's just my setup being wrong?

Thanks.
Update:

I found the problem.

In this code of Day 19, at 0:47:15 in the video, where Casey is working on the DebugTimeMarkers debug code:

1
2
3
4
5
6
win32_debug_time_marker* Marker = &DebugTimeMarkers[DebugTimeMarkerIndex++];
if (DebugTimeMarkerIndex > ArrayCount(DebugTimeMarkers)){
	DebugTimeMarkerIndex = 0;
}
Marker->PlayCursor = PlayCursor;
Marker->WriteCursor = WriteCursor;


DebugTimeMarkerIndex needs to be greater than or equal to ArrayCount(DebugTimeMarkers) so that it wouldn't go out of bounds and modify the stack.

So I need to add '=' to '>' making '>=' for it to work correctly after closing it.

I hoped Casey sees this, as that is a Index Array Out-of-Bounds error waiting to happen in his code. I wondered if follow-up videos showed Casey fixing this error.

Please spoil me.



Update 2:
It's mentioned in Day 20. Nevermind...

Edited by Thompson Lee on