Skip to content

Bug Report: onDestroy called on modules during PlayState destruction #3928

Description

@lunacynne

Issue Checklist

  • I have properly named my issue
  • I have checked the Issues/Discussions pages to see if my issue has already been reported

Platform

Compiled from GitHub Source Code

Browser

None

Version

0.5.2

Description (include any images, videos, errors, or crash logs)

in Module.hx...

/**
 * Called when a module is destroyed.
 * This currently only happens when reloading modules with F5.
 */
public function onDestroy(event:ScriptEvent) {}

but in PlayState.hx...

/**
 * Perform necessary cleanup before leaving the PlayState.
 */
function performCleanup():Void
{
  // If the camera is being tweened, stop it.
  cancelAllCameraTweens();

  // Dispatch the destroy event.
  dispatchEvent(new ScriptEvent(DESTROY, false));

im assuming this is unintentional...
maybe these events should be unique to each other? it's been a bit of a hassle figuring out how to prevent what would be unrelated cleanup code from running when playstate is destroyed
currently im just doing this:

private var pressedReload:Bool = false; // just in case theres a single frame delay
override public function onUpdate(event:UpdateScriptEvent):Void {
    pressedReload = FlxG.keys.justPressed.F5;
}

override public function onDestroy(event:ScriptEvent):Void {
    if (
        (PlayState.instance != null && PlayState.instance.criticalFailure) ||
        (!FlxG.keys.justPressed.F5 && !pressedReload)
    ) {
        return; // is not reloading
    }
    
    // reloading
}

Steps to Reproduce

trace during onDestroy in a module, it should show up in console when PlayState is destroyed as well as mod reload

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: pending pull requestDependent on a pull request that is currently awaiting review.topic: modsRelated to the creation or use of mods.type: minor bugInvolves a minor bug or issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions