Skip to content

Commit

Permalink
Merge pull request #499 from CesiumGS/more-ion-client-safety
Browse files Browse the repository at this point in the history
Fix another crash caused by destroying CesiumIonSession while it is doing network requests
  • Loading branch information
kring authored Sep 2, 2024
2 parents 2bc60bf + fc36f82 commit c48ce92
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions native~/Editor/src/CesiumIonSessionImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,13 +436,19 @@ void CesiumIonSessionImpl::refreshProfile(
.thenInMainThread(
[this, session](
CesiumIonClient::Response<CesiumIonClient::Profile>&& profile) {
if (session == nullptr)
return;

this->_isLoadingProfile = false;
this->_profile = std::move(profile.value);
this->broadcastProfileUpdate();
if (this->_loadProfileQueued)
this->refreshProfile(session);
})
.catchInMainThread([this, session](std::exception&& e) {
if (session == nullptr)
return;

this->_isLoadingProfile = false;
this->_profile = std::nullopt;
this->broadcastProfileUpdate();
Expand Down Expand Up @@ -470,13 +476,19 @@ void CesiumIonSessionImpl::refreshAssets(
.thenInMainThread(
[this, session](
CesiumIonClient::Response<CesiumIonClient::Assets>&& assets) {
if (session == nullptr)
return;

this->_isLoadingAssets = false;
this->_assets = std::move(assets.value);
this->broadcastAssetsUpdate();
if (this->_loadAssetsQueued)
this->refreshAssets(session);
})
.catchInMainThread([this, session](std::exception&& e) {
if (session == nullptr)
return;

this->_isLoadingAssets = false;
this->_assets = std::nullopt;
this->broadcastAssetsUpdate();
Expand Down Expand Up @@ -509,6 +521,9 @@ void CesiumIonSessionImpl::refreshTokens(
.thenInMainThread(
[this, session](
CesiumIonClient::Response<CesiumIonClient::TokenList>&& tokens) {
if (session == nullptr)
return;

this->_isLoadingTokens = false;
this->_tokens =
tokens.value
Expand All @@ -519,6 +534,9 @@ void CesiumIonSessionImpl::refreshTokens(
this->refreshTokens(session);
})
.catchInMainThread([this, session](std::exception&& e) {
if (session == nullptr)
return;

this->_isLoadingTokens = false;
this->_tokens = std::nullopt;
this->broadcastTokensUpdate();
Expand All @@ -541,6 +559,9 @@ void CesiumIonSessionImpl::refreshDefaults(
.thenInMainThread(
[this, session](
CesiumIonClient::Response<CesiumIonClient::Defaults>&& defaults) {
if (session == nullptr)
return;

logResponseErrors(defaults);
this->_isLoadingDefaults = false;
this->_defaults = std::move(defaults.value);
Expand All @@ -550,6 +571,9 @@ void CesiumIonSessionImpl::refreshDefaults(
this->refreshDefaults(session);
})
.catchInMainThread([this, session](std::exception&& e) {
if (session == nullptr)
return;

logResponseErrors(e);
this->_isLoadingDefaults = false;
this->_defaults = std::nullopt;
Expand Down

0 comments on commit c48ce92

Please sign in to comment.