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

Implement index operators for Arrays #627

Merged
merged 1 commit into from
Nov 17, 2021

Conversation

BastiaanOlij
Copy link
Collaborator

Resubmit of GDExceptions array index operators

@BastiaanOlij BastiaanOlij added enhancement This is an enhancement on the current functionality topic:gdextension This relates to the new Godot 4 extension implementation labels Sep 28, 2021
@BastiaanOlij BastiaanOlij added this to the 4.0 milestone Sep 28, 2021
@BastiaanOlij BastiaanOlij self-assigned this Sep 28, 2021
@BastiaanOlij
Copy link
Collaborator Author

Original PR on Vnens repo: vnen#23

note that we're still looking into why Variants are giving issues.

@alessandrofama
Copy link
Contributor

alessandrofama commented Nov 10, 2021

interface needs to be renamed to gdn_interface based on #644 ? (just pulled master and was already using the changes in this PR to test my GDExtension).

@BastiaanOlij
Copy link
Collaborator Author

@alessandrofama Long overdue to rebase, let me clean it up :)

Was it working for you? I was having issues with the Variants themselves before but that may have been resolved by now.

@alessandrofama
Copy link
Contributor

alessandrofama commented Nov 15, 2021

It was not working, but at least I could compile while working on other stuff :D

While looking at the debugger, I noticed that the address of the returned Variant* and Array* (this) were the same here:

Variant *var = (Variant *)internal::gdn_interface->array_operator_index((GDNativeTypePtr *)this, p_index);

Thought that was strange, so stepping through Godot's source, it seems to me that Array::operator[] is not being called before returning the void pointer here:

https://github.com/godotengine/godot/blob/4387f9645b1f54755506804770ba15c6c9cd5094/core/extension/gdnative_interface.cpp#L774-L778

Weirdly enough, calling the operator directly seems to have fixed the crashes for me:

return (GDNativeTypePtr)&self->operator[](p_index);

Hobby dev here, so not sure why it would behave like this 🤔 (might be completely wrong here, have been a gdnative user for a while, but new to the source).

@BastiaanOlij
Copy link
Collaborator Author

That actually makes a lot of sense, what it is likely doing is taking &self first, which is a pointer to the self pointer, and then moving that pointer forward by index. So return (GDNativeTypePtr)&(self[p_index]); would solve it too.
The operator[] syntax might be more clear...

@BastiaanOlij
Copy link
Collaborator Author

Once the fix in Godot is merged, we can merge this. Works like a charm now, thanks @alessandrofama !

@BastiaanOlij
Copy link
Collaborator Author

@akien-mga with the fix in Godot merged, I think we can merge this too, unless we want people to verify if it works first? it worked for me so :)

@akien-mga akien-mga merged commit 8d25e04 into godotengine:master Nov 17, 2021
@akien-mga
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This is an enhancement on the current functionality topic:gdextension This relates to the new Godot 4 extension implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants