C++98 iOS Photon Realtime crashes in opRaiseEvent...JString


I trying to make some simple tests using Photon Realtime.

The problem is when I use C++98 (libxxx-cpp_release_cpp98_iphoneos.a) iOS Photon libraries, it crashes every time for me at opRaiseEvent().

I tried to rewrite Basic sample code and all is I need for now is send/receive string data between 2 players joined to room.
I thought there is a problem in my code, and created iOS test program, New ProJect->Game->Objective-C from XCode.
Then add Photon_lib.cpp from demo_basics, delete Logger as I don't need it. So I set my app id, then new PhotonLib() after OpenGL init and call PhotonLib::update() every frame. It connects to server but crashes every time when trying to send data.
Backtrace is:

#0 0x000461ba in ExitGames::Common::JString::JString(ExitGames::Common::JString const&) at /Development/egp/trunkCopy2/Common-cpp/src/JString.cpp:119
#1 0x000608c4 in ExitGames::LoadBalancing::Peer::opWebRpc(ExitGames::Common::JString const&, ExitGames::Common::Object const&, bool) at /Development/egp/trunkCopy2/LoadBalancing-cpp/src/Peer.cpp:210
#2 0x000233fe in bool ExitGames::LoadBalancing::Peer::opRaiseEvent(bool, ExitGames::Common::Hashtable, unsigned char, ExitGames::LoadBalancing::RaiseEventOptions) at //applications/testphoton/../../externals/PhotonSDK/Photon-iOS-Sdk_v4-1-5-1/LoadBalancing-cpp/inc/Peer.h:75
#3 0x00023086 in bool ExitGames::LoadBalancing::Client::opRaiseEvent(bool, ExitGames::Common::Hashtable, unsigned char, ExitGames::LoadBalancing::RaiseEventOptions) at //applications/testphoton/../../externals/PhotonSDK/Photon-iOS-Sdk_v4-1-5-1/LoadBalancing-cpp/inc/Client.h:223
#4 0x00021e48 in (anonymous namespace)::PhotonLib::sendData() at //applications/testphoton/testphoton/Photon.cpp:161
#5 0x0001f6ba in (anonymous namespace)::PhotonLib::update() at //applications/testphoton/testphoton/Photon.cpp:105
#6 0x0001f420 in photon::PhotonUpdate() at //applications/testphoton/testphoton/Photon.cpp:362
#7 0x0001d4fe in ::-[GameViewController update]() at //applications/testphoton/testphoton/GameViewController.mm:234
#8 0x29836656 in -[GLKViewController _updateAndDraw] ()
#9 0x003eb904 in -[DYDisplayLinkInterposer forwardDisplayLinkCallback:] ()
#10 0x248d3a0a in CA::Display::DisplayLinkItem::dispatch() ()
#11 0x248d3856 in CA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long) ()
#12 0x23fba50a in IOMobileFramebufferVsyncNotifyFunc ()
#13 0x224c8758 in IODispatchCalloutFromCFMessage ()
#14 0x2222637c in __CFMachPortPerform ()
#16 0x22239cc6 in __CFRunLoopDoSource1 ()
#17 0x222380d8 in __CFRunLoopRun ()
#18 0x22187228 in CFRunLoopRunSpecific ()
#19 0x22187014 in CFRunLoopRunInMode ()
#20 0x23777ac8 in GSEventRunModal ()
#21 0x2685b188 in UIApplicationMain ()
#22 0x0001f148 in main at //applications/testphoton/testphoton/main.m:14
#23 0x21e2f872 in start ()

crash message is Thread 1: EXC_BAD_ACCESS code=1 address=0xd
address is the same 0xd every time.
I tried like 10 times, it crashes 100% in same code place.

So I checked that crash occurs even in Xcode sample+basic Photon SDK demo with Logger disabled.
demo_basics works without crash as is but it uses libc++ (C++11), and I need to use libstdc++ (C++98) libraries in my project.

Photon version Xcode 8.2.1. My iOS development target is iOS 7.0. I'm using on armv7(32-bit) iPod 5th gen device (iOS 9.3.5) in my tests.

My questions are
1) do I need some workaround to make it work?
2) if it's a problem on SDK side could You fix it in the next version? The same code works without crash on Win32/Android.


  • P.S. I read my post :) and it MAY look that I don't know how to implement JString send using Photon SDK, but that's not the case. For my test I used basic demo as is, sending int64 counter only, still crashes in JString as above.
  • Hi @Dmitry_Stepanushkin.

    I can reproduce this and I am afraid that this is a bug in the compiler and the only true fix is moving away from the deprecated stdlib.

    In LoadBalancing-cpp/inc/Peer.h line 75 you can see the implementation for one of the function template overloads of Peer::opRaiseEvent() calling the private non-template virtual function implementation op opRaiseEvent(). Somehow when building against libstdc++ and with C++ 98 the compiler at this line does not actually generate a call to the private implementation of opRaiseEvent(), but to the one of opWebRPC().

    However I have found a workaround that makes the code no longer triggering that bug:
    In LoadBalancing-cpp/inc/Peer.h line 61 there is the declaration of that private implementation for opRaiseEvent(), which looks like this:
    virtual bool opRaiseEvent(bool reliable, const Common::Object& parameters, nByte eventCode, RaiseEventOptions options);
    Please simply remove the 'virtual' part, and build your app and it the compiler should now generate the correct code.

    The compiler gets it right without this workaround when building against the normal libc++ C++ 11 version of the libs, but we have observed a very similar bug a while ago when trying to build the demo on very old versions of Cent OS with a GCC version from prior to 2008, so this must be related to the libstdc++ mode of clang.
  • @Kaiserludi

    Great! It solved a crash, and I got it work for connect-join-send-receive-leave-disconnect. Nice workaround saved me a lot of time, thank You!
Sign In or Register to comment.