14
14
15
15
using namespace godot ;
16
16
17
- DartScript::DartScript () : _source_code(), _needs_refresh( false ), _dart_type(nullptr ), _script_info(nullptr ) {
17
+ DartScript::DartScript () : _source_code(), _dart_type(nullptr ), _script_info(nullptr ) {
18
18
}
19
19
20
20
DartScript::~DartScript () {
@@ -41,7 +41,7 @@ void DartScript::_bind_methods() {
41
41
}
42
42
43
43
godot::Ref<Script> DartScript::_get_base_script () const {
44
- const_cast <DartScript *>(this )->refresh_type ();
44
+ const_cast <DartScript *>(this )->refresh_type (false );
45
45
46
46
return _base_script;
47
47
}
@@ -73,7 +73,7 @@ bool DartScript::_can_instantiate() const {
73
73
return default_return; \
74
74
} \
75
75
\
76
- const_cast <DartScript *>(this )->refresh_type (); \
76
+ const_cast <DartScript *>(this )->refresh_type (false ); \
77
77
if (_script_info == nullptr ) { \
78
78
return default_return; \
79
79
}
@@ -238,11 +238,8 @@ godot::Error DartScript::_reload(bool keep_state) {
238
238
239
239
if (bindings != nullptr ) {
240
240
bindings->reload_code ();
241
- _needs_refresh = true ;
242
241
}
243
242
244
- // Don't set _last_modified_time here, as it will be set by did_hot_reload();
245
-
246
243
return godot::Error::OK;
247
244
}
248
245
@@ -285,7 +282,7 @@ godot::Variant DartScript::_get_property_default_value(const godot::StringName &
285
282
}
286
283
287
284
void DartScript::_update_exports () {
288
- refresh_type ();
285
+ refresh_type (true );
289
286
290
287
for (const auto &script_instance : _placeholders) {
291
288
script_instance->notify_property_list_changed ();
@@ -344,7 +341,7 @@ void *DartScript::_instance_create(Object *for_object) const {
344
341
return nullptr ;
345
342
}
346
343
347
- const_cast <DartScript *>(this )->refresh_type ();
344
+ const_cast <DartScript *>(this )->refresh_type (false );
348
345
if (_dart_type == nullptr ) {
349
346
return nullptr ;
350
347
}
@@ -362,7 +359,7 @@ void *DartScript::_placeholder_instance_create(Object *for_object) const {
362
359
return nullptr ;
363
360
}
364
361
365
- const_cast <DartScript *>(this )->refresh_type ();
362
+ const_cast <DartScript *>(this )->refresh_type (false );
366
363
if (_dart_type == nullptr ) {
367
364
return nullptr ;
368
365
}
@@ -410,20 +407,21 @@ void DartScript::clear_property_cache() {
410
407
_properties_cache.clear ();
411
408
}
412
409
413
- void DartScript::refresh_type () {
410
+ void DartScript::refresh_type (bool force ) {
414
411
GodotDartBindings *bindings = GodotDartBindings::instance ();
415
412
if (bindings == nullptr ) {
416
413
return ;
417
414
}
418
415
419
- if (_dart_type != nullptr && !_needs_refresh) {
420
- // Don't bother unless we've been asked to reload
416
+ if (_dart_type != nullptr && !force) {
421
417
return ;
422
418
}
423
419
424
420
_base_script.unref ();
425
421
426
422
bindings->execute_on_dart_thread ([&] {
423
+ DartBlockScope scope;
424
+
427
425
// Delete old persistent handles
428
426
if (_dart_type != nullptr ) {
429
427
Dart_DeletePersistentHandle (_dart_type);
@@ -434,7 +432,6 @@ void DartScript::refresh_type() {
434
432
_script_info = nullptr ;
435
433
}
436
434
437
- DartBlockScope scope;
438
435
DartScriptLanguage *language = DartScriptLanguage::instance ();
439
436
440
437
String path = get_path ();
0 commit comments