<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
solved, should create a specific type of Attribute instead of base class. like Pango::AttrColor</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> cairo <cairo-bounces@cairographics.org> on behalf of mhao1999@live.cn <mhao1999@live.cn><br>
<b>Sent:</b> Wednesday, September 22, 2021 11:19 PM<br>
<b>To:</b> cairo@cairographics.org <cairo@cairographics.org><br>
<b>Subject:</b> [cairo] Pango:Attribute set_start_index(0) crash</font>
<div> </div>
</div>
<style type="text/css" style="display:none">
<!--
p
{margin-top:0;
margin-bottom:0}
-->
</style>
<div dir="ltr">
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
I want to apply foreground color to each of string "the" like below using pangomm:</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<span style="color:#c0c0c0"></span><span style="color:#808000"> auto</span><span style="color:#c0c0c0">
</span><span style="color:#092e64">layout</span><span style="color:#c0c0c0"> </span>
=<span style="color:#c0c0c0"> </span><span style="color:#00677c">create_pango_layout</span>(<span style="color:#008000">"the"</span>);
<pre style="margin-top:0px; margin-bottom:0px"><span style="color:#c0c0c0"> </span><span style="color:#092e64">layout</span>-><span style="color:#00677c">set_font_description</span>(<span style="color:#092e64">font</span>);</pre>
<pre style="margin-top:0px; margin-bottom:0px"><span style="color:#c0c0c0"> </span><span style="color:#800080">Pango</span>::<span style="color:#800080">AttrList</span><span style="color:#c0c0c0"> </span><span style="color:#092e64">attrlist</span>;</pre>
<pre style="margin-top:0px; margin-bottom:0px"><span style="color:#c0c0c0"> </span><span style="color:#800080">Pango</span>::<span style="color:#800080">Attribute</span><span style="color:#c0c0c0"> </span><span style="color:#092e64">attr1</span>;</pre>
<pre style="margin-top:0px; margin-bottom:0px"><span style="color:#c0c0c0"> </span><span style="color:#092e64">attr1</span>.<span style="color:#00677c">create_attr_foreground</span>(<span style="color:#000080">255</span>,<span style="color:#c0c0c0"> </span><span style="color:#000080">0</span>,<span style="color:#c0c0c0"> </span><span style="color:#000080">0</span>);</pre>
<pre style="margin-top:0px; margin-bottom:0px"><span style="color:#c0c0c0"> </span><span style="color:#092e64">attr1</span>.<span style="color:#00677c">set_start_index</span>(<span style="color:#000080">0</span>);</pre>
<pre style="margin-top:0px; margin-bottom:0px"><span style="color:#c0c0c0"> </span><span style="color:#092e64">attr1</span>.<span style="color:#00677c">set_end_index</span>(<span style="color:#000080">1</span>);</pre>
<pre style="margin-top:0px; margin-bottom:0px"><span style="color:#c0c0c0"> </span><span style="color:#092e64">attrlist</span>.<span style="color:#00677c">insert</span>(<span style="font-style:italic; color:#092e64">attr1</span>);</pre>
<pre style="margin-top:0px; margin-bottom:0px"><br></pre>
<pre style="margin-top:0px; margin-bottom:0px"><span style="color:#c0c0c0"> </span><span style="color:#800080">Pango</span>::<span style="color:#800080">Attribute</span><span style="color:#c0c0c0"> </span><span style="color:#092e64">attr2</span>;</pre>
<pre style="margin-top:0px; margin-bottom:0px"><span style="color:#c0c0c0"> </span><span style="color:#092e64">attr2</span>.<span style="color:#00677c">create_attr_foreground</span>(<span style="color:#000080">0</span>,<span style="color:#c0c0c0"> </span><span style="color:#000080">255</span>,<span style="color:#c0c0c0"> </span><span style="color:#000080">0</span>);</pre>
<pre style="margin-top:0px; margin-bottom:0px"><span style="color:#c0c0c0"> </span><span style="color:#092e64">attr2</span>.<span style="color:#00677c">set_start_index</span>(<span style="color:#000080">1</span>);</pre>
<pre style="margin-top:0px; margin-bottom:0px"><span style="color:#c0c0c0"> </span><span style="color:#092e64">attr2</span>.<span style="color:#00677c">set_end_index</span>(<span style="color:#000080">2</span>);</pre>
<pre style="margin-top:0px; margin-bottom:0px"><span style="color:#c0c0c0"> </span><span style="color:#092e64">attrlist</span>.<span style="color:#00677c">insert</span>(<span style="font-style:italic; color:#092e64">attr2</span>);</pre>
<pre style="margin-top:0px; margin-bottom:0px"><br></pre>
<pre style="margin-top:0px; margin-bottom:0px"><span style="color:#c0c0c0"> </span><span style="color:#800080">Pango</span>::<span style="color:#800080">Attribute</span><span style="color:#c0c0c0"> </span><span style="color:#092e64">attr3</span>;</pre>
<pre style="margin-top:0px; margin-bottom:0px"><span style="color:#c0c0c0"> </span><span style="color:#092e64">attr3</span>.<span style="color:#00677c">create_attr_foreground</span>(<span style="color:#000080">0</span>,<span style="color:#c0c0c0"> </span><span style="color:#000080">0</span>,<span style="color:#c0c0c0"> </span><span style="color:#000080">255</span>);</pre>
<pre style="margin-top:0px; margin-bottom:0px"><span style="color:#c0c0c0"> </span><span style="color:#092e64">attr3</span>.<span style="color:#00677c">set_start_index</span>(<span style="color:#000080">2</span>);</pre>
<pre style="margin-top:0px; margin-bottom:0px"><span style="color:#c0c0c0"> </span><span style="color:#092e64">attr3</span>.<span style="color:#00677c">set_end_index</span>(<span style="color:#000080">3</span>);</pre>
<pre style="margin-top:0px; margin-bottom:0px"><span style="color:#c0c0c0"> </span><span style="color:#092e64">attrlist</span>.<span style="color:#00677c">insert</span>(<span style="font-style:italic; color:#092e64">attr3</span>);</pre>
<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
When I debug using Qt creator, step over attr1.set_start_index(0), it crash, says:</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
"The inferior stopped because it received a signal from the operating system.</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Signal name: SIGSEGV</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Signal meaning: Segmentation fault</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Anybody can shed a light on it, thanks!</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
</div>
</body>
</html>