0 votes

Hi, I'm having a issue when i use GDNative (C++) with my game, When i press the "run" button appears the Godot logo but then the application closes, I checked my code many times but i cannot find the error.

Note: My build configuration is Debug and x64.

This is my code:

lib.cpp:

#include "Common.h"
#include "Player.h"

using namespace godot;

extern "C" void GDN_EXPORT godot_gdnative_init(godot_gdnative_init_options * o) 
{
    Godot::gdnative_init(o);
}

extern "C" void GDN_EXPORT godot_gdnative_terminate(godot_gdnative_terminate_options * o) 
{
    Godot::gdnative_terminate(o);
}

extern "C" void GDN_EXPORT godot_nativescript_init(void* handle) 
{
    Godot::nativescript_init(handle);

    register_class<godot::Player>();
}

Common.h:

include <Godot.hpp>

using namespace godot;

Player.h:

#pragma once

#include <KinematicBody2D.hpp>
#include "Common.h"

namespace godot
{
    class Player : public KinematicBody2D
    {
        GODOT_CLASS(Player, KinematicBody2D);

    public:
        static void _register_methods();
        void _ready();
        void _process(float delta);

        Player();
        ~Player();
    };
}

Player.cpp:

#include "Player.h"

namespace godot
{
    Player::Player()
    {

    }

    Player::~Player()
    {

    }

    void Player::_register_methods()
    {
        register_method("_ready", &Player::_ready);
        register_method("_process", &Player::_process);
    }

    void Player::_ready()
    {
        Godot::print("Hello, World!");
    }

    void Player::_process(float delta)
    {

    }
}
Godot version 3.3.0
in Engine by (22 points)
retagged by

1 Answer

+2 votes
Best answer

you have to register the _init method even if you aren't going to use it.

by (50 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.