fleabitdev / glsp

The GameLisp scripting language
https://gamelisp.rs/
Apache License 2.0
395 stars 13 forks source link

RData cannot access Libs, allocate heap memory or trigger a GError in their destructor #16

Closed fleabitdev closed 4 years ago

fleabitdev commented 4 years ago

RData types should be able to interact with the active Runtime in their destructor. For example, a Sprite rdata may wish to deregister itself from the Graphics lib when the user calls (free! the-spr).

Currently, when a Runtimeis dropped, it deinitializes all Libs before cleaning up any RData on the heap, and it holds dynamic borrows of certain data structures internal to the GC heap while running RData destructors. This means that practically any interaction with the active Runtime will panic.

The fix will be to have a separate pass where all RData on the heap are freed (as though using the built-in function free!) before doing any other cleanup - in particular, before dropping any Libs.

If possible, we should also add dynamic checks to forbid any RData from calling glsp::add_lib or glsp::rdata in their destructor.

fleabitdev commented 4 years ago

Fixed by 101903b.