@@ -36,15 +36,11 @@ GodotJSScriptLanguageBase::~GodotJSScriptLanguageBase()
3636 }
3737}
3838
39- void GodotJSScriptLanguageBase::init ()
39+ void GodotJSScriptLanguageBase::create_environment ()
4040{
41- if (once_inited_) return ;
42-
43- JSB_BENCHMARK_SCOPE (GodotJSScriptLanguageBase, init);
44- once_inited_ = true ;
45- JSB_LOG (Verbose, " Runtime: %s" , JSB_IMPL_VERSION_STRING);
46- JSB_LOG (VeryVerbose, " jsb lang init" );
47-
41+ ++prevent_environment_dispose_;
42+ if (environment_)
43+ return ;
4844 jsb::Environment::CreateParams params;
4945 params.initial_class_slots = (int ) ClassDB::classes.size () + JSB_MASTER_INITIAL_CLASS_EXTRA_SLOTS;
5046 params.initial_object_slots = JSB_MASTER_INITIAL_OBJECT_SLOTS;
@@ -53,34 +49,51 @@ void GodotJSScriptLanguageBase::init()
5349 params.debugger_port = jsb::internal::Settings::get_debugger_port ();
5450 params.thread_id = Thread::get_caller_id ();
5551
56- ++prevent_environment_dispose_;
57- // Initialize only once
58- if (!environment_) {
59- environment_ = std::make_shared<jsb::Environment>(params);
60- environment_->init ();
52+ environment_ = std::make_shared<jsb::Environment>(params);
53+ environment_->init ();
6154
62- // load internal scripts (jsb.core, jsb.editor.main, jsb.editor.codegen)
63- static constexpr char kRuntimeBundleFile [] = " jsb.runtime.bundle.js" ;
64- jsb_ensuref (jsb::AMDModuleLoader::load_source (environment_.get (), kRuntimeBundleFile , GodotJSProjectPreset::get_source_rt) == OK,
65- " the embedded '%s' not found, run 'scons' again to refresh all *.gen.cpp sources" , kRuntimeBundleFile );
66- jsb_ensuref (environment_->load (" jsb.inject" ) == OK, " failed to load jsb.inject" );
55+ // load internal scripts (jsb.core, jsb.editor.main, jsb.editor.codegen)
56+ static constexpr char kRuntimeBundleFile [] = " jsb.runtime.bundle.js" ;
57+ jsb_ensuref (jsb::AMDModuleLoader::load_source (environment_.get (), kRuntimeBundleFile , GodotJSProjectPreset::get_source_rt) == OK,
58+ " the embedded '%s' not found, run 'scons' again to refresh all *.gen.cpp sources" , kRuntimeBundleFile );
59+ jsb_ensuref (environment_->load (" jsb.inject" ) == OK, " failed to load jsb.inject" );
6760
6861#ifdef TOOLS_ENABLED
69- static constexpr char kEditorBundleFile [] = " jsb.editor.bundle.js" ;
70- jsb_ensuref (jsb::AMDModuleLoader::load_source (environment_.get (), kEditorBundleFile , GodotJSProjectPreset::get_source_ed) == OK,
71- " the embedded '%s' not found, run 'scons' again to refresh all *.gen.cpp sources" , kEditorBundleFile );
62+ static constexpr char kEditorBundleFile [] = " jsb.editor.bundle.js" ;
63+ jsb_ensuref (jsb::AMDModuleLoader::load_source (environment_.get (), kEditorBundleFile , GodotJSProjectPreset::get_source_ed) == OK,
64+ " the embedded '%s' not found, run 'scons' again to refresh all *.gen.cpp sources" , kEditorBundleFile );
7265#endif
73- }
7466}
7567
76- void GodotJSScriptLanguageBase::finish ()
68+ void GodotJSScriptLanguageBase::destroy_environment ()
7769{
78- jsb_check (once_inited_);
79- once_inited_ = false ;
70+ if (!environment_)
71+ return ;
8072 if (--prevent_environment_dispose_ == 1 ) {
8173 environment_->dispose ();
8274 environment_.reset ();
8375 }
76+ }
77+
78+ void GodotJSScriptLanguageBase::init ()
79+ {
80+ if (once_inited_) return ;
81+
82+ JSB_BENCHMARK_SCOPE (GodotJSScriptLanguageBase, init);
83+ once_inited_ = true ;
84+ JSB_LOG (Verbose, " Runtime: %s" , JSB_IMPL_VERSION_STRING);
85+ JSB_LOG (VeryVerbose, " jsb lang init" );
86+
87+ create_environment ();
88+
89+ }
90+
91+ void GodotJSScriptLanguageBase::finish ()
92+ {
93+ jsb_check (once_inited_);
94+ once_inited_ = false ;
95+
96+ destroy_environment ();
8497#if !JSB_WITH_WEB
8598 jsb::Worker::finish ();
8699#endif
0 commit comments