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

null result of load() call destroys arrays #41835

Open
z80 opened this issue Sep 7, 2020 · 4 comments
Open

null result of load() call destroys arrays #41835

z80 opened this issue Sep 7, 2020 · 4 comments

Comments

@z80
Copy link

z80 commented Sep 7, 2020

If load() call returns null, this null is destructive for arrays (at least).

function test():
    var classes = []
    var S = load( "res://...." ) # Here load() returns null
    classes.push_back( S ) # At this point "classes" changes from "[]" to "null". I.e. literally null
    return classes # Here it returns "null" instead of "[ null ]".

But if the same code runs without load() then it works as expected. And array is not destroyed.

function test():
    var classes = []
    var S = null
    classes.push_back( S ) # At this point "classes" is totally fine. It goes from "[]" to "[ null ]"
    return classes # returns "[ null ]". I.e. normal behavior.

Godot version is 3.2.2 built from source. OS is Windows 10.

@Calinou
Copy link
Member

Calinou commented Sep 7, 2020

Minimal reproduction project: test_array_load_null.zip

Running both methods in 3.2.2, I get the following output:

Broken: [[Object:null]]
Working: [Null]

("Broken" is the first one, "Working" is the second one.)

@akien-mga
Copy link
Member

Well @Calinou's project doesn't confirm the bug, namely:

    classes.push_back( S ) # At this point "classes" changes from "[]" to "null". I.e. literally null
    return classes # Here it returns "null" instead of "[ null ]".

[[Object:null]] is an Array containing a null Object, which is expected from the code. The classes variable is therefore still an Array.

@Calinou
Copy link
Member

Calinou commented Sep 7, 2020

Maybe this is related to #39465?

@z80
Copy link
Author

z80 commented Sep 7, 2020

Hello!
I'm sorry I didn't examine the problem thoroughly enough. I've made step-by-step screenshots. It looks like what debugger shows contradicts to what print() states about objects. Please see below line-by-line screenshots. I hope it explains better than the original statement.

01
Figure 1. "classes" variable is an empty array.

02
Figure 2. "classes" is still empty array. One of the load() results is shown as T=null, L=Object:7947.

03
Figure 3. Just after adding T=null to "classes" array turns it to null in the debugger window.

04
Figure 4. The same exact function but with print() statements after each line.

05
Figure 5. print() output of the same variable the debugger thinks is null. It shows that the array is still an array. And there are no null objects at all.

It looks like it is just the debugger that is confused by load() result for some reason. And print() shows that even the null return of load() is actually not null but PackedScene:4914.

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

No branches or pull requests

4 participants