agar.io-clone
agar.io-clone copied to clipboard
Recombining on a virus crashes the client
Missing error handler on 'socket'. TypeError: Cannot read property 'mass' of undefined at splitCell (/root/agar.io-clone/bin/server/server.js:416:21) at Socket.<anonymous> (/root/agar.io-clone/bin/server/server.js:432:17) at Socket.EventEmitter.emit (events.js:95:17) at Socket.onevent (/root/agar.io-clone/node_modules/socket.io/lib/socket.js:335:8) at Socket.onpacket (/root/agar.io-clone/node_modules/socket.io/lib/socket.js:295:12) at Client.ondecoded (/root/agar.io-clone/node_modules/socket.io/lib/client.js:193:14) at Decoder.Emitter.emit (/root/agar.io-clone/node_modules/socket.io/node_modules/socket.io-parser/node_modules/component-emitter/index.js:134:20) at Decoder.add (/root/agar.io-clone/node_modules/socket.io/node_modules/socket.io-parser/index.js:247:12) at Client.ondata (/root/agar.io-clone/node_modules/socket.io/lib/client.js:175:18) at Socket.EventEmitter.emit (events.js:95:17) [INFO] User disconnected!
I got this same error today but haven't been able to reproduce it yet.
Missing error handler on
socket. TypeError: Cannot read property 'mass' of undefined at splitCell (/Users/tallred/workspace/agar.io-clone/bin/server/server.js:416:21) at Socket.<anonymous> (/Users/tallred/workspace/agar.io-clone/bin/server/server.js:433:17) at emitOne (events.js:90:13) at Socket.emit (events.js:182:7) at Socket.onevent (/Users/tallred/workspace/agar.io-clone/node_modules/socket.io/lib/socket.js:335:8) at Socket.onpacket (/Users/tallred/workspace/agar.io-clone/node_modules/socket.io/lib/socket.js:295:12) at Client.ondecoded (/Users/tallred/workspace/agar.io-clone/node_modules/socket.io/lib/client.js:193:14) at Decoder.Emitter.emit (/Users/tallred/workspace/agar.io-clone/node_modules/component-emitter/index.js:134:20) at Decoder.add (/Users/tallred/workspace/agar.io-clone/node_modules/socket.io-parser/index.js:247:12) at Client.ondata (/Users/tallred/workspace/agar.io-clone/node_modules/socket.io/lib/client.js:175:18)
Got same bug, no errors on both console (client/server) but client freeze...
Crash is caused by the program with the function splitCell seeking an out of range value of an non-existant cell (which has just been recombined and destroyed) , you fix it by adding a simple condition, below :
if(currentPlayer.cells.length < c.limitSplit && currentPlayer.massTotal >= c.defaultPlayerMass*2) {
//Split single cell from virus
if(virusCell) {
//add this
if(currentPlayer.cells.length > virusCell)splitCell(currentPlayer.cells[virusCell]);
}
Also add a virus.splice(virusCollision,1) where collision test of virus occurs prevent from weird behaviour and will destroy the virus upon collision
if(virusCollision > 0 && currentCell.mass > virus[virusCollision].mass) {
sockets[currentPlayer.id].emit('virusSplit', z);
//add this
virus.splice(virusCollision,1);
}