| 1881 | } |
| 1882 | |
| 1883 | bool CSharpInstance::refcount_decremented() { |
| 1884 | #ifdef DEBUG_ENABLED |
| 1885 | CRASH_COND(!base_ref_counted); |
| 1886 | CRASH_COND(owner == nullptr); |
| 1887 | #endif // DEBUG_ENABLED |
| 1888 | |
| 1889 | RefCounted *rc_owner = Object::cast_to<RefCounted>(owner); |
| 1890 | |
| 1891 | int refcount = rc_owner->get_reference_count(); |
| 1892 | |
| 1893 | if (refcount == 1 && !gchandle.is_weak()) { // The managed side also holds a reference, hence 1 instead of 0 |
| 1894 | // If owner owner is no longer referenced by the unmanaged side, |
| 1895 | // the managed instance takes responsibility of deleting the owner when GCed. |
| 1896 | |
| 1897 | // Release the current strong handle and replace it with a weak handle. |
| 1898 | |
| 1899 | GCHandleIntPtr old_gchandle = gchandle.get_intptr(); |
| 1900 | gchandle.handle = { nullptr }; // No longer owns the handle (released by swap function) |
| 1901 | |
| 1902 | GCHandleIntPtr new_gchandle = { nullptr }; |
| 1903 | bool create_weak = true; |
| 1904 | bool target_alive = GDMonoCache::managed_callbacks.ScriptManagerBridge_SwapGCHandleForType( |
| 1905 | old_gchandle, &new_gchandle, create_weak); |
| 1906 | |
| 1907 | if (!target_alive) { |
| 1908 | return refcount == 0; // Called after the managed side was collected, so nothing to do here |
| 1909 | } |
| 1910 | |
| 1911 | gchandle = MonoGCHandleData(new_gchandle, gdmono::GCHandleType::WEAK_HANDLE); |
| 1912 | |
| 1913 | return false; |
| 1914 | } |
| 1915 | |
| 1916 | ref_dying = (refcount == 0); |
| 1917 | |
| 1918 | return ref_dying; |
| 1919 | } |
| 1920 | |
| 1921 | const Variant CSharpInstance::get_rpc_config() const { |
| 1922 | return script->get_rpc_config(); |
nothing calls this directly
no test coverage detected