decentraland / sdk

PM repository for SDK
Apache License 2.0
4 stars 4 forks source link

Sync scenes: crashes if the `getUserData` doesn't set a value before the `syncEntity` is called #1082

Open leanmendoza opened 7 months ago

leanmendoza commented 7 months ago

This issue is happening in Godot (not sure in Bevy nor Explorer-Alpha). It works fine in the current reference client because the promise is resolved immediately (by kernel).

This error is logged by the beer-dispenser scene when it's spawned:

Error: Profile not initialized. Called syncEntity inside the main() function.
    at syncEntity2 (file://~scene.js/:14225:13)
    at main (file://~scene.js/:35761:3)
    at Object._INTERNAL_startup_system [as fn] (file://~scene.js/:36162:26)
    at Object.update (file://~scene.js/:12451:26)
    at async Object.onUpdate (file://~scene.js/:36124:3) msg Some("Profile not initialized. Called syncEntity inside the main() function.") @ JsError { name: Some("Error"), message: Some("Profile not initialized. Called syncEntity inside the main() function."), stack: Some("Error: Profile not initialized. Called syncEntity inside the main() function.\n    at syncEntity2 (file://~scene.js/:14225:13)\n    at main (file://~scene.js/:35761:3)\n    at Object._INTERNAL_startup_system [as fn] (file://~scene.js/:36162:26)\n    at Object.update (file://~scene.js/:12451:26)\n    at async Object.onUpdate (file://~scene.js/:36124:3)"), cause: None, exception_message: "Uncaught Error: Profile not initialized. Called syncEntity inside the main() function.", frames: [], source_line: None, source_line_frame_index: None, aggregated: None 

The SDK is trying to get the primary player profile information async, while the main function is called in the first tick, sync after evaluation (https://adr.decentraland.org/adr/ADR-133).

A possible fix would be to use PlayerIdentityData.get(engine.PlayerEntity) to get primary player data. Other option is to implement retries until the player data is available since the async function can take a bit.