Asynchronous functions cocos2d-js

Hello!!! I have a problem: the game is to find a solution that runs 2-3 seconds. Because of what the game occasionally fails and closes. How can this be solved?

Could you add some details ?

Of course. Playing on the type move blocks horizontally \ vertically. Finding the solution is done by pressing the button. Repeats steps of the blocks and looks for the first successful series of steps. What other items needed?

This error occurs: Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 10553…

By using the search function solutions error appears again in any number of clicks on the button.

gimme coda bro

var solve = function (board, endBlocks) {
var b;
var i;
var seen = new Set();
var queue = ;
var dist = distance(endBlocks, board.blocks);
queue[dist] = ;
queue[dist].push(board);

while (queue.length !== 0) {
	for (i in queue) {
		if (typeof(queue[i]) !== "undefined") {
			if (queue[i].length !== 0) {
				b = queue[i].shift();
				break;
			} else {
				delete queue[i];
			}
		}
	}
	if (b.canPrisonerEscape()) {
		return showSolution.bind(this)(b);
	}
	var stringBoard = b.hax();
	if (!seen.has(stringBoard)) {
		seen.add(stringBoard);
		var boards = b.generateAllBoards();
		for (i in boards) {
			var child = boards[i];
			dist = distance(endBlocks, child.blocks);
			if (typeof(queue[dist]) === "undefined") {
				queue[dist] = [];
			}
			queue[dist].push(child);
		}
	}
}

};