[gimp] app: fix crashes by not trying to navigate on a NULL layout
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: fix crashes by not trying to navigate on a NULL layout
- Date: Thu, 14 Oct 2010 09:04:07 +0000 (UTC)
commit 8e0dd56feb3aa6deba752aec44f8fde96ae611d7
Author: Michael Natterer <mitch gimp org>
Date: Thu Oct 14 11:01:16 2010 +0200
app: fix crashes by not trying to navigate on a NULL layout
Add boolean return value to gimp_text_tool_ensure_layout() and check
it where needed. Also fix the new VISUAL_POSITIONS navigation code yet
again.
app/tools/gimptexttool-editor.c | 37 ++++++++++++++++++-------------------
app/tools/gimptexttool.c | 4 +++-
app/tools/gimptexttool.h | 2 +-
3 files changed, 22 insertions(+), 21 deletions(-)
---
diff --git a/app/tools/gimptexttool-editor.c b/app/tools/gimptexttool-editor.c
index 025687f..3fd8d23 100644
--- a/app/tools/gimptexttool-editor.c
+++ b/app/tools/gimptexttool-editor.c
@@ -681,45 +681,43 @@ gimp_text_tool_move_cursor (GimpTextTool *text_tool,
if (! cancel_selection)
{
PangoLayout *layout;
- gint index;
- gint trailing;
- index = gimp_text_buffer_get_iter_index (text_tool->buffer,
- &cursor, TRUE);
+ if (! gimp_text_tool_ensure_layout (text_tool))
+ break;
layout = gimp_text_layout_get_pango_layout (text_tool->layout);
while (count != 0)
{
+ gint index;
+ gint trailing;
gint new_index;
+ index = gimp_text_buffer_get_iter_index (text_tool->buffer,
+ &cursor, TRUE);
+
if (count > 0)
{
pango_layout_move_cursor_visually (layout, TRUE, index, 0, 1,
&new_index, &trailing);
count--;
-
- if (new_index != G_MAXINT)
- index = new_index;
- else
- break;
}
else
{
pango_layout_move_cursor_visually (layout, TRUE, index, 0, -1,
&new_index, &trailing);
count++;
-
- if (new_index != -1)
- index = new_index;
- else
- break;
}
- }
- gimp_text_buffer_get_iter_at_index (text_tool->buffer,
- &cursor, index, TRUE);
- gtk_text_iter_forward_chars (&cursor, trailing);
+ if (new_index != G_MAXINT && new_index != -1)
+ index = new_index;
+ else
+ break;
+
+ gimp_text_buffer_get_iter_at_index (text_tool->buffer,
+ &cursor, index, TRUE);
+ gtk_text_iter_forward_chars (&cursor, trailing);
+ }
}
break;
@@ -753,7 +751,8 @@ gimp_text_tool_move_cursor (GimpTextTool *text_tool,
cursor_index = gimp_text_buffer_get_iter_index (text_tool->buffer,
&cursor, TRUE);
- gimp_text_tool_ensure_layout (text_tool);
+ if (! gimp_text_tool_ensure_layout (text_tool))
+ break;
layout = gimp_text_layout_get_pango_layout (text_tool->layout);
diff --git a/app/tools/gimptexttool.c b/app/tools/gimptexttool.c
index 1d36e0a..c44b2b2 100644
--- a/app/tools/gimptexttool.c
+++ b/app/tools/gimptexttool.c
@@ -1740,7 +1740,7 @@ gimp_text_tool_clear_layout (GimpTextTool *text_tool)
}
}
-void
+gboolean
gimp_text_tool_ensure_layout (GimpTextTool *text_tool)
{
if (! text_tool->layout && text_tool->text)
@@ -1749,6 +1749,8 @@ gimp_text_tool_ensure_layout (GimpTextTool *text_tool)
text_tool->layout = gimp_text_layout_new (text_tool->layer->text, image);
}
+
+ return text_tool->layout != NULL;
}
void
diff --git a/app/tools/gimptexttool.h b/app/tools/gimptexttool.h
index 194a426..b93c29c 100644
--- a/app/tools/gimptexttool.h
+++ b/app/tools/gimptexttool.h
@@ -118,7 +118,7 @@ void gimp_text_tool_create_vectors_warped (GimpTextTool *text_tool);
/* only for the text editor */
void gimp_text_tool_clear_layout (GimpTextTool *text_tool);
-void gimp_text_tool_ensure_layout (GimpTextTool *text_tool);
+gboolean gimp_text_tool_ensure_layout (GimpTextTool *text_tool);
#endif /* __GIMP_TEXT_TOOL_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]