-
-
Notifications
You must be signed in to change notification settings - Fork 11
fix(godot): add initialization guard to prevent double plugin init #87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0a18e96
844a7a6
468d476
e283d4a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,11 +27,15 @@ signal developer_provided_billing_android(details: Dictionary) | |
| # Native plugin reference | ||
| var _native_plugin: Object = null | ||
| var _is_connected: bool = false | ||
| static var _is_initialized: bool = false | ||
|
|
||
| # Platform detection | ||
| var _platform: String = "" | ||
|
|
||
| func _ready() -> void: | ||
| if _is_initialized: | ||
| return | ||
| _is_initialized = true | ||
|
Comment on lines
+36
to
+38
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Static guard currently leaves later Early return on Proposed fix static var _is_initialized: bool = false
+static var _shared_native_plugin: Object = null
# Platform detection
var _platform: String = ""
func _ready() -> void:
- if _is_initialized:
- return
- _is_initialized = true
_platform = OS.get_name()
+
+ if _is_initialized:
+ # Reuse class-level initialized native handle for this instance.
+ _native_plugin = _shared_native_plugin
+ return
+
_init_native_plugin()
+ _shared_native_plugin = _native_plugin
+ _is_initialized = true🤖 Prompt for AI Agents |
||
| _platform = OS.get_name() | ||
| _init_native_plugin() | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of an instance variable
_is_initializedfor this guard only prevents multiple calls to_ready()on the same instance (e.g., if a node is removed and re-added to the tree).If the issue described in the PR (duplicate initialization from both Plugin and AutoLoad) results in two separate instances of the script being created, this guard will not prevent both from initializing the native plugin and connecting duplicate signals. While this is a good improvement for robustness, a more definitive fix for duplicate listeners would be to check
_native_plugin.is_connected(signal_name, method)before callingconnect()in the_connect_signals_*methods.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 468d476. Changed _is_initialized to static var so it guards across all instances.