Skip to content

Commit 54e6128

Browse files
committed
Fix crash when loading script
1 parent cc59521 commit 54e6128

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/_pythonscript_extension_resource_format_loader.pxi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ cdef class PythonResourceFormatLoader:
136136

137137
script = PythonScript()
138138
script._set_source_code(source_code.into_gd_data())
139+
# Since we pass the script instance to Godot as a variant, we must manually
140+
# increase refcount for the Python object `script` so that it is not deleted
141+
# upon leaving this function.
142+
Py_INCREF(script)
139143
# `into_gd_data()` steal the underlying Godot string, so `source_code`
140144
# ends up containing nothing and we'd rather destroy it early to avoid
141145
# confusions.

0 commit comments

Comments
 (0)