forked from rosebudai/OpenRCT2-Web
ScBase::Unregister() freed the class prototype but kept proto and protoCtx. The script classes are globals and the JS runtime is freed when a context is destroyed, so these values become dangling pointers. The script classes are registered only by ScriptEngine::Initialise(), but ~ScriptEngine() always unregisters them. Destroying a context whose script engine was never initialised, after an initialised one had been destroyed, therefore freed the stale prototype again through the freed JSContext. On Windows this crashed WaterObjectTest when it ran after TileElementsViewTests in the same test process. Reset proto and protoCtx after freeing them, and add a test that destroys an uninitialised context after an initialised one. Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>