What's up with this error?

This is a slightly complicated one, but I’m getting an error in the console that I don’t understand:

Assertion failed: (i < Size()), function operator[], file array.h, line 478.
INFO:CRASH: Successfully wrote Crashdump to file: /Users/josh/Library/Application Support/Defold/_crash
ERROR:CRASH: CALL STACK:

# 0 pc      0x91d7d libc++abi.dylib _sigtramp+29

I am investigating, but I have no idea what could be happening here. Any clues for where to investigate?

the error appears when i run this code the second time, but not the first (everything prints corrrectly)

local function renderlevel(self) -- this creates all the tiles, dudes, trees, star, and spaces. 
	print(55)
	self.wait = 0
	self.dudepos= {}
	self.dudegos= {}
	self.dudestarts= {}
	self.allgos = {}
	print(61)
	self.gridsize = (math.sqrt(#self.level))
	pprint(self.level)
	print(63)
	for k, v in ipairs(self.level) do
		local x = ((k-1)%self.gridsize)
		local y = self.gridsize-(((k-x)/self.gridsize)+1)
		local z = 0
		local pos = vmath.vector3((x*self.tilesize)-(self.tilesize*self.gridsize)/2,(y*self.tilesize)-(self.tilesize*self.gridsize)/2,z)
		local rot = vmath.quat(0,0,0,0)
		print("72")
		if v == 0 then --render space (useful for those cute corners)
			local ids = collectionfactory.create("#space", pos, rot)
			local map_id = ids[hash("/go")]
			table.insert(self.allgos, map_id)
			go.set_parent(map_id, ".")
		elseif v > 0 then --render tile
			pos.z = -0.5
			local ids = collectionfactory.create("#tile", pos, rot)
			local map_id = ids[hash("/go")]
			table.insert(self.allgos, map_id)
			go.set_parent(map_id, ".")
			if v == 2 then
				pos.z = 0.2
				local ids = collectionfactory.create("#dude", pos, rot)
				local map_id = ids[hash("/go")]
				table.insert(self.allgos, map_id)
				go.set_parent(map_id, ".")
				table.insert(self.dudepos, k)
				table.insert(self.dudegos, map_id)
				table.insert(self.dudestarts, k)
			elseif v == 3 then
				local ids = collectionfactory.create("#tree", pos, rot)
				local map_id = ids[hash("/go")]
				table.insert(self.allgos, map_id)
				go.set_parent(map_id, ".")
			elseif v == 4 then
				local ids = collectionfactory.create("#star", pos, rot)
				local map_id = ids[hash("/go")]
				table.insert(self.allgos, map_id)
				go.set_parent(map_id, ".")
			end
		end 
	end
	print("107")
end
	

It’s worth reporting it on Github, Defold team will have more info about it :wink:

I’ll do a small-as-possible project demonstrating the bug and get it uploaded on Monday.
The bug definitely seems to be related to using a collection factory twice in some way…

It’s definitely a bug in the engine that needs to be fixed. A report on GitHub and some steps to reproduce the issue would be appreciated!