Saturday 17 January 2015

Building TRViewer – part 3

We have successfully built both the Debug and Release configurations of TRViewer but when you try to open a file using the toolbar or menu in the Debug version TRViewer stops with the following runtime error.

Debug configuration runtime error

This is not a program “crash” in the ordinary sense.

The program “hit” an ASSERT statement which halted the program.

Programmers write ASSERT statements into their code to alert them that some critical condition has not been met which may cause the program to malfunction if the program kept executing.

An ASSERT statement is only compiled into Debug configurations of a program or DLL so this is why the Release version of TRViewer did not get this error.

This message tells us that there is something wrong with the code even though the Release version seems to work correctly.

Clicking “Abort” will stop the program.

If you click the “Ignore” the program will try to ignore the error and continue.

If you click “Retry” you will be presented with another dialog which gives you the option to “Break” or “Continue”.

Break or continue

Clicking “Continue” is the same as clicking “Ignore” previously.

Clicking “Break” will return you to the Visual Studio debugger and hopefully to the line of code that was executing when the program stopped.

You would normally hit “Break” when debugging an application to try and find where the error is in your code.

In this case we do not return to the error line because the assertion is in a *.dll and we don’t have the necessary extra Visual Studio files to go to the exact line.

The message however tells you the line and file where the ASSERT statement was hit.

We need to check line 473 of docmgr.cpp which is not in the location displayed in the message but found at:

"C:\Program Files\Microsoft Visual Studio 12.0\VC\atlmfc\src\mfc\docmgr.cpp"

The assert we hit

The comments for the ASSERT tell us that the formatting of our extensions in the document template string is incorrect.

The document template string is the list of file types and extensions that appear in the open and save dialogs.

File filter extensions

Stop the debugger and go to EDIT>Find and Replace>Find in Files and search for “.phd”.

Find the string

The file filter strings are part of the resources so double click on the *.rc file in the Find Results list to go to the line code.

Find Results

Do you see what’s wrong with line 1199 shown below?

IDR_TRVIEWTYPE          "\nTRView\nTRViewer\nTomb Raider Files (*.phd,*.tub;*.tr2;*.tr4)\n.phd;*.tub;*.tr2;*.tr4\nTRViewer.Document\nTRViewer Document"

We need to remove the asterisks, “*” from the extensions which are not inside the parentheses.

Change line 1199 of TRViewer.rc to:

IDR_TRVIEWTYPE          "\nTRView\nTRViewer\nTomb Raider Files (*.phd,*.tub;*.tr2;*.tr4)\n.phd;.tub;.tr2;.tr4\nTRViewer.Document\nTRViewer Document"

Save the change and build the Debug configuration of TRViewer and the Debug version now opens an Open File dialog when the open menu or toolbar button is clicked.

Commit your changes to source control.

Now the Debug version is working correctly, you run TRViewer in the debugger and if the program crashes when opening your level or performing an operation on your level you can click “Retry” and “Break” to study the source code variables where the program stopped and hopefully find and fix the problem. (HeinzFritz!)


prev | next | first

No comments:

Post a Comment