migueldeicaza / SwiftGodot

New Godot bindings for Swift
https://migueldeicaza.github.io/SwiftGodotDocs/tutorials/swiftgodot-tutorials/
MIT License
1.14k stars 76 forks source link

`VariantCollection` crashes after Variant leak fix #390

Closed tishin closed 8 months ago

tishin commented 8 months ago

That's the reason CI tests are failing. Simplified example:

func testClipPolygons () {
    let a = PackedVector2Array ()
    let b = PackedVector2Array ()
    var r: VariantCollection<PackedVector2Array>

    a.pushBack (value: Vector2 (x: 225, y: 180))
    a.pushBack (value: Vector2 (x: 160, y: 230))
    a.pushBack (value: Vector2 (x: 20, y: 212))
    a.pushBack (value: Vector2 (x: 50, y: 115))

    b.pushBack (value: Vector2 (x: 150, y: 200))
    b.pushBack (value: Vector2 (x: 65, y: 190))
    b.pushBack (value: Vector2 (x: 80, y: 140))

    r = Geometry2D.clipPolygons (polygonA: a, polygonB: b)
    XCTAssertEqual (r.size (), 2, "Polygon 'a' completely overlaps polygon 'b'. This should result in 2 clipped polygons.")
    XCTAssertEqual (r [0].size (), 4, "The resulting clipped polygon should have 4 vertices.")
    XCTAssertEqual (r [0].size (), 4, "The resulting clipped polygon should have 4 vertices.")
}

The first r[0].size() check works fine, the second one crashes.

tishin commented 8 months ago

What seems to be going on here is VariantCollection's subscript gets a Variant from the underlying GArray's subscript and loses its reference after converting the Variant to PackedVector2Array.

migueldeicaza commented 8 months ago

Mhm, I don't know what happened to my Xcode or package setup, but I don't seem to be able to run any tests from Xcode.

migueldeicaza commented 8 months ago

Oh, this automatically closed the issue, but happy to reopen if there is still another problem