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

Calling a method of your own Reference script within PREDELETE notification fails #31166

Open
Zylann opened this issue Aug 6, 2019 · 6 comments

Comments

@Zylann
Copy link
Contributor

Zylann commented Aug 6, 2019

Godot 3.1.1

I made a script class which has a clear() function, for which the goal is to cleanup some external resources. It can be called by code using the class, or at the destruction of the instance. The only destructor logic that I know of is NOTIFICATION_PREDELETE.
However... that doesn't work :(

extends Node


class Test:
	var a = 42
	
	func _notification(what):
		if what == NOTIFICATION_PREDELETE:
			print("Predelete ", a)
			clear() # Breaks here

	func clear():
		print("Clearing Test ", a)
		

func _ready():
	var test1 = Test.new()
	test1 = null

When I run this, I get the following error:

Attempt to call function 'clear' in base 'null instance' on a null instance.

Which isn't helping here, and makes no sense because _notification was called in the first place. I would like to be be able to call functions of my own script, otherwise I have to entirely copy/paste its contents...

Note: that situation only seems to occur with References. If I inherit Node and free() it, the code runs normally.
I tested with inner classes but the same issue happens with file scripts.

@Zylann Zylann changed the title Calling a method of your own script within PREDELETE notification fails Calling a method of your own Reference script within PREDELETE notification fails Aug 6, 2019
@Xrayez
Copy link
Contributor

Xrayez commented Aug 6, 2019

I've stumbled upon very similar experience in #6784 (comment).

@akien-mga akien-mga added this to the 3.2 milestone Aug 7, 2019
@KoBeWi
Copy link
Member

KoBeWi commented Dec 30, 2019

Hehe
prints("Predelete", self, self.a)
Output: Predelete [Object:null] 42

No idea what happens, but it's still valid in d711c57

@akien-mga akien-mga modified the milestones: 3.2, 4.0 Jan 19, 2020
@KoBeWi
Copy link
Member

KoBeWi commented Dec 19, 2020

Still valid in 16524d4

@Jummit
Copy link
Contributor

Jummit commented Nov 19, 2021

Still valid in v3.4

@dalexeev
Copy link
Member

dalexeev commented Feb 10, 2023

Still reproducible in 4.0 RC 1.

@akien-mga
Copy link
Member

akien-mga commented Aug 3, 2023

Still reproducible in 4.2-dev (0606ba7), and it's crashing:

Predelete 42

================================================================
handle_crash: Program crashed with signal 11
Engine version: Godot Engine v4.2.dev.custom_build (c97e4a31ac85839dea31d84a86c9441b7e775273)
Dumping the backtrace. Please include this when reporting the bug to the project developer.
[1] /lib64/libc.so.6(+0x36980) [0x7f98954ef980] (??:0)
[2] EncodedObjectAsID::get_object_id() const (/home/akien/Projects/godot/godot.git/./core/io/marshalls.cpp:52)
[3] EditorDebuggerInspector::add_stack_variable(Array const&) (/home/akien/Projects/godot/godot.git/./editor/debugger/editor_debugger_inspector.cpp:236 (discriminator 2))
[4] ScriptEditorDebugger::_parse_message(String const&, unsigned long, Array const&) (/home/akien/Projects/godot/godot.git/./editor/debugger/script_editor_debugger.cpp:466)
[5] ScriptEditorDebugger::_notification(int) (/home/akien/Projects/godot/godot.git/./editor/debugger/script_editor_debugger.cpp:939 (discriminator 14))
[6] ScriptEditorDebugger::_notificationv(int, bool) (/home/akien/Projects/godot/godot.git/./editor/debugger/script_editor_debugger.h:60 (discriminator 14))
[7] Object::notification(int, bool) (/home/akien/Projects/godot/godot.git/./core/object/object.cpp:800)
[8] SceneTree::_process_group(SceneTree::ProcessGroup*, bool) (/home/akien/Projects/godot/godot.git/./scene/main/scene_tree.cpp:948)
[9] SceneTree::_process(bool) (/home/akien/Projects/godot/godot.git/./scene/main/scene_tree.cpp:1020 (discriminator 2))
[10] SceneTree::process(double) (/home/akien/Projects/godot/godot.git/./scene/main/scene_tree.cpp:510)
[11] Main::iteration() (/home/akien/Projects/godot/godot.git/main/main.cpp:3443)
[12] OS_LinuxBSD::run() (/home/akien/Projects/godot/godot.git/platform/linuxbsd/os_linuxbsd.cpp:912)
[13] /home/akien/Projects/godot/godot.git/bin/godot.linuxbsd.editor.dev.x86_64(main+0x15a) [0x574bf40] (/home/akien/Projects/godot/godot.git/platform/linuxbsd/godot_linuxbsd.cpp:76)
[14] /lib64/libc.so.6(+0x236b7) [0x7f98954dc6b7] (??:0)
[15] /lib64/libc.so.6(__libc_start_main+0x85) [0x7f98954dc775] (??:0)
[16] /home/akien/Projects/godot/godot.git/bin/godot.linuxbsd.editor.dev.x86_64(_start+0x21) [0x574bd21] (??:?)
-- END OF BACKTRACE --
================================================================

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment