[][src]Module bve_native::panic

Controlling the behavior of BVE when it panics.

Panicking is by definition a bug in BVE, but it does happen, and it needs to be handled before the application is shutdown. The global panic handler consists of two parts. A function pointer and a void* data. They are both stored globally and can be controlled with the functions in this module. The function is called with the void* and a string which contains printable information about the panic.

There is a bve_default_panic_handler which is called if you don't manually set your own. This takes the provided string and prints it to stderr and returns.

Safety

There is a race condition between bve_set_panic_handler and bve_set_panic_data.

This race is, in practice, little cause for concern. As long as no other rust code is executing, there is no problem. If you call these at the beginning of the program, like would be expected, there's no chance of a race.

If:

  • you set the panic handler,
  • you haven't set the panic data to the proper pointer,
  • there is rust code that is currently panicking,

the new panic handler will be called with the wrong pointer. This can cause all kinds of bad things if the panic handler expects that pointer to be of a specific type.

Functions

bve_default_panic_handler

The default panic handler that is automatically installed. Does not touch the data pointer. Prints the string to stderr, panicking (and aborting) if it fails.

bve_get_panic_data

Returns the currently set data to be passed to the panic handler. May be null.

bve_get_panic_handler

Returns the currently set panic handler. Non-null.

bve_set_panic_data

Sets the data passed to the panic handler.

bve_set_panic_handler

Sets the panic handler to the provided function pointer.

Type Definitions

PanicHandler

Function pointer type for the Panic Handler.