| 1548 | } |
| 1549 | |
| 1550 | void GDScript::clear(ClearData *p_clear_data) { |
| 1551 | if (clearing) { |
| 1552 | return; |
| 1553 | } |
| 1554 | clearing = true; |
| 1555 | |
| 1556 | ClearData data; |
| 1557 | ClearData *clear_data = p_clear_data; |
| 1558 | bool is_root = false; |
| 1559 | |
| 1560 | // If `clear_data` is `nullptr`, it means that it's the root. |
| 1561 | // The root is in charge to clear functions and scripts of itself and its dependencies |
| 1562 | if (clear_data == nullptr) { |
| 1563 | clear_data = &data; |
| 1564 | is_root = true; |
| 1565 | } |
| 1566 | |
| 1567 | { |
| 1568 | MutexLock lock(func_ptrs_to_update_mutex); |
| 1569 | for (UpdatableFuncPtr *updatable : func_ptrs_to_update) { |
| 1570 | updatable->ptr = nullptr; |
| 1571 | } |
| 1572 | } |
| 1573 | |
| 1574 | // If we're in the process of shutting things down then every single script will be cleared |
| 1575 | // anyway, so we can safely skip this very costly operation. |
| 1576 | if (!GDScriptLanguage::singleton->finishing) { |
| 1577 | RBSet<GDScript *> must_clear_dependencies = get_must_clear_dependencies(); |
| 1578 | for (GDScript *E : must_clear_dependencies) { |
| 1579 | clear_data->scripts.insert(E); |
| 1580 | E->clear(clear_data); |
| 1581 | } |
| 1582 | } |
| 1583 | |
| 1584 | for (const KeyValue<StringName, GDScriptFunction *> &E : member_functions) { |
| 1585 | clear_data->functions.insert(E.value); |
| 1586 | } |
| 1587 | member_functions.clear(); |
| 1588 | |
| 1589 | for (KeyValue<StringName, MemberInfo> &E : member_indices) { |
| 1590 | clear_data->scripts.insert(E.value.data_type.script_type_ref); |
| 1591 | E.value.data_type.script_type_ref = Ref<Script>(); |
| 1592 | } |
| 1593 | |
| 1594 | for (KeyValue<StringName, MemberInfo> &E : static_variables_indices) { |
| 1595 | clear_data->scripts.insert(E.value.data_type.script_type_ref); |
| 1596 | E.value.data_type.script_type_ref = Ref<Script>(); |
| 1597 | } |
| 1598 | static_variables.clear(); |
| 1599 | static_variables_indices.clear(); |
| 1600 | |
| 1601 | if (implicit_initializer) { |
| 1602 | clear_data->functions.insert(implicit_initializer); |
| 1603 | implicit_initializer = nullptr; |
| 1604 | } |
| 1605 | |
| 1606 | if (implicit_ready) { |
| 1607 | clear_data->functions.insert(implicit_ready); |
no test coverage detected