(Using the Unity Transport package version 2.3.0
)
Hi,
I am trying to write & read in parallel from a NetworkDriver
using two IJobParallelForDefer
jobs. One for reading new messages and one for writing new messages.
I schedule my jobs like so:
// Update the driver
m_BaseJobHandle = m_NetworkDriver.ScheduleUpdate();
// Update peers list
m_BaseJobHandle = connectionJob.Schedule(m_BaseJobHandle);
// Receive incoming messages
m_ReceiveJobHandle = serverReceiveJob.Schedule(m_ActivePeerLocalIds, 1, m_BaseJobHandle);
// Send outgoing messages
m_SendJobHandle = serverSendJob.Schedule(m_ActivePeerLocalIds, 1, m_BaseJobHandle);
Notice how the driver update and the peers update make the “base” handle, which is necessary for both receiving & sending messages, but then receiving and sending is done in parallel because they don’t share anything with each others, other than the peer list.
Still, when I schedule the jobs, I am spammed with errors from Unity:
InvalidOperationException: The previously scheduled job ServerNetworkConnection:ServerSendJob writes to the Unity.Collections.NativeArray`1[System.Int32] ServerSendJob.NetworkDriver.m_PendingBeginSend. You are trying to schedule a new job ServerNetworkConnection:ServerReceiveJob, which writes to the same Unity.Collections.NativeArray`1[System.Int32] (via ServerReceiveJob.NetworkDriver.m_PendingBeginSend). To guarantee safety, you must include ServerNetworkConnection:ServerSendJob as a dependency of the newly scheduled job.
I understand what the error is asking out of me, but what I am wondering is: Is there truly no way to have one parallel job sending messages and another parallel job reading messages from the same NetworkDriver
?
Or is it just a waste of time and I am better off combining both jobs into one parallel job that both sends & receive for each peers?
Thanks a lot for the help!