Managed to avoid the exception by making sure the queue is at least bigger than the packets that are going to be transmitted
Checked that the queue is at least equal than the number of packets to be transmitted. Still have a bug attempting to erase packets from an empty queue. Packet count seems to be alright, though