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

Fixing reference return #662

Closed

Conversation

BastiaanOlij
Copy link
Collaborator

@BastiaanOlij BastiaanOlij commented Nov 24, 2021

Investigating various issues around using reference, adding use cases to the test project to test them and fixing them.

Note, things are currently broken on the Godot side until godotengine/godot#55282 is merged.
You can work around that issue by commenting out the print statements in the constructors of Example and ExampleRef.

@BastiaanOlij BastiaanOlij added the enhancement This is an enhancement on the current functionality label Nov 24, 2021
@BastiaanOlij BastiaanOlij added this to the 4.0 milestone Nov 24, 2021
@BastiaanOlij BastiaanOlij self-assigned this Nov 24, 2021
@BastiaanOlij
Copy link
Collaborator Author

At this point in time I'm getting a crash when closing the editor after loading the project.
Seems to work in runtime.

Also property inspector stopped working again.

@BastiaanOlij
Copy link
Collaborator Author

The crash I mention here is caused by our issues with initialization, because we have our print in our construct the editor starts constructing additional object and that messes everything up. Groud is working on a rewrite of that. We have a workaround by moving the line initializing_with_extension = true; in class_db.cpp down till after setting our pointers in godot itself.

kb173 added a commit to boku-ilen/geodot-plugin that referenced this pull request Feb 3, 2022
These are likely related to refcounting issues.
The change in the SConstruct script fixes a crash that occured somewhere in `bind_get_argument_type` when registering classes and binding methods.
Commenting out the `delete`s in destructors fixed a `double free or corruption` crash that occured after the fix described above.

Likely related to godotengine/godot-cpp#652, but neither godotengine/godot-cpp#660 or godotengine/godot-cpp#662 seemed to help...
@kb173
Copy link

kb173 commented Feb 3, 2022

Although we already wrote about this in the gdextension Godot chat, I'm summarizing it again here so it doesn't get lost there:

I was getting the following compile error when compiling my GDExtension with this PR (both on your branch and on origin/master with this commit cherry-picked):

godot-cpp/include/godot_cpp/classes/ref.hpp: In instantiation of 'godot::Ref<T>::Ref(godot::Ref<T_Other>&&) [with T_Other = godot::GeoPoint; T = godot::GeoFeature]':
src/geodata.cpp:109:16:   required from here
godot-cpp/include/godot_cpp/classes/ref.hpp:198:40: error: 'godot::GeoPoint* godot::Ref<godot::GeoPoint>::reference' is private within this context
  198 |                 T *swap = (T *)p_other.reference;
      |                                ~~~~~~~~^~~~~~~~~
godot-cpp/include/godot_cpp/classes/ref.hpp:50:12: note: declared private here
   50 |         T *reference = nullptr;
      |            ^~~~~~~~~
godot-cpp/include/godot_cpp/classes/ref.hpp:199:25: error: 'godot::GeoPoint* godot::Ref<godot::GeoPoint>::reference' is private within this context
  199 |                 p_other.reference = (T_Other *)reference;
      |                 ~~~~~~~~^~~~~~~~~
godot-cpp/include/godot_cpp/classes/ref.hpp:50:12: note: declared private here
   50 |         T *reference = nullptr;
      |            ^~~~~~~~~
godot-cpp/include/godot_cpp/classes/ref.hpp: In instantiation of 'godot::Ref<T>::Ref(godot::Ref<T_Other>&&) [with T_Other = godot::GeoLine; T = godot::GeoFeature]':
src/geodata.cpp:118:16:   required from here
godot-cpp/include/godot_cpp/classes/ref.hpp:198:40: error: 'godot::GeoLine* godot::Ref<godot::GeoLine>::reference' is private within this context
  198 |                 T *swap = (T *)p_other.reference;
      |                                ~~~~~~~~^~~~~~~~~
godot-cpp/include/godot_cpp/classes/ref.hpp:50:12: note: declared private here
   50 |         T *reference = nullptr;
      |            ^~~~~~~~~
godot-cpp/include/godot_cpp/classes/ref.hpp:199:25: error: 'godot::GeoLine* godot::Ref<godot::GeoLine>::reference' is private within this context
  199 |                 p_other.reference = (T_Other *)reference;
      |                 ~~~~~~~~^~~~~~~~~
godot-cpp/include/godot_cpp/classes/ref.hpp:50:12: note: declared private here
   50 |         T *reference = nullptr;
      |            ^~~~~~~~~
godot-cpp/include/godot_cpp/classes/ref.hpp: In instantiation of 'godot::Ref<T>::Ref(godot::Ref<T_Other>&&) [with T_Other = godot::GeoPolygon; T = godot::GeoFeature]':
src/geodata.cpp:127:16:   required from here
godot-cpp/include/godot_cpp/classes/ref.hpp:198:40: error: 'godot::GeoPolygon* godot::Ref<godot::GeoPolygon>::reference' is private within this context
  198 |                 T *swap = (T *)p_other.reference;
      |                                ~~~~~~~~^~~~~~~~~
godot-cpp/include/godot_cpp/classes/ref.hpp:50:12: note: declared private here
   50 |         T *reference = nullptr;
      |            ^~~~~~~~~
godot-cpp/include/godot_cpp/classes/ref.hpp:199:25: error: 'godot::GeoPolygon* godot::Ref<godot::GeoPolygon>::reference' is private within this context
  199 |                 p_other.reference = (T_Other *)reference;
      |                 ~~~~~~~~^~~~~~~~~
godot-cpp/include/godot_cpp/classes/ref.hpp:50:12: note: declared private here
   50 |         T *reference = nullptr;
      |            ^~~~~~~~~
scons: *** [src/geodata.os] Error 1
scons: building terminated because of errors.

Note that GeoPoint, GeoLine, and GeoPolygon all inherit from GeoFeature, which inherits from Resource. Seems to be related to this additional layer of inheritance.

I could work around this error by manually making all members of Ref (in godot-cpp/include/godot_cpp/classes/ref.hpp) public.

reduz added a commit to reduz/godot that referenced this pull request Feb 11, 2022
-Creating from object pointer via funcptr API was missing reference initialization.
-Supersedes godotengine/godot-cpp#662
-Fixes several crashes in GDExtension
@BastiaanOlij
Copy link
Collaborator Author

Now basing this on including godotengine/godot#57968 for an upstream fix, so mostly just test cases left.

@@ -9,9 +9,12 @@ func _ready():
($Example as Example).simple_const_func() # Force use of ptrcall
prints("returned", $Example.return_something("some string"))
prints("returned const", $Example.return_something_const())
prints("returned ref", $Example.return_extended_ref())

prints("returned example ref object: ", $Example.return_extended_ref())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did this mean to say "extended" instead of "example"?

kb173 added a commit to boku-ilen/geodot-plugin that referenced this pull request Feb 15, 2022
These are likely related to refcounting issues.
The change in the SConstruct script fixes a crash that occured somewhere in `bind_get_argument_type` when registering classes and binding methods.
Commenting out the `delete`s in destructors fixed a `double free or corruption` crash that occured after the fix described above.

Likely related to godotengine/godot-cpp#652, but neither godotengine/godot-cpp#660 or godotengine/godot-cpp#662 seemed to help...
gaudecker pushed a commit to gaudecker/godot that referenced this pull request Apr 3, 2022
-Creating from object pointer via funcptr API was missing reference initialization.
-Supersedes godotengine/godot-cpp#662
-Fixes several crashes in GDExtension
@Zylann
Copy link
Collaborator

Zylann commented Jul 4, 2022

I think this was a second attempt at fixing #652 (other PR was #660) but this PR doesnt mention any issue number nor the previous PR so... here they are, unless I'm mistaken.

I wonder if it could be related to #751 as well.

@Faless
Copy link
Contributor

Faless commented Dec 15, 2022

Superseded by #958.

@Faless Faless closed this Dec 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
archived enhancement This is an enhancement on the current functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants