LennyPhoenix / GodotDiscordSDK

A Discord Game SDK wrapper for Godot, written in C.
MIT License
54 stars 5 forks source link

Core.get_activity_manager() lags and crashes Godot editor for an EditorPlugin #21

Closed 3ddelano closed 2 years ago

3ddelano commented 2 years ago

System Info

Describe the bug

After calling core.get_activity_manager() the Godot editor hangs and crashes for an EditorPlugin.

To Reproduce

  1. Use this code:
    
    tool
    extends EditorPlugin

var core: Discord.Core var activities: Discord.ActivityManager

func _enter_tree() -> void: create_core()

func destroy_core(): core = null activities = null

func create_core(): destroy_core() core = Discord.Core.new() var result: int = core.create(928212232213520454, Discord.CreateFlags.DEFAULT)

if result != Discord.Result.OK:
    print("Failed to initialize DiscordGameSDK")
    destroy_core()
    return

print("Connected to Discord Application")
# Crashes if the below line is not commented
activities = core.get_activity_manager()

func _process(delta: float) -> void: if core: var result: int = core.run_callbacks() if result != Discord.Result.OK: print("Callbacks failed: ")


2. Godot editor only crashes if the line not commented out `activities = core.get_activity_manager()`

## Expected behaviour
The core.get_activity_manager() should have returned a valid Discord.ActivityManager

## Checklist
<!-- Place an `X` between the square brackets. -->
- [x] I have checked for duplicate issues.
- [x] I have provided a detailed description of the issue.
- [x] I have provided reproduction steps (if applicable).
LennyPhoenix commented 2 years ago

If you run the project directly from a terminal do you get an error?

LennyPhoenix commented 2 years ago

Crashes like this usually show up on Godot's terminal output instead of the in editor

LennyPhoenix commented 2 years ago

After looking into this, I can confirm that the error occurs. It looks like something strange is happening though, as the run_callbacks function seems to give this error after a few calls:

SCRIPT ERROR: create_core: Invalid call. Nonexistent function 'run_callbacks' in base 'Reference (core.gdns)'.
   At: res://addons/plugin_test/plugin.gd:26.

It will also occasionally crash with a Segmentation fault (core dumped) error, which is slightly more concerning. I'm going to attempt to debug the error but this codebase is a complete mess to begin with so I can't make any promises.

LennyPhoenix commented 2 years ago

(Misclicked :P)

LennyPhoenix commented 2 years ago

I give up, this codebase is a complete mess to be honest. I will be rewriting the library in Rust at some point in the future, most likely when GDExtension is released. GameSDK is becoming less and less supported as time goes on anyway, so the next library might just end up interfacing with IPC directly.

LennyPhoenix commented 2 years ago

I might give this another look at some point, but I haven't got much free time to work on issues like this when the code is so awful. I'm not sure what motivated past-me to write this in C, but it was a mistake for sure.

3ddelano commented 2 years ago

Great. I'll close this for now

LennyPhoenix commented 2 years ago

I created a quick test project to see how this would look in Rust, it is very promising so far. However, I tried testing this issue using that implementation, and even the most basic class yields the same error:

#[derive(NativeClass)]
#[inherit(Object)]
pub struct Test;

#[methods]
impl Test {
    fn new(_owner: &Object) -> Self {
        Test
    }

    #[export]
    fn hello_world(&mut self, _owner: &Object) {
        godot_print!("Hello World!");
    }
}

image

It appears this may be an issue with GDNative in general, I will make a bug report on the Godot repo as soon as possible.

LennyPhoenix commented 2 years ago

Hm, looks like it does work in some scenarios, I'm going to look into this more later.

3ddelano commented 2 years ago

Yes I too have some issues in trying to get the C++ version of the GameSDK binded in Godot. For some reason the godot editor says "Cant open dynamic library". It happens of if I try to call some method from discord.