Skip to content

Overriding _input, _unhandled_input, or _unhandled_key_input crashes and produces system error #655

Closed

Description

@valentinAlkan

In GDExtensions 4.0, trying to override any of the input functions produces an error when input is detected. Code compiles, project runs normally, and everything is copacetic until input is detected. The following error is produced prior to crashing.

terminate called after throwing an instance of 'std::system_error'
  what():  Invalid argument

Function signature is as follows:

virtual void _unhandled_input(const Ref<InputEvent> &event) override{};

Activity

  1. added
    bug
    topic:gdextension
    on Nov 17, 2021
  2. nwroyer commented on Nov 17, 2021

    @nwroyer

    Looks like this might indicate a more general issue with overriding virtual functions in GDExtension classes - I ran into the same thing with _integrate_forces in #651. It might be worth merging these bug reports as this seems to be related or stemming from the same root cause.

  3. valentinAlkan commented on Nov 19, 2021

    @valentinAlkan
    Author

    A workaround is extending a GDExtension class with a GDSript. Overriding _input functions in GDScript and forwarding the events to another function in the GDExtension class that takes a variant seems to work.

    GDExtensionBaseClassGD.gd

    extends GDExtensionBaseClass
    func _unhandled_input(event: InputEvent):
    	_unhandled_input_forwarded(event)
    

    GDExtensionBaseClass.cpp

    void GDExtensionBaseClass::_unhandled_input_forwarded(Variant varEvent){
            //cast variant to input event
    	InputEvent* event = cast_to<InputEvent>(varEvent);
    	if (!event) return;
    	UtilityFunctions::print("I am a forwarded input event");
    	*do stuff*
        }
    }
    /////////////////////////////
    
    void GDExtensionBaseClass::_bind_methods(){
            ClassDB::bind_method(D_METHOD("_input_forwarded"), &GDExtensionBaseClass::_unhandled_input_forwarded);
    };
    
  4. Faless commented on Jul 28, 2022

    @Faless
    Contributor

    Fixed by #677

  5. added this to the 4.0 milestone on Jul 29, 2022
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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions