Skip to content

Occasional crash in GameServices::IsAuthorized() #22

@stolk

Description

@stolk

On one of my devices, I see this behaviour:

  • sign out of game services.
  • back ground the game.
  • fore ground the game again.
  • sign in.

Then my app will crash in:
(gpg::GameServices::IsAuthorized()+9)

From the docs at https://developers.google.com/games/services/cpp/GettingStartedNativeClient:

In most implementations, a given GameServices object will persist as long as your C environment does; you do not need to reinitialize it when your Android Activity pauses and resumes or when your iOS ViewController loads and unloads.

So I initialize only once, similar to the minimalist example code here: https://github.com/playgameservices/cpp-android-basic-samples/blob/master/samples-android/Minimalist/jni/StateManager.cpp

My InitServices() method:

void StateManager::InitServices
(
        gpg::PlatformConfiguration const &pc,
        gpg::GameServices::Builder::OnAuthActionStartedCallback started_callback,
        gpg::GameServices::Builder::OnAuthActionFinishedCallback finished_callback
)
{
        LOGI("Initializing Services");
        LOGI( "thread id is %d, pid is %d", gettid(), getpid() );

        // Players().FetchSelf() response
        auto pcallback = [&]( gpg::PlayerManager::FetchSelfResponse const& response )
        {
                if ( gpg::IsSuccess( response.status ) )
                {
                        self_id_ = response.data.Id();
                        const std::string& url = response.data.AvatarUrl( gpg::ImageResolution::ICON );
                        LOGI( "Our self id = %s", self_id_.c_str() );
                        LOGI( "Our url = %s", url.c_str() );
                        DownloadAvatar( url, 0 );
                }
        };
        // AuthActionStarted callback
        auto scallback = [started_callback]( gpg::AuthOperation op )
        {
                is_auth_in_progress_ = true;
                if ( started_callback != nullptr ) started_callback( op );
        };
        // AuthActionFinished callback
        auto fcallback = [finished_callback, pcallback]( gpg::AuthOperation op, gpg::AuthStatus status )
        {
                LOGI("Sign in finished with a result %s", gpg::DebugString( status ).c_str() );
                is_auth_in_progress_ = false;
                if ( finished_callback != nullptr ) finished_callback( op, status );
                if ( status == gpg::AuthStatus::VALID )
                {
                        ASSERT( game_services_ );
                        game_services_->Players().FetchSelf( pcallback );       // find out what our own Id is.
                        FetchLeaderboards();
                }
        };

        if (!game_services_)
        {
                LOGI("Uninitialized services, so creating");
                game_services_ = gpg::GameServices::Builder()
                        .SetOnAuthActionStarted( scallback )
                        .SetOnAuthActionFinished( fcallback )
                        .SetOnMultiplayerInvitationEvent( invitationcallback )
                        .Create(pc);
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions