Skip to content

Calling methods that return a Ref crashes #751

Closed

Description

@tancop

When trying to call methods like Mesh::get_surface_count and Mesh::surface_get_material I get a crash. This is definitely a GDExtension issue as it doesn't happen when called from GDScript.

Backtrace (for surface_get_material):

================================================================
handle_crash: Program crashed with signal 11
Engine version: Godot Engine v4.0.alpha7.official (3e9ead05f2e87e46b5982cc9a140e172ee98c227)
Dumping the backtrace. Please include this when reporting the bug on https://github.com/godotengine/godot/issues
[1] /lib64/libc.so.6(+0x42750) [0x7f09ad6c9750] (??:0)
[2] godot::Mesh::surface_get_material(int) const (??:0)
[3] ExampleRef::test(godot::Ref<godot::ArrayMesh>) (??:0)
[4] void godot::call_with_variant_args_helper<godot::___UnexistingClass, godot::Ref<godot::ArrayMesh>, 0ul>(godot::___UnexistingClass*, void (godot::___UnexistingClass::*)(godot::Ref<godot::ArrayMesh>), godot::Variant const**, GDNativeCallError&, IndexSequence<0ul>) (??:0)
[5] void godot::call_with_variant_args_dv<godot::___UnexistingClass, godot::Ref<godot::ArrayMesh> >(godot::___UnexistingClass*, void (godot::___UnexistingClass::*)(godot::Ref<godot::ArrayMesh>), void* const*, int, GDNativeCallError&, std::vector<godot::Variant, std::allocator<godot::Variant> > const&) (??:0)
[6] godot::MethodBindT<godot::Ref<godot::ArrayMesh> >::call(void*, void* const*, long, GDNativeCallError&) const (??:0)
[7] godot::MethodBind::bind_call(void*, void*, void* const*, long, void*, GDNativeCallError*) (??:0)
[8] /home/tpotancok/Programs/Godot_v4.0-alpha7_linux.64() [0x3f9f3cf] (??:0)
[9] /home/tpotancok/Programs/Godot_v4.0-alpha7_linux.64() [0x402686b] (??:0)
[10] /home/tpotancok/Programs/Godot_v4.0-alpha7_linux.64() [0x3edbeca] (??:0)
[11] /home/tpotancok/Programs/Godot_v4.0-alpha7_linux.64() [0x174ac87] (??:0)
[12] /home/tpotancok/Programs/Godot_v4.0-alpha7_linux.64() [0x163bb78] (??:0)
[13] /home/tpotancok/Programs/Godot_v4.0-alpha7_linux.64() [0x280eb43] (??:0)
[14] /home/tpotancok/Programs/Godot_v4.0-alpha7_linux.64() [0x1405793] (??:0)
[15] /home/tpotancok/Programs/Godot_v4.0-alpha7_linux.64() [0x4010684] (??:0)
[16] /home/tpotancok/Programs/Godot_v4.0-alpha7_linux.64() [0x27d5a06] (??:0)
[17] /home/tpotancok/Programs/Godot_v4.0-alpha7_linux.64() [0x27d59af] (??:0)
[18] /home/tpotancok/Programs/Godot_v4.0-alpha7_linux.64() [0x280e0df] (??:0)
[19] /home/tpotancok/Programs/Godot_v4.0-alpha7_linux.64() [0x283e61f] (??:0)
[20] /home/tpotancok/Programs/Godot_v4.0-alpha7_linux.64() [0xd5862d] (??:0)
[21] /lib64/libc.so.6(+0x2d560) [0x7f09ad6b4560] (??:0)
[22] /lib64/libc.so.6(__libc_start_main+0x7c) [0x7f09ad6b460c] (??:0)
[23] /home/tpotancok/Programs/Godot_v4.0-alpha7_linux.64() [0xd71cde] (??:0)
-- END OF BACKTRACE --
================================================================

Reproduction project: extension-crash.tar.gz

Activity

  1. added
    bug
    topic:gdextension
    on May 5, 2022
  2. reopened this on Jun 5, 2022
  3. Zylann commented on Jul 1, 2022

    @Zylann
    Collaborator

    godot::___UnexistingClass that looks odd.

    Is this happening exclusively on meshes? My guess is, it's yet another occurence of Ref<T> passing being buggy somewhat, there are already various reported bugs which could be related to this one.

    Note 1: for better troubleshooting of errors you might find, consider compiling the bindings and your library in debug mode, so that more info will be visible, and it will allow you to attach a debugger to inspect variables. For example, it can show that some pointer is null or some memory was used after being freed thanks to a binary pattern etc.

    Note 2:
    register_types.os in your files, .os is a bogus extension, with GCC it should be .o for object files generated by the compiler. That was a mistake done in the past in a SCons script example but keeps being copied by everyone it seems (even though the linker doesn't seem to care about the extension?).

    Note 3:
    Always check for null before accessing a pointer passed from GDScript. I assume it's ok here, but it's to rule out any mistake because it could cause similar crashes.

    Note 4:
    #include <godot_cpp/variant/utility_functions.hpp>
    Where is this file? I don't see it in https://github.com/godotengine/godot-cpp/tree/master/include/godot_cpp/variant

  4. tancop commented on Jul 4, 2022

    @tancop
    ContributorAuthor

    Is this happening exclusively on meshes? My guess is, it's yet another occurence of Ref<T> passing being buggy somewhat, there are already various reported bugs which could be related to this one.

    No, I tested it on a Texture2D and also get a crash. Backtraces here.

    Note 1: for better troubleshooting of errors you might find, consider compiling the bindings and your library in debug mode, so that more info will be visible, and it will allow you to attach a debugger to inspect variables. For example, it can show that some pointer is null or some memory was used after being freed thanks to a binary pattern etc.

    Both are compiled in debug mode. The godot binary is release_debug because it's an official alpha.

    Note 3: Always check for null before accessing a pointer passed from GDScript. I assume it's ok here, but it's to rule out any mistake because it could cause similar crashes.

    Tried that, still segfaults with the same backtrace.

    Note 4: #include <godot_cpp/variant/utility_functions.hpp> Where is this file? I don't see it in https://github.com/godotengine/godot-cpp/tree/master/include/godot_cpp/variant

    I also don't see it, but it works and it's used in the official test project. Odd.

  5. changed the title [-]Calling surface related methods on `Mesh` crashes[/-] [+]Calling methods that return a `Ref` crashes[/+] on Jul 4, 2022
  6. Faless commented on Jul 4, 2022

    @Faless
    Contributor
  7. Zylann commented on Jul 4, 2022

    @Zylann
    Collaborator

    Note when I mean to use debug mode, this won't give more info in crash dumps of Godot. The idea is so you can attach a C++ debugger while running your project so that if a crash occurs it will stop at a breakpoint, allowing to inspect things.

  8. tancop commented on Jul 4, 2022

    @tancop
    ContributorAuthor

    Note when I mean to use debug mode, this won't give more info in crash dumps of Godot. The idea is so you can attach a C++ debugger while running your project so that if a crash occurs it will stop at a breakpoint, allowing to inspect things.

    I attached gdb, that's how I got the new backtraces.

  9. tancop commented on Jul 16, 2022

    @tancop
    ContributorAuthor

    Looks like this is fixed in the new version but only for types that directly extend RefCounted or Resource (Texture2D and ArrayMesh with other base classes still crash). This remaining bug is older and already mentioned in #662.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcrashtopic:gdextension

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions