HaxeFlixel / flixel

Free, cross-platform 2D game engine powered by Haxe and OpenFL
https://haxeflixel.com/
MIT License
1.92k stars 427 forks source link

Destroy bug I think #3159

Closed Joalor64GH closed 3 weeks ago

Joalor64GH commented 1 month ago

for some reason, i'm getting an error on this line??

super.destroy();
DetectiveBaldi commented 1 month ago

are you using the object after it's destroyed? also sending an error with 0 other context usually doesn't help fix it, send related code

Joalor64GH commented 1 month ago
override function destroy() {
        instance = null;

        for (lua in luaArray) {
            lua.call('onDestroy', []);
            lua.stop();
        }
        luaArray = [];

        #if HSCRIPT_ALLOWED
        for (i in hscriptMap.keys()) {
            callHscript(i, 'onDestroy', []);
            var hscript = hscriptMap.get(i);
            hscriptMap.remove(i);
            hscript = null;
        }
        hscriptMap.clear();
        #end

        #if hscript
        if (FunkinLua.hscript != null) FunkinLua.hscript = null;
        #end

        FlxG.stage.removeEventListener(KeyboardEvent.KEY_DOWN, onKeyPress);
        FlxG.stage.removeEventListener(KeyboardEvent.KEY_UP, onKeyRelease);

        FlxG.timeScale = 1;
        #if FLX_PITCH FlxG.sound.music.pitch = 1; #end

        super.destroy();
    }
Geokureli commented 1 month ago

Can you include the entire error? it usually gives the exact line number and the type of issue. if you're building in debug it will usually pause on the offending line.

If you're not building with debug features then you're making things much harder for no reason. For more info: https://haxeflixel.com/documentation/visual-studio-code/#debugging

P.S.: Please lmk if you are shadowing any classes, as we can't really help diagnose problems if you subvert our code

Joalor64GH commented 4 weeks ago

Quote reply

Called from openfl.display.Application::exec openfl/display/Application.hx line 130
Called from lime.app.Application::exec lime/app/Application.hx line 150
Called from lime._internal.backend.native.NativeApplication::exec lime/_internal/backend/native/NativeApplication.hx line 146
Called from lime._internal.backend.native.NativeApplication::handleRenderEvent lime/_internal/backend/native/NativeApplication.hx line 375
Called from lime.app._Event_lime_graphics_RenderContext_Void::dispatch lime/_internal/macros/EventMacro.hx line 91
Called from openfl.display.Stage::__onLimeRender openfl/display/Stage.hx line 2177
Called from openfl.display.Stage::__broadcastEvent openfl/display/Stage.hx line 1187
Called from openfl.display.DisplayObject::__dispatch openfl/display/DisplayObject.hx line 1398
Called from openfl.events.EventDispatcher::__dispatchEvent openfl/events/EventDispatcher.hx line 426
Called from flixel.FlxGame::onEnterFrame flixel/FlxGame.hx line 553
Called from flixel.FlxGame::step flixel/FlxGame.hx line 680
Called from flixel.FlxGame::update flixel/FlxGame.hx line 727
Called from flixel.FlxGame::switchState flixel/FlxGame.hx line 625
Called from meta.state.PlayState::destroy meta/state/PlayState.hx line 5917
Called from flixel.addons.ui.FlxUIState::destroy flixel/addons/ui/FlxUIState.hx line 331
Called from flixel.addons.transition.FlxTransitionableState::destroy flixel/addons/transition/FlxTransitionableState.hx line 75
Called from flixel.FlxState::destroy flixel/FlxState.hx line 186
Called from flixel.group.FlxTypedGroup::destroy flixel/group/FlxGroup.hx line 145
Called from flixel.ui.FlxBar::destroy flixel/ui/FlxBar.hx line 203
Called from flixel.ui.FlxBar::set_frontFrames flixel/ui/FlxBar.hx line 990
Critical Error: Uncatchable Throw: Null Object Reference
super.destroy();
Joalor64GH commented 4 weeks ago

i think i get the debugging stuff now lol

Vortex2Oblivion commented 4 weeks ago

Are you shadowing any classes?

Joalor64GH commented 4 weeks ago

What does that mean?

Geokureli commented 4 weeks ago

What does that mean?

are you replacing any flixel classes with your own versions of them by any means? Funkin people tend to do this and it mainly causes errors when updating flixel

Joalor64GH commented 4 weeks ago

Only four of them:

FlxInputText.hx FlxUIInputText.hx FlxDrawQuadsItem.hx FlxTransitionableState.hx

Geokureli commented 4 weeks ago

at this point I would say if debugging doesn't help you, try recreating the issue is a small project that doesn't shadow those classes. otherwise it's impossible to tell what's causing this, and it may not be a problem with flixel, but rather an issue with your code or your shadowing classes.

my guess is that you may be destroying things twice, accidentally, or your shadow classes are causing an error. I always advise against shadowing, if you feel it is necessary in order to accomplish something, let us know, in a github issue. we may offer a better alternative, or we can make a change to flixel to help you

if you are confused on how to debug this, lmk what you're trying

Joalor64GH commented 4 weeks ago

Well, one thing I tried was compiling the game myself in VSC, but I kept getting an error even though I had all of the libraries installed. So instead, I compiled the game using a classic workflow to get the error from the debug log. Basically, I got the error when I exited PlayState. I then decided to refer to the FlxBasic documentation because I thought that might've had to do something with it. I even tried shadowing one class for some reason.

Joalor64GH commented 3 weeks ago

Update: I found out that the issue had to do with something else, but thanks for the help, at least!