Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 tasks done
cyn0x8 opened this issue Dec 10, 2024 · 0 comments
Open
2 tasks done

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

cyn0x8 opened this issue Dec 10, 2024 · 0 comments
Labels
status: pending triage The bug or PR has not been reviewed yet. type: minor bug Involves a minor bug or issue.

Comments

@cyn0x8
Copy link
Contributor

cyn0x8 commented Dec 10, 2024

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

@cyn0x8 cyn0x8 added status: pending triage The bug or PR has not been reviewed yet. type: minor bug Involves a minor bug or issue. labels Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: pending triage The bug or PR has not been reviewed yet. type: minor bug Involves a minor bug or issue.
Projects
None yet
Development

No branches or pull requests

1 participant