You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Recently upgrading my project to latest version of SwiftGodot, and encountered a crash in this function ArrayMesh.addSurfaceFromArrays.
Thankfully, enabling experimentalDisableVariantUnref does allow to workaround this for now!
Here is the code causing the crash, as requested by the comment on that variable :)
import Foundation
import SwiftGodot
@Godot(.tool)classLine3D:MeshInstance3D{var_vertices=PackedVector3Array()var_tangents=PackedVector3Array()var_colors=PackedColorArray()var_uvs=PackedVector2Array()var_indices=PackedInt32Array()var_arrays=GArray()vartime:Float=0@Exportvarwidth:Double=1@Exportvaralpha:Double=1@ExportvaruseGlobalSpace:Bool= false
@Export(.resourceType,"Gradient")vargradient:Gradient=.init()@Export(.resourceType,"Curve")varwidthCurve:Curve=.init()@Exportvarpoints:PackedVector3Array=.init()overridefunc _ready(){
_arrays.resize(size:Mesh.ArrayType.max.rawValue)
if mesh ==nil{
mesh =ArrayMesh()}
if Engine.isEditorHint()== false {
mesh =ArrayMesh()}rebuild()}overridefunc _process(delta _:Double){
if Engine.isEditorHint(){rebuild()}}@Callablefunc rebuild(){printd("Rebuilding line!")
guard let am = mesh as?ArrayMeshelse{return}printd("Points: \(points)")
am.clearSurfaces()varcount= points.size()
if count <2{return}
_vertices.resize(newSize: count *2)
_tangents.resize(newSize: count *2)
_colors.resize(newSize: count *2)
_uvs.resize(newSize: count *2)
_indices.resize(newSize: count *2)varinvGlobalTx:Transform3D?=nil
if useGlobalSpace {
invGlobalTx = globalTransform.inverse()}varhalf_width= width /2
for i in 0..<Int(count){varj0= i *2varj1= j0 +1varp=points[i]
if invGlobalTx !=nil{
p = invGlobalTx! * p
}_vertices[j0]= p
_vertices[j1]= p
vartangent:Vector3
if i ==0{
tangent =(points[i +1]- p).normalized()}else if i == count -1{
tangent =(p - points[i -1]).normalized()}else{
tangent =(p - points[i -1]).lerp(to:points[i +1]- p, weight: 0.5).normalized()}_tangents[j0]= tangent
_tangents[j1]= tangent
varu=Double(i)/ Double(count -1)varc= gradient.sample(offset: u)
c.alpha =Float(alpha)_colors[j0]= c
_colors[j1]= c
varv= half_width * widthCurve.sample(offset: u)_uvs[j0]=Vector2(x:Float(u), y:Float(-v))_uvs[j1]=Vector2(x:Float(u), y:Float(v))_indices[j0]=Int32(j0)_indices[j1]=Int32(j1)}// enable this to prevent crash!// experimentalDisableVariantUnref = true_arrays[Int(Mesh.ArrayType.vertex.rawValue)]=Variant(_vertices)_arrays[Int(Mesh.ArrayType.normal.rawValue)]=Variant(_tangents)_arrays[Int(Mesh.ArrayType.color.rawValue)]=Variant(_colors)_arrays[Int(Mesh.ArrayType.texUv.rawValue)]=Variant(_uvs)_arrays[Int(Mesh.ArrayType.index.rawValue)]=Variant(_indices)
am.addSurfaceFromArrays(primitive:Mesh.PrimitiveType.triangleStrip, arrays: _arrays)}}
The text was updated successfully, but these errors were encountered:
Recently upgrading my project to latest version of SwiftGodot, and encountered a crash in this function
ArrayMesh.addSurfaceFromArrays
.Thankfully, enabling
experimentalDisableVariantUnref
does allow to workaround this for now!Here is the code causing the crash, as requested by the comment on that variable :)
The text was updated successfully, but these errors were encountered: