<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Cyrille Berger &#187; Programming</title>
	<atom:link href="http://blog.cberger.net/tags/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.cberger.net</link>
	<description>What I do, where I live, what I think.</description>
	<lastBuildDate>Mon, 30 Aug 2010 09:38:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to find where an exception is emited with Qt ?</title>
		<link>http://blog.cberger.net/2010/02/24/how-to-find-where-an-exception-is-emited-with-qt/</link>
		<comments>http://blog.cberger.net/2010/02/24/how-to-find-where-an-exception-is-emited-with-qt/#comments</comments>
		<pubDate>Wed, 24 Feb 2010 09:51:02 +0000</pubDate>
		<dc:creator>Cyrille Berger</dc:creator>
				<category><![CDATA[KDE]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Qt]]></category>

		<guid isPermaLink="false">http://cyrilleberger.wordpress.com/?p=918</guid>
		<description><![CDATA[When an exception is thrown and not catched in a Qt application, it get catched by Qt&#8217;s event loop, and the following message is displayed in the console:
 Qt has caught an exception thrown from an event handler. Throwing exceptions from an event handler is not supported in Qt. You must reimplement QApplication::notify() and catch [...]]]></description>
			<content:encoded><![CDATA[<p>When an exception is thrown and not catched in a Qt application, it get catched by Qt&#8217;s event loop, and the following message is displayed in the console:</p>
<p><code> Qt has caught an exception thrown from an event handler. Throwing exceptions from an event handler is not supported in Qt. You must reimplement QApplication::notify() and catch all exceptions there. terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc </code> </p>
<p>In other situations, <em>std::bad_alloc</em> is replaced by the name of the exception. The problem is that if you now want to know where it happens in your program, the backtrace points to where the exception is rethrown by Qt&#8217;s event loop, which is not where the error happens.</p>
<p>I first had this problem a few days ago when implementing multi-layers support in EXR, since the exception name was specific to OpenEXR, I just grepped the code and deduce where the error occurred. But this is not very convenient when the error is generic, like <em>std::bad_alloc</em> which can be thrown just anywhere. And as it turned out by Qt itself in &#8216;qBadAlloc()&#8217;. The solution suggested by Maelcum on IRC is simply to set a breakpoint in the function <em>__cxa_throw</em>, which is a function of the C++ standard library that is actually doing the job when the keyword <em>throw</em> is used (at least with the GNU stdlib++, no idea if it is valid with other standard library implementation). And then you get a backtrace that point to the problem.</p>
<p>I thought I would share this tip in case, in some day, you find yourself with an uncaught exception in a Qt application.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cberger.net/2010/02/24/how-to-find-where-an-exception-is-emited-with-qt/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>OpenGTL 0.9.12 and Shiva noise</title>
		<link>http://blog.cberger.net/2009/11/20/opengtl-0-9-12-and-shiva-noise/</link>
		<comments>http://blog.cberger.net/2009/11/20/opengtl-0-9-12-and-shiva-noise/#comments</comments>
		<pubDate>Fri, 20 Nov 2009 19:14:05 +0000</pubDate>
		<dc:creator>Cyrille Berger</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[OpenGTL]]></category>
		<category><![CDATA[Graphics]]></category>
		<category><![CDATA[Open Souce]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Shiva]]></category>

		<guid isPermaLink="false">http://blog.cberger.net/?p=826</guid>
		<description><![CDATA[OpenGTL 0.9.12
Earlier today I made a new release of OpenGTL (download page), version 0.9.12, for that release 23 tasks were completed, the main changes are:

Fixing thread safety issues at run time.
Progress report.
Many new mathematical functions for the Shiva standard library.
Replacement of the Shiva kernels random functions.
OpenGTL is now compiling and running on Mac OS X.

The [...]]]></description>
			<content:encoded><![CDATA[<h2>OpenGTL 0.9.12</h2>
<p>Earlier today I made a new release of <a href="http://www.opengtl.org">OpenGTL</a> (<a href="http://www.opengtl.org//Download.html">download page</a>), version 0.9.12, for that release <a href="http://tasks.opengtl.org/index.php?do=index&amp;tasks=&amp;project=1&amp;due=23&amp;status[]=">23 tasks</a> were completed, the main changes are:</p>
<ul>
<li>Fixing thread safety issues at run time.</li>
<li>Progress report.</li>
<li>Many new mathematical functions for the Shiva standard library.</li>
<li>Replacement of the Shiva kernels random functions.</li>
<li>OpenGTL is now compiling and running on Mac OS X.</li>
</ul>
<p>The first two points are important changes for <a href="http://www.krita.org">krita</a>, since the first one meant that with the previous releases we had to use mutex while executing Kernels, preventing to benefit from multi-core. The second one means the user can see something is happening in Krita when a filter is processed.</p>
<h2>Random functions in Shiva</h2>
<p>This new release also break the Shiva language compared to previous release, I try to prevent that, but since the language is still very young it was bound to happen. In previous releases I quickly introduced a <em>rand()</em> function, because I wanted to write a <a href="http://en.wikipedia.org/wiki/Perlin_noise">perlin noise</a> generator. The problem with <em>rand()</em> is that it does not take a seed parameter, meaning that the function use the global seed, meaning that two consecutive call to ther <em>perlin noise</em> generator kernel gives two different results, without any kind of control. For graphics, we need to make sure that the result are reproductible, so now in 0.9.12, the function <em>rand()</em> has been replace by one that takes a seed parameter <em>rand(output int seed)</em>.</p>
<p>Such a function is usefull at init time, to construct random structures, like those needed by the <em>perlin noise</em>. But this is not sufficient, we also need a random function that can be used while processing a pixel, and one that would always return the same value for a given pixel and a given seed, for instance to write a <a href="http://en.wikipedia.org/wiki/Salt_and_pepper_noise">salt and pepper noise</a> generator.</p>
<p>The problem of the <em>rand(output int seed)</em> function is that it works by incrementing the seed parameter, so that next time you call it, it gives a different result, so as long as the call are made sequentially it would work fine. But in case of Shiva (or Krita, for that matter), we cannot guarantee that those call will be made sequentially,  and it is not possible to keep a value between the computation of two different pixels. Because we might just be interested in generating part of the image, or we might be executing the kernel in a multi-threaded environment. To solve this problem, about six monthes ago, in Krita, we developed an algorithm that takes the pixel coordinate and the seed, and return a pseudo-random number. For 0.9.12, I copied that algorithm in Shiva, giving birth to the second new function for random number generation, which is <em>rand(int x, int y, int seed)</em>.</p>
<p>The code for the <em>salt and pepper noise</em> generator is:</p>
<p><code>kernel Noise<br />
{<br />
&nbsp;&nbsp;void evaluatePixel(out pixel4 result)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;int x = result.coord.x;<br />
&nbsp;&nbsp;&nbsp;&nbsp;int y = result.coord.y;<br />
&nbsp;&nbsp;&nbsp;&nbsp;for(int i = 0; i &lt; 3; ++i)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;result[i] = frand(x, y, 32);<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;result.setAlpha( 1.0);<br />
&nbsp;&nbsp;}<br />
}<br />
</code></p>
<p>The code for the <em>perlin noise</em> generator is slightly more complicated and can be watch in the <a href="http://bitbucket.org/opengtl/opengtl/src/tip/OpenShiva/tests/imagegenerators/PerlinNoise.shiva">opengtl mercurial repository</a>.</p>
<p>And the resulting images, <em>salt and pepper noise</em> on the left, and <em>perlin noise</em> on the right:</p>
<div style="text-align:center;"><img src="http://cyrille.diwi.org/images/kritablog/Noise.png" alt="" />&nbsp;<img src="http://cyrille.diwi.org/images/kritablog/PerlinNoise.png" alt="" /></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.cberger.net/2009/11/20/opengtl-0-9-12-and-shiva-noise/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
