Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hexagonrecursion/678d6115534ecdff97e5bca164252f5d to your computer and use it in GitHub Desktop.
Save hexagonrecursion/678d6115534ecdff97e5bca164252f5d to your computer and use it in GitHub Desktop.
Implementation enhancement proposal: stay calm and panic()
What should our CBot implementation do when it detects a bug in itself? e.g. can't find a variable by m_nIdent https://github.com/colobot/colobot/issues/1494
1. assert(false) like we currently use in many places is a bit too powerful - it crashes the entire game.
2. A CBot "exception" is not powerful enough - a bunch more CBot code may run in the compromised instance of the interpreter potentially making the problem worse. Also: when I see the code throwing a CBot "exception" I expect this detects a possible user error rather than just being defensive.
It would be great to have a middle ground between a CBot "exception" and assert(false).
I propose we panic(). Here is how I think we should implement panics:
1. Unlike an exception you can not catch() an panic
2. Destructors do not run
3. Finally does not run
4. open files are automatically closed
5. synchronized classes are unlocked
6. AI scripts (scripts on bots or aliens the player can not select) are automatically restarted. It might be a good idea to restart them when they exit with an exception too.
7. Foreground tasks (like goto) are stopped
With this mechanism we can also
1. Keep track of which public classes and functions are used in a program and whether they have been removed or replaced and panic when trying to run an affected program. Would fix https://github.com/colobot/colobot/issues/1628
2. Panic if we detect that the source code of an AI script has changed between save&load. Would fix: https://github.com/colobot/colobot/issues/1623
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment