[Issue/Bug]: Parse error when launching a game with DiscordRPC, even with checks to disable running DiscordRPC in place. #58

Closed
opened 2024-06-01 11:22:00 +00:00 by sourcelocation · 13 comments
sourcelocation commented 2024-06-01 11:22:00 +00:00 (Migrated from github.com)

What happened?

When launching the game on mobile, it crashes while parsing the file where I'm using DiscordRPC, even with checks to avoid running the code on mobile.

Version

1.3.1

Godot Version

4.2.1

Exact steps to reproduce this error

Use DiscordRPC on mobile, but don't run it. You will get this error
image

GDScript

func set_up():
	print(OS.get_name()) # prints: Android
	if is_mobile: return
	DiscordRPC.app_id = 1234945200032317602 # Parse Error

Godot output

No suitable library found for GDExtension: res://addons/discord-rpc-gd/bin/discord-rpc-gd.gdextension. Possible feature flags for your platform: mobile, android, etc2, astc, arm64, template, debug, template_debug

Additional information

No response

Checks

### What happened? When launching the game on mobile, it crashes while parsing the file where I'm using DiscordRPC, even with checks to avoid running the code on mobile. ### Version 1.3.1 ### Godot Version 4.2.1 ### Exact steps to reproduce this error Use DiscordRPC on mobile, but don't run it. You will get this error ![image](https://github.com/vaporvee/discord-rpc-godot/assets/52459150/163ffc5c-ba3c-4406-b731-015a75da1250) ### GDScript ```gdscript func set_up(): print(OS.get_name()) # prints: Android if is_mobile: return DiscordRPC.app_id = 1234945200032317602 # Parse Error ``` ### Godot output `No suitable library found for GDExtension: res://addons/discord-rpc-gd/bin/discord-rpc-gd.gdextension. Possible feature flags for your platform: mobile, android, etc2, astc, arm64, template, debug, template_debug` ### Additional information _No response_ ### Checks - [X] I tried reinstalling the addon or tried to fix it myself with other methods. - [X] I tried restarting Discord and Godot completely. - [X] I did read the documentation https://vaporvee.com/docs/discord-rpc-godot/

there is a function to unregister that in GDExtentionManager i think. will send you a solution when I'm at home. on web it doesnt crash never tested it on mobile tbh

there is a function to unregister that in GDExtentionManager i think. will send you a solution when I'm at home. on web it doesnt crash never tested it on mobile tbh
sourcelocation commented 2024-06-02 10:29:57 +00:00 (Migrated from github.com)

Thank you, will be waiting

Thank you, will be waiting

Sorry for not responding will have time next week

Sorry for not responding will have time next week
sourcelocation commented 2024-07-29 22:54:29 +00:00 (Migrated from github.com)

No problem, I'm still developing my game to this day.

No problem, I'm still developing my game to this day.

Try

if GDExtensionManager.is_extension_loaded("res://addons/discord-rpc-gd/bin/discord-rpc-gd.gdextension"):

before loading any part of the plugin also exclude the plugin in the export settings like the following and tell me if it helped.
Screenshot 2024-08-08 220332
I don't have the project anymore where i accomplished this but i remember GDExtensionManager is the way.

Try ```gdscript if GDExtensionManager.is_extension_loaded("res://addons/discord-rpc-gd/bin/discord-rpc-gd.gdextension"): ``` before loading any part of the plugin also exclude the plugin in the export settings like the following and tell me if it helped. ![Screenshot 2024-08-08 220332](https://github.com/user-attachments/assets/006086fa-32fa-47db-8c88-d163e2f1fcca) I don't have the project anymore where i accomplished this but i remember GDExtensionManager is the way.
sourcelocation commented 2024-08-09 15:20:12 +00:00 (Migrated from github.com)

Thank you 👍

Thank you 👍
Yolwoocle commented 2024-09-10 12:36:11 +00:00 (Migrated from github.com)

Try

if GDExtensionManager.is_extension_loaded("res://addons/discord-rpc-gd/bin/discord-rpc-gd.gdextension"):

before loading any part of the plugin also exclude the plugin in the export settings like the following and tell me if it helped. Screenshot 2024-08-08 220332 I don't have the project anymore where i accomplished this but i remember GDExtensionManager is the way.

This did not seem to work for me, and I still get the Identifier "DiscordRPC" not declared in the current scope error, despite writing code to avoid running lines with DiscordRPC. I know that it was mentioned in #67 that Discord rich presence is not possible, but I would love to know if there is some sort of workaround to avoid having the game crashing on mobile.

> Try > > ```gdscript > if GDExtensionManager.is_extension_loaded("res://addons/discord-rpc-gd/bin/discord-rpc-gd.gdextension"): > ``` > > before loading any part of the plugin also exclude the plugin in the export settings like the following and tell me if it helped. ![Screenshot 2024-08-08 220332](https://private-user-images.githubusercontent.com/80621863/356363706-006086fa-32fa-47db-8c88-d163e2f1fcca.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjU5NzE1MzgsIm5iZiI6MTcyNTk3MTIzOCwicGF0aCI6Ii84MDYyMTg2My8zNTYzNjM3MDYtMDA2MDg2ZmEtMzJmYS00N2RiLThjODgtZDE2M2UyZjFmY2NhLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA5MTAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwOTEwVDEyMjcxOFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTgxNzJmNzJiNDJlMTAyZDVhOGFiNzUzMDg0NWUyMzhiNzAyODM3MjBhNGQ4YmM0NjlmNzU5YTQyMjMyNDRmMTUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.hvlIobfr-wrPIAuqPWKQ6u3DMAjrHL1PI896fmz7I-c) I don't have the project anymore where i accomplished this but i remember GDExtensionManager is the way. This did not seem to work for me, and I still get the `Identifier "DiscordRPC" not declared in the current scope` error, despite writing code to avoid running lines with DiscordRPC. I know that it was mentioned in #67 that Discord rich presence is not possible, but I would love to know if there is some sort of workaround to avoid having the game crashing on mobile.
Yolwoocle commented 2024-09-10 12:40:12 +00:00 (Migrated from github.com)

Ideally, since try/catch patterns are not a thing in Godot, this plugin should avoid causing crashes on unsupported platforms.

Ideally, since try/catch patterns are not a thing in Godot, this plugin should avoid causing crashes on unsupported platforms.

the issue is this is just how godot runs gdextensions i can't change that. Is the autoload maybe still running? you should only add the node conataining a script with discord rpc when the plugin is loaded so you cant do

if GDExtensionManager.is_extension_loaded("res://addons/discord-rpc-gd/bin/discord-rpc-gd.gdextension"):
    DiscordRPC.app_id= xyz

instead you need to do

if GDExtensionManager.is_extension_loaded("res://addons/discord-rpc-gd/bin/discord-rpc-gd.gdextension"):
    add_child(your_node_with_discord_rpc_xyz)
the issue is this is just how godot runs gdextensions i can't change that. Is the autoload maybe still running? you should only add the node conataining a script with discord rpc when the plugin is loaded so you cant do ```gdscript if GDExtensionManager.is_extension_loaded("res://addons/discord-rpc-gd/bin/discord-rpc-gd.gdextension"): DiscordRPC.app_id= xyz ``` instead you need to do ```gdscript if GDExtensionManager.is_extension_loaded("res://addons/discord-rpc-gd/bin/discord-rpc-gd.gdextension"): add_child(your_node_with_discord_rpc_xyz) ```

then you maybe make a manager with the node saved and run stuff on it when its not null

then you maybe make a manager with the node saved and run stuff on it when its not null
Yolwoocle commented 2024-09-11 16:36:28 +00:00 (Migrated from github.com)

Okay, thank you for your answer. I ended up making a scene for the Discord rich presence, and put something like this in my main autoload, which seems to do the trick.

func is_discord_rpc_supported() -> bool:
	return game_platform == GamePlatform.PC and GDExtensionManager.is_extension_loaded("res://addons/discord-rpc-gd/bin/discord-rpc-gd.gdextension")

func _init_discord_rpc():
	if not is_discord_rpc_supported():
		return
	
	var discord_rich_presence_scene: PackedScene = load("res://scenes/integration/discord_rich_presence.tscn")
	discord_rich_presence = discord_rich_presence_scene.instantiate()
	add_child(discord_rich_presence)
	
	discord_rich_presence.initialize()
Okay, thank you for your answer. I ended up making a scene for the Discord rich presence, and put something like this in my main autoload, which seems to do the trick. ```gdscript func is_discord_rpc_supported() -> bool: return game_platform == GamePlatform.PC and GDExtensionManager.is_extension_loaded("res://addons/discord-rpc-gd/bin/discord-rpc-gd.gdextension") func _init_discord_rpc(): if not is_discord_rpc_supported(): return var discord_rich_presence_scene: PackedScene = load("res://scenes/integration/discord_rich_presence.tscn") discord_rich_presence = discord_rich_presence_scene.instantiate() add_child(discord_rich_presence) discord_rich_presence.initialize() ```

I'll add that to the troubleshooting guide if that's okay :)

I'll add that to the troubleshooting guide if that's okay :)
Yolwoocle commented 2024-10-03 20:33:36 +00:00 (Migrated from github.com)

I'll add that to the troubleshooting guide if that's okay :)

Sounds good. Feel free to use my bit of code if needed

> I'll add that to the troubleshooting guide if that's okay :) Sounds good. Feel free to use my bit of code if needed
Sign in to join this conversation.
No description provided.