Hi,<br><br>I have recently experienced an interesting behavior of the &#39;cairo_restore()&#39; function. It doesn&#39;t restore the cairo context saved by &#39;cairo_save()&#39; if an error occurs when executing windows gdi functions.<br>
<br>When I used these two functions I assumed that they must provide a transaction like functionality: &#39;cairo_save()&#39; saves the cairo context while &#39;cairo_restore()&#39; would restore it even if an error would occur by executing cairo functions between. But this is not the case. If a cairo function fail to execute between,&nbsp; by failing one of the windows gdi function, then &#39;cairo_restore()&#39; will not restore the previously saved context. <br>
I have experienced such situation for the application I&#39;m working on it. For an unknown reason sometime some windows gdi functions (CreateCompatibleDC(), BitBlt() and other) fail to execute with error code 6 and 8. In this situation the cairo function responsible with that windows gdi function call will set the error status to CAIRO_STATUS_NO_MEMORY and the &#39;cairo_restore()&#39; will not restore the cairo context. I have noticed that cairo context actually has not been damaged by the failure of the windows gdi function, yet the context is not restored.<br>
Also the cairo documentation doesn&#39;t mention that &#39;cairo_restore()&#39; will not restore the context if an error occurs in a cairo function between &#39;cairo_save()&#39; and &#39;cairo_restore()&#39;.<br><br>I would like to propose a change in the &#39;cairo_restore()&#39; implementation, such that:<br>
&nbsp; a) will restore the previously saved context by &#39;cairo_save()&#39; even if in an error occurs<br>&nbsp; b) will return as result the error code generated by any cairo function executed between &#39;cairo_save()&#39; and &#39;cairo_restore()&#39;<br>

&nbsp; c) will reset the error status to CAIRO_STATUS_SUCCESS so that any next execution of &#39;cairo_save()&#39; and &#39;cairo_restore()&#39; will not exit because of a previous status set to an error code.<br><br>The function would be something like:<br>
<br>int<br>cairo_restore (cairo_t *cr)<br>{<br>...<br>int result = CAIRO_STATUS_SUCESS;<br>if (cr-&gt;status != CAIRO_STATUS_SUCCESS)<br>{<br>&nbsp;&nbsp;&nbsp; result = cr-&gt;status;<br>&nbsp;&nbsp;&nbsp; cr-&gt;status = CAIRO_STATUS_SUCCESS;<br>&nbsp;&nbsp;&nbsp; if ((cr-&gt;gstate) &amp;&amp; (cr-&gt;gstate-&gt;target))<br>
&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cr-&gt;gstate-&gt;target-&gt;status = CAIRO_STATUS_SUCCESS;<br>&nbsp;&nbsp;&nbsp; }<br>}<br>// if (cr-&gt;status)<br>// return;<br>...<br>return result;<br>}<br><br><br>Best regards,<br>Iosif Haidu<br><br>