Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A bug when Object is inline-wrapped into a Variant. #574

Open
elijah-semyonov opened this issue Oct 8, 2024 · 1 comment
Open

A bug when Object is inline-wrapped into a Variant. #574

elijah-semyonov opened this issue Oct 8, 2024 · 1 comment

Comments

@elijah-semyonov
Copy link
Contributor

elijah-semyonov commented Oct 8, 2024

This test fails:

func testObjectArrayAcceptsNil() {
    let array = GArray(Object.self)
    array.append(Variant())
    array.append(Variant())
     
    XCTAssertEqual(array.count, 2)
    XCTAssertEqual(array[0], Variant())
    XCTAssertEqual(array[1], Variant())
     
    array.append(Variant(Object()))
    XCTAssertEqual(array.count, 3)
  }

Console prints:

Attempted to push_back an invalid (previously freed?) object instance into a 'TypedArray.

This crashes:

 func testObjectNotLost() {
     let variant = Variant(Object())
     let methodListVariant: Variant
     
     switch variant.call(method: "get_method_list") {
     case .success(let variant):
         methodListVariant = variant
     case .failure(let error):
         XCTFail("Could not get method list, error: \(error)")
         return
     }
     
     guard let methodList = GArray(methodListVariant) else {
         XCTFail("Could not get method list, got \(methodListVariant.gtype) instead")
         return
     }
     
     XCTAssertFalse(methodList.isEmpty())
}

Note:
Only framework types are affected
RefCounted-inherited types are not affected

@elijah-semyonov elijah-semyonov changed the title A bug when Object is wrapped into a Variant and pushed into GArray A bug when Object is inline-wrapped into a Variant. Oct 8, 2024
@elijah-semyonov
Copy link
Contributor Author

elijah-semyonov commented Nov 27, 2024

The problem is due to Object shouldn't be freed by Swift without an explicit free, Objects don't have refcounted semantics, so Godot doesn't even try to increment their ref counter, when receiving it from Swift world.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant