Skip to content

A problem with the Ref #343

Open
Open

Description

@RameshRavone

Bare minimum of the file ai_script.cpp

void AIScript::_init() {
    _enabled = true;
    _source = Dictionary();
}

void AIScript::setSourceCode(String &p_source) {
    Ref<JSONParseResult> res = JSON::get_singleton()->parse(p_source);
    if (res->get_error() == Error::OK) {
        _source = res->get_result();
        emit_signal("changed");
    }
}

void AIScript::set_enabled(bool p_value) {
    ............

while ai_script.h is

class AIScript : public Resource {
    GODOT_CLASS(AIScript, Resource)

public:
    AIScript() {}

    void _init();
    Variant setSourceCode(String &p_source); 

And when I call Ref<AIScript> scr = AIScript::_new() following happens

handle_crash: Program crashed with signal 11
Dumping the backtrace. Please include this when reporting the bug on https://github.com/godotengine/godot/issues
[1] /lib/x86_64-linux-gnu/libc.so.6(+0x46470) [0x7f7751676470] (??:0)
[2] godot() [0x2c39b50] (/home/rameshravone/Works/godot/./core/safe_refcount.h:107)
[3] godot() [0x2c39b0b] (/home/rameshravone/Works/godot/core/reference.cpp:37)
[4] godot() [0x2c3ade8] (/home/rameshravone/Works/godot/./core/method_ptrcall.h:104)
[5] /home/rameshravone/Works/GodotWorkspace/GDNative/TestBlank/demo/addons/test/libgodotai.so(+0x11f18a) [0x7f772c8b418a] (??:0)
[6] godot::Ref<godot::AIScript>::ref_pointer(godot::AIScript*) (??:0)
[7] SimpleClass::method(godot::Variant) (??:0)
[8] void godot::_WrappedMethod<SimpleClass, godot::Variant, godot::Variant>::apply<0>(godot::Variant*, SimpleClass*, godot::Variant**, godot::__Sequence<0>) (??:0)
[9] godot_variant godot::__wrapped_method<SimpleClass, godot::Variant, godot::Variant>(void*, void*, void*, int, godot_variant**) (??:0)
[10] godot() [0x961a42] (/home/rameshravone/Works/godot/modules/gdnative/nativescript/nativescript.cpp:719)
[11] godot() [0x2c02311] (/home/rameshravone/Works/godot/core/object.cpp:?)
[12] godot() [0x2cc9167] (/home/rameshravone/Works/godot/core/variant_call.cpp:?)
[13] godot() [0x5826f3] (/home/rameshravone/Works/godot/modules/gdscript/gdscript.h:435)
[14] godot() [0x50c419] (/home/rameshravone/Works/godot/./core/variant.h:418)
[15] godot() [0x202ecbb] (/home/rameshravone/Works/godot/scene/3d/spatial.h:54)
[16] godot() [0x2bfec5e] (/home/rameshravone/Works/godot/core/object.cpp:933)
[17] godot() [0x1b5af4d] (/home/rameshravone/Works/godot/./scene/scene_string_names.h:52)
[18] godot() [0x1b5af0b] (/home/rameshravone/Works/godot/scene/main/node.cpp:186)
[19] godot() [0x1b600fa] (/home/rameshravone/Works/godot/scene/main/node.cpp:2553)
[20] godot() [0x1b915ea] (/home/rameshravone/Works/godot/scene/main/scene_tree.cpp:465)
[21] godot() [0x456440] (/home/rameshravone/Works/godot/platform/x11/os_x11.cpp:3253)
[22] godot(main+0x99) [0x447c29] (/home/rameshravone/Works/godot/platform/x11/godot_x11.cpp:57)
[23] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf3) [0x7f77516571e3] (??:0)
[24] godot() [0x447ace] (??:?)
-- END OF BACKTRACE --
Aborted (core dumped)
make: *** [Makefile:10: rungame] Error 134

Activity

  1. PhilWun commented on Nov 9, 2019

    @PhilWun

    I have the same problem. It happened after I updated api.json. I tested around and found out, that the problem is, that the new function of NativeScript returns now a Variant instead of an Object. The commit that changed that is godotengine/godot@e2121c9. But I'm not sure yet, why it causes a segmentation fault.

  2. PhilWun commented on Nov 9, 2019

    @PhilWun

    The cause of the segmentation fault is, that the reference count hits 0 during the _new() call. The object gets deleted and a dangling pointer remains.

  3. RameshRavone commented on Nov 10, 2019

    @RameshRavone
    ContributorAuthor

    Thanks @Philius342

  4. Zylann commented on Jun 5, 2020

    @Zylann
    Collaborator

    Just merged a fix, let me know if that works for you now ;)

  5. follower commented on Jun 22, 2020

    @follower

    As of ~ 9eceb16 (i.e. after @Zylann's PR) the __internal_constructor() workaround (mentioned elsewhere) should no longer be necessary and use of it may lead to crash, this should now work correctly:

    • Ref<CustomClass> ref = Ref<CustomClass>(custom_class_instance);

    I've attempting to summarise the current state here: #417

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions