Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2002:
[Freeciv-Dev] concerning the use of assert
Home

[Freeciv-Dev] concerning the use of assert

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] concerning the use of assert
From: "Per I. Mathisen" <per@xxxxxxxxxxx>
Date: Sun, 1 Sep 2002 12:57:50 +0000 (GMT)

I've had a little discussion with Ross about the use of asserts. While I
enjoy using them liberally myself, I can see his point about making the
game a minefield of potential cores that can often be avoided when we can
instead return to a sane state.

The problem with doing such error recovery instead of an assert is that
with an assert we get error reporting, with the former the error goes
unreported.

There should be a way to get the best of both worlds.

How about a function which can be called instead of assert, and which
writes a bug report to file then creates a savegame to match, and finally
notifies the player that a bug was detected and that he/she should send
the bug report in to us. Maybe we could even launch gdb on ourself to get
a backtrace on some platforms. Then do error recovery as best as we can.

The interface could be something like

        bool error(condition)

which returns (!condition), so that we can do

        if (error(punit == NULL || pdefender == NULL)) {
                /* error recovery */
                return;
        }

and then on some commandline switch becomes an assert(FALSE) instead for
debugging.

Though maybe the create-savegame part should be separate from the error()
call, since we may not always be in a position to create a sane
savegame...

Other ideas?

Yours
Per

"I don't see why people are so upset about cloning sheep. American
television networks have been doing that to their audiences for years."
-- Jello Biafra



[Prev in Thread] Current Thread [Next in Thread]