When we are trying to send messages while the client is offline, we get a crash in NRtClient::send. More precisely the std::stoi(msg.cid()) call fails.
Upon further investigation we found that the msg.cid variable is set by the NRtClient::createReqContext function, which is being called before every NRtClient::send call. Except in NRtClient::sendMatchData where it’s not called, and that seems to be the cause of the crash.
Is this a bug, or are we missing something?
We are on version 2.6.0, but we checked in 2.7.1 too and there’s no change.
Hey @BiroAndras could you share what platform you are testing on, file this as an issue on Github in nakama-cpp and share a stack trace?
I would be surprised if
std::stoi(msg.cid()) has to do with it because that doesn’t depend on whether the client is offline or online.
We are testing on Windows.
The problem depends on whether the client is offline or online because msg.cid() is only used in error handling. If everything is fine it’s never touched and there’s no crash.
void NRtClient::send(const ::nakama::realtime::Envelope & msg)
if (!_wantDisconnect && isConnected())
if (_protocol->serialize(msg, bytes))
reqInternalError(std::stoi(msg.cid()), NRtError(RtErrorCode::TRANSPORT_ERROR, "Send message failed"));
_lastMessageTs = getUnixTimestampMs();
reqInternalError(std::stoi(msg.cid()), NRtError(RtErrorCode::TRANSPORT_ERROR, "Serialize message failed"));
reqInternalError(std::stoi(msg.cid()), NRtError(RtErrorCode::CONNECT_ERROR, "Not connected"));
I will file this issue on Github too, but only tomorrow, I don’t have access to the stack trace now.
@BiroAndras okay I think I see the issue – not all messages (e.g., match data) have a cid, so there should be an empty check before the cid. I’ll add that patch to the client tomorrow.
The C++ client will be released with this fix and a couple others sometime later this week.
Here is the latest release which should resolve your issue: Release v2.7.2 · heroiclabs/nakama-cpp · GitHub