From 7faf1cb3f3ddb62b03eed469f4a6bf1cd77ea9ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 6 Oct 2015 19:07:09 +0200 Subject: [PATCH] Fix a couple of crashes --- UI/Store.cpp | 8 +- .../src/org/ppsspp/ppsspp/NativeActivity.java | 93 ++++++++++++------- ext/native/net/http_client.h | 4 + 3 files changed, 72 insertions(+), 33 deletions(-) diff --git a/UI/Store.cpp b/UI/Store.cpp index 8a974dd4c4..1e36aefc56 100644 --- a/UI/Store.cpp +++ b/UI/Store.cpp @@ -51,9 +51,11 @@ std::string ResolveUrl(std::string baseUrl, std::string url) { class HttpImageFileView : public UI::View { public: HttpImageFileView(http::Downloader *downloader, const std::string &path, UI::ImageSizeMode sizeMode = UI::IS_DEFAULT, UI::LayoutParams *layoutParams = 0) - : UI::View(layoutParams), downloader_(downloader), path_(path), color_(0xFFFFFFFF), sizeMode_(sizeMode), texture_(nullptr), textureFailed_(false), fixedSizeW_(0.0f), fixedSizeH_(0.0f) {} + : UI::View(layoutParams), path_(path), color_(0xFFFFFFFF), sizeMode_(sizeMode), downloader_(downloader), texture_(nullptr), textureFailed_(false), fixedSizeW_(0.0f), fixedSizeH_(0.0f) {} ~HttpImageFileView() { + if (download_) + download_->Cancel(); delete texture_; } @@ -119,6 +121,10 @@ void HttpImageFileView::SetFilename(std::string filename) { } void HttpImageFileView::DownloadCompletedCallback(http::Download &download) { + if (download.IsCancelled()) { + // We were probably destroyed. Can't touch "this" (heh). + return; + } if (download.ResultCode() == 200) { download.buffer().TakeAll(&textureData_); } else { diff --git a/android/src/org/ppsspp/ppsspp/NativeActivity.java b/android/src/org/ppsspp/ppsspp/NativeActivity.java index 4b364315ec..ec8baf0ff0 100644 --- a/android/src/org/ppsspp/ppsspp/NativeActivity.java +++ b/android/src/org/ppsspp/ppsspp/NativeActivity.java @@ -740,40 +740,69 @@ public class NativeActivity extends Activity { public boolean processCommand(String command, String params) { if (command.equals("launchBrowser")) { - Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(params)); - startActivity(i); - return true; - } else if (command.equals("launchEmail")) { - Intent send = new Intent(Intent.ACTION_SENDTO); - String uriText; - uriText = "mailto:email@gmail.com" + "?subject=Your app is..." - + "&body=great! Or?"; - uriText = uriText.replace(" ", "%20"); - Uri uri = Uri.parse(uriText); - send.setData(uri); - startActivity(Intent.createChooser(send, "E-mail the app author!")); - return true; - } else if (command.equals("sharejpeg")) { - Intent share = new Intent(Intent.ACTION_SEND); - share.setType("image/jpeg"); - share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + params)); - startActivity(Intent.createChooser(share, "Share Picture")); - } else if (command.equals("sharetext")) { - Intent sendIntent = new Intent(); - sendIntent.setType("text/plain"); - sendIntent.putExtra(Intent.EXTRA_TEXT, params); - sendIntent.setAction(Intent.ACTION_SEND); - startActivity(sendIntent); - } else if (command.equals("showTwitter")) { - String twitter_user_name = params; try { - startActivity(new Intent(Intent.ACTION_VIEW, - Uri.parse("twitter://user?screen_name=" - + twitter_user_name))); + Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(params)); + startActivity(i); + return true; } catch (Exception e) { - startActivity(new Intent( - Intent.ACTION_VIEW, - Uri.parse("https://twitter.com/#!/" + twitter_user_name))); + // No browser? + Log.e(TAG, e.toString()); + return false; + } + } else if (command.equals("launchEmail")) { + try { + Intent send = new Intent(Intent.ACTION_SENDTO); + String uriText; + uriText = "mailto:email@gmail.com" + "?subject=Your app is..." + + "&body=great! Or?"; + uriText = uriText.replace(" ", "%20"); + Uri uri = Uri.parse(uriText); + send.setData(uri); + startActivity(Intent.createChooser(send, "E-mail the app author!")); + return true; + } catch (Exception e) { // For example, android.content.ActivityNotFoundException + Log.e(TAG, e.toString()); + return false; + } + } else if (command.equals("sharejpeg")) { + try { + Intent share = new Intent(Intent.ACTION_SEND); + share.setType("image/jpeg"); + share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + params)); + startActivity(Intent.createChooser(share, "Share Picture")); + return true; + } catch (Exception e) { // For example, android.content.ActivityNotFoundException + Log.e(TAG, e.toString()); + return false; + } + } else if (command.equals("sharetext")) { + try { + Intent sendIntent = new Intent(); + sendIntent.setType("text/plain"); + sendIntent.putExtra(Intent.EXTRA_TEXT, params); + sendIntent.setAction(Intent.ACTION_SEND); + startActivity(sendIntent); + return true; + } catch (Exception e) { // For example, android.content.ActivityNotFoundException + Log.e(TAG, e.toString()); + return false; + } + } else if (command.equals("showTwitter")) { + try { + String twitter_user_name = params; + try { + startActivity(new Intent(Intent.ACTION_VIEW, + Uri.parse("twitter://user?screen_name=" + + twitter_user_name))); + } catch (Exception e) { + startActivity(new Intent( + Intent.ACTION_VIEW, + Uri.parse("https://twitter.com/#!/" + twitter_user_name))); + } + return true; + } catch (Exception e) { // For example, android.content.ActivityNotFoundException + Log.e(TAG, e.toString()); + return false; } } else if (command.equals("launchMarket")) { // Don't need this, can just use launchBrowser with a market: diff --git a/ext/native/net/http_client.h b/ext/native/net/http_client.h index 34c03c2ffa..e8ca917da9 100644 --- a/ext/native/net/http_client.h +++ b/ext/native/net/http_client.h @@ -104,6 +104,10 @@ public: cancelled_ = true; } + bool IsCancelled() const { + return cancelled_; + } + // NOTE: Callbacks are NOT executed until RunCallback is called. This is so that // the call will end up on the thread that calls g_DownloadManager.Update(). void SetCallback(std::function callback) {