Merge lp:~3v1n0/unity/fix-load-icon-crash-926658-5.0 into lp:unity/5.0

Proposed by Marco Trevisan (Treviño)
Status: Merged
Merged at revision: 2413
Proposed branch: lp:~3v1n0/unity/fix-load-icon-crash-926658-5.0
Merge into: lp:unity/5.0
Diff against target: 146 lines (+26/-39)
2 files modified
plugins/unityshell/src/ResultRendererTile.cpp (+26/-24)
tests/test_service_lens.c (+0/-15)
To merge this branch: bzr merge lp:~3v1n0/unity/fix-load-icon-crash-926658-5.0
Reviewer Review Type Date Requested Status
Andrea Azzarone (community) Approve
Michal Hruby (community) Needs Fixing
Review via email: mp+116090@code.launchpad.net

Commit message

ResultRendererTile: fix a crash if row.renderer<TextureContainer*>() is null

Description of the change

backported branch lp:~3v1n0/unity/fix-load-icon-crash-926658 to unity-5.0

To post a comment you must log in.
Revision history for this message
Michal Hruby (mhr3) wrote :

Same as https://code.launchpad.net/~3v1n0/unity/fix-load-icon-crash-926658/+merge/116091 this is not a proper fix for the issue.

Moreover glib::Object::IsType isn't available in 5.0.

Revision history for this message
Michal Hruby (mhr3) :
review: Needs Fixing
Revision history for this message
Andrea Azzarone (azzar1) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/unityshell/src/ResultRendererTile.cpp'
2--- plugins/unityshell/src/ResultRendererTile.cpp 2012-04-25 12:09:59 +0000
3+++ plugins/unityshell/src/ResultRendererTile.cpp 2013-01-30 19:02:21 +0000
4@@ -21,14 +21,10 @@
5 */
6
7
8-#include <sstream> // for ostringstream
9 #include "ResultRendererTile.h"
10
11-#include <boost/algorithm/string.hpp>
12-
13 #include <pango/pango.h>
14 #include <pango/pangocairo.h>
15-#include <gdk/gdk.h>
16 #include <gtk/gtk.h>
17
18 #include <NuxCore/Logger.h>
19@@ -51,6 +47,7 @@
20 namespace
21 {
22 nux::logging::Logger logger("unity.dash.results");
23+const std::string DEFAULT_GICON = ". GThemedIcon text-x-preview";
24
25 const int FONT_SIZE = 10;
26 }
27@@ -230,7 +227,7 @@
28
29 void ResultRendererTile::Preload(Result& row)
30 {
31- if (row.renderer<TextureContainer*>() == nullptr)
32+ if (!row.renderer<TextureContainer*>())
33 {
34 row.set_renderer(new TextureContainer());
35 LoadIcon(row);
36@@ -240,17 +237,25 @@
37
38 void ResultRendererTile::Unload(Result& row)
39 {
40- TextureContainer *container = row.renderer<TextureContainer*>();
41- delete container;
42+ delete row.renderer<TextureContainer*>();
43 row.set_renderer<TextureContainer*>(nullptr);
44 }
45
46 void ResultRendererTile::LoadIcon(Result& row)
47 {
48+ auto container = row.renderer<TextureContainer*>();
49+
50+ if (!container)
51+ {
52+ LOG_ERROR(logger) << "No valid container for Result " << row.name() << " with URI "
53+ << row.uri();
54+ return;
55+ }
56+
57 Style& style = Style::Instance();
58 std::string const& icon_hint = row.icon_hint;
59-#define DEFAULT_GICON ". GThemedIcon text-x-preview"
60 std::string icon_name;
61+
62 if (G_UNLIKELY(neko))
63 {
64 int tmp1 = style.GetTileIconSize() + (rand() % 16) - 8;
65@@ -266,28 +271,25 @@
66 icon_name = !icon_hint.empty() ? icon_hint : DEFAULT_GICON;
67 }
68
69-
70-
71- GIcon* icon = g_icon_new_for_string(icon_name.c_str(), NULL);
72- TextureContainer* container = row.renderer<TextureContainer*>();
73-
74- IconLoader::IconLoaderCallback slot = sigc::bind(sigc::mem_fun(this, &ResultRendererTile::IconLoaded), icon_hint, row);
75-
76- if (g_strrstr(icon_name.c_str(), "://"))
77+ auto slot = sigc::bind(sigc::mem_fun(this, &ResultRendererTile::IconLoaded), icon_hint, row);
78+
79+ if (icon_name.find("://") != std::string::npos)
80 {
81 container->slot_handle = IconLoader::GetDefault().LoadFromURI(icon_name, style.GetTileIconSize(), slot);
82 }
83- else if (G_IS_ICON(icon))
84- {
85- container->slot_handle = IconLoader::GetDefault().LoadFromGIconString(icon_name, style.GetTileIconSize(), slot);
86- }
87 else
88 {
89- container->slot_handle = IconLoader::GetDefault().LoadFromIconName(icon_name, style.GetTileIconSize(), slot);
90+ glib::Object<GIcon> icon(g_icon_new_for_string(icon_name.c_str(), nullptr));
91+
92+ if (G_IS_ICON(icon.RawPtr()))
93+ {
94+ container->slot_handle = IconLoader::GetDefault().LoadFromGIconString(icon_name, style.GetTileIconSize(), slot);
95+ }
96+ else
97+ {
98+ container->slot_handle = IconLoader::GetDefault().LoadFromIconName(icon_name, style.GetTileIconSize(), slot);
99+ }
100 }
101-
102- if (icon != NULL)
103- g_object_unref(icon);
104 }
105
106 nux::BaseTexture* ResultRendererTile::CreateTextureCallback(std::string const& texid,
107
108=== modified file 'tests/test_service_lens.c'
109--- tests/test_service_lens.c 2011-12-08 08:48:10 +0000
110+++ tests/test_service_lens.c 2013-01-30 19:02:21 +0000
111@@ -8,7 +8,6 @@
112 static void add_filters(ServiceLens *self);
113 static void on_search_changed(UnityScope* scope, UnityLensSearch *lens_search, UnitySearchType search_type, GCancellable *canc, ServiceLens* self);
114 static UnityActivationResponse* on_activate_uri(UnityScope* scope, const char* uri, ServiceLens* self);
115-static UnityPreview* on_preview_uri(UnityScope* scope, const char* uri, ServiceLens *self);
116
117 struct _ServiceLensPrivate
118 {
119@@ -59,8 +58,6 @@
120 G_CALLBACK(on_search_changed), self);
121 g_signal_connect(priv->scope, "activate-uri",
122 G_CALLBACK(on_activate_uri), self);
123- g_signal_connect(priv->scope, "preview-uri",
124- G_CALLBACK(on_preview_uri), self);
125
126 /* Get ready to export and export */
127 unity_lens_add_local_scope(priv->lens, priv->scope);
128@@ -183,18 +180,6 @@
129 return unity_activation_response_new(UNITY_HANDLED_TYPE_HIDE_DASH, "");
130 }
131
132-static UnityPreview*
133-on_preview_uri(UnityScope* scope, const char* uri, ServiceLens *self)
134-{
135- gchar *genres[] = {"awesome"};
136- return (UnityPreview*)unity_track_preview_new(1, "Animus Vox",
137- "The Glitch Mob", "Drink The Sea",
138- 404, genres, 1,
139- "file://music/the/track", "Play",
140- "", "play://music/the/track",
141- "preview://music/the/track", "pause://music/the/track");
142-}
143-
144 ServiceLens*
145 service_lens_new()
146 {

Subscribers

People subscribed via source and target branches