playgameservices / cpp-android-basic-samples

Sample games using the Google Play Games C++ SDK
303 stars 131 forks source link

Crash In participant.Id().compare #40

Closed jknight-nc closed 8 years ago

jknight-nc commented 8 years ago

Hey there, This code is crashing with a segfault. This is in a RealTimeRoomListener, which is trying to send an unreliable message to a single player using a playerId

void NCRTMatchGoogleImpl::sendUnreliableMessageToPlayer(std::string playerId, ncrtgpgdata data)
{
  if (m_room.Valid()) {
    const std::vector<gpg::MultiplayerParticipant> participants = m_room.Participants();
    for (gpg::MultiplayerParticipant participant : participants) {
      if (participant.Valid()) {
        if (participant.Id().compare(playerId) == 0) {
        ......
Program received signal SIGSEGV, Segmentation fault.
0x7501e518 in NCRTMatchGoogleImpl::sendUnreliableMessageToPlayer(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::vector<unsigned char, std::__1::allocator<unsigned char> >) (this=0x822fd5e8, playerId=..., data=...) at /Volumes/jkncvault/repos/triton/Source/Realtime/NCRT/Google/NCRTMatchGoogleImpl.mm:213
213         if (participant.Id().compare(playerId) == 0) {

Seems like the participant is invalid, even though participant.Valid() returns true.

We are also setting m_room = room on all of the RealTimeRoom listener callbacks that supply a room (including OnDataReceived). I believe setting m_room = room must be destroying this. I noticed that in ButtonClickerExample they only save the room variable in OnRoomStatusChanged, but I am saving it in OnP2PConnected/Disconnected, ParticipantStatusChanged etc.

claywilkinson commented 8 years ago

Can you post the full crash log? and which version of the SDK you are using?

jknight-nc commented 8 years ago

Hello Clay, thank you for looking into these issues. Our project no longer experiences this problem. The supplied std::string was being created with a NULL const char*. We are checking for this NULL earlier in the program and are avoiding this crash now.