0 votes

Hello pleople,

Mhmmm... Strange thing is that error. it does not break the game, it launch well. But after closing the game window Godot freeze for 30 seconds and then show me theses errors in loop. They look to be parented to some function that i call (transform.get_global_transform()). So i have a problem, first, i don't really like to be stuck 30 seconds after closing the game, and then... Well... An error is an error, i would like to burn it with fire.

I just have no idea about where to look, so here i am :).

Here the problematic code:

tool
extends Spatial

export var planetSize = 100.0 setget _set_planet_size, _get_planet_size
export var lod = 10 setget _set_lod, _get_lod

const latitudes = 180.0 
const longitudes = 360.0

var coroutine = null

func _set_planet_size(value):
    planetSize = value
    GeneratePlanet()
func _get_planet_size():
    return planetSize

func _set_lod(value):
    lod = int(value)
    GeneratePlanet()
func _get_lod():
    return lod

func _ready():
    GeneratePlanet()

func GeneratePlanet():
    var baseCoordinates = GenerateBaseShape()
    GeneratePlanetMesh(baseCoordinates)

func GenerateBaseShape():
    var coordinate = []
    var depart = Vector3(0, planetSize, 0)
    var lat = 1
    var edge = Spatial.new()
    var center = Spatial.new()
    add_child(center)
    center.add_child(edge)

    for lat in range(lod):
        coordinate.append([])
        var epicentre = Spatial.new()
        var centralLatitude = Spatial.new()

        add_child(epicentre)
        centralLatitude.translate(depart)
        epicentre.add_child(centralLatitude)
        epicentre.rotate_x(latitudes / lod *(PI/180) * (lat + 1))
        #print(centralLatitude.get_global_transform().origin)
        for long in range(lod):
            if long == 0:
                coordinate[lat].append(centralLatitude.get_global_transform().origin)
            center.global_translate(Vector3(0, edge.get_global_transform().origin.y, 0) - center.get_global_transform().origin) 
            edge.global_translate(centralLatitude.get_global_transform().origin - edge.get_global_transform().origin)

            center.rotate_y(longitudes / lod * (long+1) * (PI/180))
            coordinate[lat].append(edge.get_global_transform().origin)
    for i in range(get_child_count()):
        get_child(i).queue_free()
    return coordinate

func GeneratePlanetMesh(coordinate):
    var sf = SurfaceTool.new()
    var m = Mesh.new()
    sf.begin(Mesh.PRIMITIVE_TRIANGLES)

    for latitude in range(lod):
        for longitude in range(lod):
            if latitude == 0:
                sf.add_vertex(Vector3(0, planetSize, 0))
                sf.add_vertex(coordinate[latitude][longitude + 1])
                sf.add_vertex(coordinate[latitude][longitude])
            else:
                sf.add_vertex(coordinate[latitude - 1][longitude])
                sf.add_vertex(coordinate[latitude][longitude + 1])
                sf.add_vertex(coordinate[latitude][longitude]) 

                sf.add_vertex(coordinate[latitude -1][longitude ])
                sf.add_vertex(coordinate[latitude-1][longitude +1])
                sf.add_vertex(coordinate[latitude][longitude +1])

                if latitude == lod - 1:
                    sf.add_vertex(coordinate[latitude - 1][longitude])
                    sf.add_vertex(coordinate[latitude][0])
                    sf.add_vertex(coordinate[latitude][longitude]) 

    sf.generate_normals()
    sf.index()
    sf.commit(m)

    var planet = MeshInstance.new()
    add_child(planet)
    planet.mesh = m

And here is is a screenshot:

http://i.imgur.com/EwNwonJ.png

Anyone to satisfy my pyromaniac tendencies :-) ?

in Engine by (54 points)

Well... That code is awful, i'm constructing a complete new one witout using theses spatial nodes that i was using to help. But i still curious about to know why this bug occurs :).

1 Answer

0 votes

My guess.
I see many instancing in the code. Make sure that all of the new instances has a parent.
Godot does not like nodes without parent. :) Godot is family centric.

That pattern would help you find that case.
assert (newstuff.get_parent != null)

by (312 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.