0 votes

I created a new thread for background loading, but when I try to run a large loop setting cells for grid map, my game crashes

asked May 26 in Engine by thisischico (17 points)

please show us your code

Start loading script

func _start(_param):
    map.create_map()

    loading.hide()
    queue_free()
    thread.wait_to_finish()

func _ready() -> void:
    loading = main.instance_loading()
    thread = Thread.new()
    thread.start(self, "_start", null)

Map's create_map function

func create_map(size: Vector3 = Vector3(128, 1, 128)) -> void:
    loading.total = int(size.x * size.y * size.z)
    loading.progress = 0
    for x in size.x:
        map_data.append([])
        for y in size.y:
            map_data[x].append([])
            for z in size.z:
                map_data[x][y].append([])
                map.set_cell_item(x, y, z, 0)
                loading.progress += 1

mh, i' unsure... maybe you shoud swap

queue_free()
thread.wait_to_finish()

to

thread.wait_to_finish()
queue_free()

(not tested, just a guess)

In addition to gridmap, I still have a lot of things loading, and they work fine

Please log in or register to answer this question.

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 How to use this Q&A? before posting your first questions.