Skip to content

Commit 27eaab5

Browse files
committed
fix: Hopefully fix property reloading on hot reload
This appears to fix the issue, but isn't particularly efficient, so we may want to look into better ways to cache what files have changed long term.
1 parent c322d4e commit 27eaab5

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

src/cpp/script/dart_script.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
using namespace godot;
1616

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) {
1818
}
1919

2020
DartScript::~DartScript() {
@@ -41,7 +41,7 @@ void DartScript::_bind_methods() {
4141
}
4242

4343
godot::Ref<Script> DartScript::_get_base_script() const {
44-
const_cast<DartScript *>(this)->refresh_type();
44+
const_cast<DartScript *>(this)->refresh_type(false);
4545

4646
return _base_script;
4747
}
@@ -73,7 +73,7 @@ bool DartScript::_can_instantiate() const {
7373
return default_return; \
7474
} \
7575
\
76-
const_cast<DartScript *>(this)->refresh_type(); \
76+
const_cast<DartScript *>(this)->refresh_type(false); \
7777
if (_script_info == nullptr) { \
7878
return default_return; \
7979
}
@@ -238,11 +238,8 @@ godot::Error DartScript::_reload(bool keep_state) {
238238

239239
if (bindings != nullptr) {
240240
bindings->reload_code();
241-
_needs_refresh = true;
242241
}
243242

244-
// Don't set _last_modified_time here, as it will be set by did_hot_reload();
245-
246243
return godot::Error::OK;
247244
}
248245

@@ -285,7 +282,7 @@ godot::Variant DartScript::_get_property_default_value(const godot::StringName &
285282
}
286283

287284
void DartScript::_update_exports() {
288-
refresh_type();
285+
refresh_type(true);
289286

290287
for (const auto &script_instance : _placeholders) {
291288
script_instance->notify_property_list_changed();
@@ -344,7 +341,7 @@ void *DartScript::_instance_create(Object *for_object) const {
344341
return nullptr;
345342
}
346343

347-
const_cast<DartScript *>(this)->refresh_type();
344+
const_cast<DartScript *>(this)->refresh_type(false);
348345
if (_dart_type == nullptr) {
349346
return nullptr;
350347
}
@@ -362,7 +359,7 @@ void *DartScript::_placeholder_instance_create(Object *for_object) const {
362359
return nullptr;
363360
}
364361

365-
const_cast<DartScript *>(this)->refresh_type();
362+
const_cast<DartScript *>(this)->refresh_type(false);
366363
if (_dart_type == nullptr) {
367364
return nullptr;
368365
}
@@ -410,20 +407,21 @@ void DartScript::clear_property_cache() {
410407
_properties_cache.clear();
411408
}
412409

413-
void DartScript::refresh_type() {
410+
void DartScript::refresh_type(bool force) {
414411
GodotDartBindings *bindings = GodotDartBindings::instance();
415412
if (bindings == nullptr) {
416413
return;
417414
}
418415

419-
if (_dart_type != nullptr && !_needs_refresh) {
420-
// Don't bother unless we've been asked to reload
416+
if (_dart_type != nullptr && !force) {
421417
return;
422418
}
423419

424420
_base_script.unref();
425421

426422
bindings->execute_on_dart_thread([&] {
423+
DartBlockScope scope;
424+
427425
// Delete old persistent handles
428426
if (_dart_type != nullptr) {
429427
Dart_DeletePersistentHandle(_dart_type);
@@ -434,7 +432,6 @@ void DartScript::refresh_type() {
434432
_script_info = nullptr;
435433
}
436434

437-
DartBlockScope scope;
438435
DartScriptLanguage *language = DartScriptLanguage::instance();
439436

440437
String path = get_path();

src/cpp/script/dart_script.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,14 @@ class DartScript : public godot::ScriptExtension {
6060
static void _bind_methods();
6161

6262
private:
63-
void refresh_type();
63+
void refresh_type(bool force);
6464
void clear_property_cache();
6565
void *create_script_instance_internal(Object *for_object, bool is_placeholder) const;
6666

6767
godot::String _source_code;
6868
godot::String _path;
6969
std::unordered_map<godot::StringName, GDExtensionPropertyInfo> _properties_cache;
7070
mutable std::unordered_set<DartScriptInstance *> _placeholders;
71-
mutable bool _needs_refresh;
7271
mutable godot::Ref<DartScript> _base_script;
7372
mutable Dart_PersistentHandle _dart_type;
7473
mutable Dart_PersistentHandle _script_info;

0 commit comments

Comments
 (0)