<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>[Al 5.0.5] Works on Linux, doesn&#39;t in WIndows</title>
		<link>http://www.allegro.cc/forums/view/609612</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Thu, 22 Mar 2012 17:48:51 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That&#39;s it: some examples of my new Allegro.pas wrapper that works on Linux (Xubuntu) raises a SIGSEGV on Windows XP SP2.</p><p>I suspect it&#39;s a problem drawing on memory bitmaps, because if the program doesn&#39;t do that (i.e. it uses OpenGL only) it works without problems.</p><p>For example, it fails at line:<br /><span class="source-code">	<a href="http://www.allegro.cc/manual/al_put_pixel"><span class="a">al_put_pixel</span></a> <span class="k2">(</span>i, j, <a href="http://www.allegro.cc/manual/al_color_hsv"><span class="a">al_color_hsv</span></a> <span class="k2">(</span>hue, sat, <span class="n">1</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span></span><br />Where:
</p><div class="source-code snippet"><div class="inner"><pre>  i <span class="k3">=</span> <span class="n">0</span>
  j <span class="k3">=</span> <span class="n">9</span>
  hue <span class="k3">=</span> <span class="n">180</span>
  sat <span class="k3">=</span> <span class="n">0</span>.<span class="n">335790485</span>
</pre></div></div><p>
GDB backtrace is:
</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span>Program received <a href="http://www.delorie.com/djgpp/doc/libc/libc_724.html" target="_blank">signal</a> SIGSEGV, Segmentation fault.
<span class="number">  2</span><span class="n">0x3f2a09a2</span> in ?? <span class="k2">(</span><span class="k2">)</span>
<span class="number">  3</span><span class="k2">(</span>gdb<span class="k2">)</span> bt
<span class="number">  4</span><span class="p">#0  0x3f2a09a2 in ?? ()</span>
<span class="number">  5</span><span class="p">#1  0x3f800000 in ?? ()</span>
<span class="number">  6</span><span class="p">#2  0x3f800000 in ?? ()</span>
<span class="number">  7</span><span class="p">#3  0x3f800000 in ?? ()</span>
<span class="number">  8</span><span class="p">#4  0x0ba708a0 in ?? ()</span>
<span class="number">  9</span><span class="p">#5  0x0ba708e4 in ?? ()</span>
<span class="number"> 10</span><span class="p">#6  0x0142fc08 in ?? ()</span>
<span class="number"> 11</span><span class="p">#7  0x7c91ee18 in strchr () from ntdll.dll</span>
<span class="number"> 12</span><span class="p">#8  0x7c936ac8 in ntdll!iswdigit () from ntdll.dll</span>
<span class="number"> 13</span><span class="p">#9  0xffffffff in ?? ()</span>
<span class="number"> 14</span><span class="p">#10 0x7c936abe in ntdll!iswdigit () from ntdll.dll</span>
<span class="number"> 15</span><span class="p">#11 0x7c9368ad in ntdll!iswdigit () from ntdll.dll</span>
<span class="number"> 16</span><span class="p">#12 0x00040000 in ?? ()</span>
<span class="number"> 17</span><span class="p">#13 0x40000060 in ?? ()</span>
<span class="number"> 18</span><span class="p">#14 0x7c92056d in ntdll!RtlFreeThreadActivationContextStack () from ntdll.dll</span>
<span class="number"> 19</span><span class="p">#15 0x00000000 in ?? () from</span>
<span class="number"> 20</span><span class="p">#16 0x00000000 in ?? () from</span>
<span class="number"> 21</span><span class="p">#17 0x001389c0 in ?? ()</span>
<span class="number"> 22</span><span class="p">#18 0x00000004 in ?? ()</span>
<span class="number"> 23</span><span class="p">#19 0x00276728 in ?? ()</span>
<span class="number"> 24</span><span class="p">#20 0x0142fc90 in ?? ()</span>
<span class="number"> 25</span><span class="p">#21 0x77c06fab in qsort () from C:\WINDOWS\system32\msvcrt.dll</span>
<span class="number"> 26</span><span class="p">#22 0x00276724 in ?? ()</span>
<span class="number"> 27</span><span class="k3">-</span><span class="k3">-</span><span class="k3">-</span>Type <span class="k3">&lt;</span>return&gt; to <span class="k1">continue</span>, <span class="k1">or</span> q <span class="k3">&lt;</span>return&gt; to quit---
<span class="number"> 28</span><span class="p">#23 0x00000004 in ?? ()</span>
<span class="number"> 29</span><span class="p">#24 0x67353d44 in d3d_display_thread_proc ()</span>
<span class="number"> 30</span>   from C:\WINDOWS\system32\allegro-5.0.5-monolith-mt-debug.dll
<span class="number"> 31</span><span class="p">#25 0x00402284 in INIT () at examples/ex_blit.pas:251</span>
<span class="number"> 32</span><span class="p">#26 0x00402308 in main () at examples/ex_blit.pas:269</span>
</div></div><p>
As you see I&#39;m using &quot;allegro-5.0.5-monolith-mt-<b>debug</b>.dll&quot; but it doesn&#39;t show a lot...</p><p>Another example (actually ex_gldepth), it shows an &quot;Assertion failed!&quot; message at file &quot;text.c&quot; line 102, Expression: text.  But if I comment the lines that draws text on the texture it works perfectly.</p><p>May be it&#39;s related with the <a href="http://www.allegro.cc/forums/thread/602423/841541#target">Allegro4 polygon3d issue</a>, Free Pascal enables CPU exceptions for data conversion.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Niunio)</author>
		<pubDate>Thu, 23 Feb 2012 17:57:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Can you set a breakpoint on al_put_pixel then step through and see how it ends up in qsort? (It shouldn&#39;t...)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Thu, 23 Feb 2012 21:27:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That stack trace looks broken <img src="http://www.allegro.cc/forums/smileys/shocked.gif" alt=":o" /></p><p>Make sure you&#39;re also compiling your code in debug mode, as well as linking to the debug versions of the system libraries. If that doesn&#39;t help, you&#39;re blowing up the stack.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Fri, 24 Feb 2012 00:52:52 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;ve recompiled the Allegro 5 libraries (I was using Matthew&#39;s precompiled ones) but stack trace is still broken. <img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" /></p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/609612/948073#target">Elias</a> said:</div><div class="quote"><p>Can you set a breakpoint on al_put_pixel then step through and see how it ends up in qsort?</p></div></div><p>I did but GDB seems to be unable to step-in Allegro. If I debug the C examples it steps in correctly.</p><p>[off-topic] BTW, why does it use qsort? I&#39;ve read the code and I don&#39;t understand the benefits of sorting it (and with qsort!!! Remember it&#39;s not the fastest in <i>all</i> cases <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /> ). May be that&#39;s why Al5 looks slower than Al4 in software rendering.[/off-topic]</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/609612/948118#target">Thomas Fjellstrom</a> said:</div><div class="quote"><p>Make sure you&#39;re also compiling your code in debug mode, as well as linking to the debug versions of the system libraries.</p></div></div><p> I have revised it and it is correct.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>If that doesn&#39;t help, you&#39;re blowing up the stack.</p></div></div><p> Question is, how did I blowed up the stack? <img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" /> In Linux it looks (and runs) nice.</p><p>May be I should ask to Free Pascal/Lazarus experts. <img src="http://www.allegro.cc/forums/smileys/embarassed.gif" alt=":-[" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Niunio)</author>
		<pubDate>Fri, 24 Feb 2012 19:47:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/609612/948222#target">Niunio</a> said:</div><div class="quote"><p>BTW, why does it use qsort?</p></div></div><p>

That&#39;s the point, it does not. So I&#39;m puzzled how how you can get a crash inside qsort... <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Fri, 24 Feb 2012 20:08:25 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;ve realized that my installation was old (I was using GDB 6!) so I&#39;ve updated and recompiled... And now I have different information.</p><p>I did a step-by-step execution to see if it can debug inside the DLL, for example:
</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span><span class="k2">(</span>gdb<span class="k2">)</span> s
<span class="number">  2</span>EXAMPLEBITMAP <span class="k2">(</span>W<span class="k3">=</span><span class="n">100</span>, H<span class="k3">=</span><span class="n">100</span><span class="k2">)</span> at examples<span class="k3">/</span>ex_blit.pas:29
<span class="number">  3</span><span class="n">29</span>          mx <span class="k2">:</span><span class="k3">=</span> w <span class="k3">*</span> <span class="n">0</span>.<span class="n">5</span><span class="k2">;</span>
<span class="number">  4</span><span class="k2">(</span>gdb<span class="k2">)</span> n
<span class="number">  5</span><span class="n">30</span>          my <span class="k2">:</span><span class="k3">=</span> h <span class="k3">*</span> <span class="n">0</span>.<span class="n">5</span><span class="k2">;</span>
<span class="number">  6</span><span class="k2">(</span>gdb<span class="k2">)</span> n
<span class="number">  7</span><span class="n">31</span>          Pattern <span class="k2">:</span><span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_bitmap"><span class="a">al_create_bitmap</span></a> <span class="k2">(</span>w, h<span class="k2">)</span><span class="k2">;</span>
<span class="number">  8</span><span class="k2">(</span>gdb<span class="k2">)</span> n
<span class="number">  9</span><span class="n">0x00401530</span> in <a href="http://www.allegro.cc/manual/al_create_bitmap"><span class="a">al_create_bitmap</span></a> <span class="k2">(</span><span class="k2">)</span>
<span class="number"> 10</span><span class="k2">(</span>gdb<span class="k2">)</span> n
<span class="number"> 11</span>Single stepping until <a href="http://www.delorie.com/djgpp/doc/libc/libc_298.html" target="_blank">exit</a> from function <a href="http://www.allegro.cc/manual/al_create_bitmap"><span class="a">al_create_bitmap</span></a>,
<span class="number"> 12</span>which has no <a href="http://www.allegro.cc/manual/line"><span class="a">line</span></a> number information.
<span class="number"> 13</span><a href="http://www.allegro.cc/manual/al_create_bitmap"><span class="a">al_create_bitmap</span></a> <span class="k2">(</span>w<span class="k3">=</span><span class="n">100</span>, h<span class="k3">=</span><span class="n">100</span><span class="k2">)</span>
<span class="number"> 14</span>    at C:\msys\<span class="n">1</span>.<span class="n">0</span>\...\allegro-5.0.5\src\bitmap.c:142
<span class="number"> 15</span><span class="n">142</span>     <span class="k2">{</span>
<span class="number"> 16</span><span class="k2">(</span>gdb<span class="k2">)</span> n
<span class="number"> 17</span><span class="n">143</span>        <a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a> <span class="k3">*</span>bitmap <span class="k3">=</span> do_create_bitmap<span class="k2">(</span>w, h<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 18</span><span class="k2">(</span>gdb<span class="k2">)</span> n
<span class="number"> 19</span><span class="n">144</span>        <span class="k1">if</span> <span class="k2">(</span>bitmap<span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 20</span><span class="k2">(</span>gdb<span class="k2">)</span> n
<span class="number"> 21</span><span class="n">145</span>           _al_register_destructor<span class="k2">(</span>_al_dtor_list, bitmap,
<span class="number"> 22</span><span class="k2">(</span>gdb<span class="k2">)</span> n
<span class="number"> 23</span>...
</div></div><p>
You see it works.</p><p>But it still fails at the same line but showing different information:
</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span>Breakpoint <span class="n">3</span>, EXAMPLEBITMAP <span class="k2">(</span>W<span class="k3">=</span><span class="n">100</span>, H<span class="k3">=</span><span class="n">100</span><span class="k2">)</span> at examples<span class="k3">/</span>ex_blit.pas:44
<span class="number">  2</span><span class="n">44</span>              <a href="http://www.allegro.cc/manual/al_put_pixel"><span class="a">al_put_pixel</span></a> <span class="k2">(</span>i, j, <a href="http://www.allegro.cc/manual/al_color_hsv"><span class="a">al_color_hsv</span></a> <span class="k2">(</span>hue, sat, <span class="n">1</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  3</span><span class="k2">(</span>gdb<span class="k2">)</span> print i
<span class="number">  4</span>$<span class="n">10</span> <span class="k3">=</span> <span class="n">0</span>
<span class="number">  5</span><span class="k2">(</span>gdb<span class="k2">)</span> print j
<span class="number">  6</span>$<span class="n">11</span> <span class="k3">=</span> <span class="n">9</span>
<span class="number">  7</span><span class="k2">(</span>gdb<span class="k2">)</span> print hue
<span class="number">  8</span>$<span class="n">12</span> <span class="k3">=</span> <span class="n">180</span>
<span class="number">  9</span><span class="k2">(</span>gdb<span class="k2">)</span> print sat
<span class="number"> 10</span>$<span class="n">13</span> <span class="k3">=</span> <span class="n">0</span>.<span class="n">335790485</span>
<span class="number"> 11</span><span class="k2">(</span>gdb<span class="k2">)</span> step
<span class="number"> 12</span>
<span class="number"> 13</span>Program received <a href="http://www.delorie.com/djgpp/doc/libc/libc_724.html" target="_blank">signal</a> SIGSEGV, Segmentation fault.
<span class="number"> 14</span><span class="n">0x3f2a09a2</span> in ?? <span class="k2">(</span><span class="k2">)</span>
<span class="number"> 15</span><span class="k2">(</span>gdb<span class="k2">)</span> backtrace
<span class="number"> 16</span><span class="p">#0  0x3f2a09a2 in ?? ()</span>
<span class="number"> 17</span><span class="p">#1  0x3f800000 in ?? ()</span>
<span class="number"> 18</span><span class="p">#2  0x3f800000 in ?? ()</span>
<span class="number"> 19</span><span class="p">#3  0x3f800000 in ?? ()</span>
<span class="number"> 20</span><span class="p">#4  0x0bae2ec0 in ?? ()</span>
<span class="number"> 21</span><span class="p">#5  0x00402274 in INIT () at examples/ex_blit.pas:251</span>
<span class="number"> 22</span><span class="p">#6  0x004022f8 in main () at examples/ex_blit.pas:269</span>
<span class="number"> 23</span><span class="k2">(</span>gdb<span class="k2">)</span>
</div></div><p> It looks like it fails before it calls al_color_hsv, doesn&#39;t it? <img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" /></p><p>BTW, I&#39;ll ask at the Free Pascal mailing list because there are some odd warning messages that I don&#39;t understand, they&#39;re from another module but who knows::).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Niunio)</author>
		<pubDate>Thu, 01 Mar 2012 03:01:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Lots of ??s in stacktraces is a big clue to memory and stack corruption (so long as you have compiled <i>everything</i> with debug symbols).</p><p>It&#39;s hard to track down if you don&#39;t have access to tools like valgrind.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Thu, 01 Mar 2012 05:05:41 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Where to did you set breakpoint 3? I&#39;m still unsure as to where exactly it crashes from what you have shown...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Thu, 01 Mar 2012 05:26:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/609612/948727#target">Elias</a> said:</div><div class="quote"><p>Where to did you set breakpoint 3?</p></div></div><p>It&#39;s from a translation of the Allegro&#39;s ex_blitmap.c example to Pascal.  The breakpoint 3 is in next function:</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span>  FUNCTION ExampleBitmap <span class="k2">(</span>CONST w, h: INTEGER<span class="k2">)</span><span class="k2">:</span> ALLEGRO_BITMAPptr<span class="k2">;</span>
<span class="number">  2</span>  VAR
<span class="number">  3</span>    i, j: INTEGER<span class="k2">;</span>
<span class="number">  4</span>    mx, my, a, d, sat, hue: SINGLE<span class="k2">;</span>
<span class="number">  5</span>    State: <a href="http://www.allegro.cc/manual/ALLEGRO_STATE"><span class="a">ALLEGRO_STATE</span></a><span class="k2">;</span>
<span class="number">  6</span>    Lock: ALLEGRO_LOCKED_REGIONptr<span class="k2">;</span>
<span class="number">  7</span>    Pattern: ALLEGRO_BITMAPptr<span class="k2">;</span>
<span class="number">  8</span>  BEGIN
<span class="number">  9</span>    mx <span class="k2">:</span><span class="k3">=</span> w <span class="k3">*</span> <span class="n">0</span>.<span class="n">5</span><span class="k2">;</span>
<span class="number"> 10</span>    my <span class="k2">:</span><span class="k3">=</span> h <span class="k3">*</span> <span class="n">0</span>.<span class="n">5</span><span class="k2">;</span>
<span class="number"> 11</span>    Pattern <span class="k2">:</span><span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_bitmap"><span class="a">al_create_bitmap</span></a> <span class="k2">(</span>w, h<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 12</span>    <a href="http://www.allegro.cc/manual/al_store_state"><span class="a">al_store_state</span></a> <span class="k2">(</span>State, ALLEGRO_STATE_TARGET_BITMAP<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 13</span>    <a href="http://www.allegro.cc/manual/al_set_target_bitmap"><span class="a">al_set_target_bitmap</span></a> <span class="k2">(</span>Pattern<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 14</span>    Lock <span class="k2">:</span><span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_lock_bitmap"><span class="a">al_lock_bitmap</span></a> <span class="k2">(</span>Pattern, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_WRITEONLY<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 15</span>    FOR i <span class="k2">:</span><span class="k3">=</span> <span class="n">0</span> TO w <span class="k3">-</span> <span class="n">1</span> DO
<span class="number"> 16</span>    BEGIN
<span class="number"> 17</span>      FOR j <span class="k2">:</span><span class="k3">=</span> <span class="n">0</span> TO h <span class="k3">-</span> <span class="n">1</span> DO
<span class="number"> 18</span>      BEGIN
<span class="number"> 19</span>        a <span class="k2">:</span><span class="k3">=</span> arctan2 <span class="k2">(</span>i <span class="k3">-</span> mx, j <span class="k3">-</span> my<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 20</span>        d <span class="k2">:</span><span class="k3">=</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_738.html" target="_blank">sqrt</a> <span class="k2">(</span>power <span class="k2">(</span>i <span class="k3">-</span> mx, <span class="n">2</span><span class="k2">)</span> <span class="k3">+</span> power <span class="k2">(</span>j <span class="k3">-</span> my, <span class="n">2</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 21</span>        sat <span class="k2">:</span><span class="k3">=</span> power <span class="k2">(</span><span class="n">1</span> <span class="k3">-</span> <span class="n">1</span> <span class="k3">/</span> <span class="k2">(</span><span class="n">1</span> <span class="k3">+</span> d <span class="k3">*</span> <span class="n">0</span>.<span class="n">1</span><span class="k2">)</span>, <span class="n">5</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 22</span>        hue <span class="k2">:</span><span class="k3">=</span> <span class="n">3</span> <span class="k3">*</span> a <span class="k3">*</span> <span class="n">180</span> <span class="k3">/</span> <a href="http://www.allegro.cc/manual/ALLEGRO_PI"><span class="a">ALLEGRO_PI</span></a><span class="k2">;</span>
<span class="number"> 23</span>        hue <span class="k2">:</span><span class="k3">=</span> <span class="k2">(</span>hue <span class="k3">/</span> <span class="n">360</span> <span class="k3">-</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_330.html" target="_blank">floor</a> <span class="k2">(</span>hue <span class="k3">/</span> <span class="n">360</span><span class="k2">)</span><span class="k2">)</span> <span class="k3">*</span> <span class="n">360</span><span class="k2">;</span>
<span class="number"> 24</span>        <a href="http://www.allegro.cc/manual/al_put_pixel"><span class="a">al_put_pixel</span></a> <span class="k2">(</span>i, j, <a href="http://www.allegro.cc/manual/al_color_hsv"><span class="a">al_color_hsv</span></a> <span class="k2">(</span>hue, sat, <span class="n">1</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span> <span class="k2">{</span> <span class="k3">&lt;</span><span class="k3">-</span><span class="k3">-</span> breakpoint <span class="n">3</span> <span class="k2">}</span>
<span class="number"> 25</span>      END<span class="k2">;</span>
<span class="number"> 26</span>    END<span class="k2">;</span>
<span class="number"> 27</span>    <a href="http://www.allegro.cc/manual/al_put_pixel"><span class="a">al_put_pixel</span></a> <span class="k2">(</span><span class="n">0</span>, <span class="n">0</span>, <a href="http://www.allegro.cc/manual/al_map_rgb"><span class="a">al_map_rgb</span></a> <span class="k2">(</span><span class="n">0</span>, <span class="n">0</span>, <span class="n">0</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 28</span>    <a href="http://www.allegro.cc/manual/al_unlock_bitmap"><span class="a">al_unlock_bitmap</span></a> <span class="k2">(</span>Pattern<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 29</span>    <a href="http://www.allegro.cc/manual/al_restore_state"><span class="a">al_restore_state</span></a> <span class="k2">(</span>State<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 30</span>    ExampleBitmap <span class="k2">:</span><span class="k3">=</span> Pattern<span class="k2">;</span>
<span class="number"> 31</span>  END<span class="k2">;</span>
</div></div><p>

It fails in the 10th iteration of the inner loop, when i=0 and j=9.</p><p>As you see, the translation is almost &quot;word-by-word&quot;.</p><p>I was thinking about the problem is a bad function declaration, but if it is then why does it run on Linux?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Niunio)</author>
		<pubDate>Thu, 01 Mar 2012 07:02:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/609612/948734#target">Niunio</a> said:</div><div class="quote"><p>I was thinking about the problem is a bad function declaration, but if it is then why does it run on Linux?</p></div></div><p>

That&#39;s the beauty of undefined behavior... it may run. Or not.</p><p>The only thing I notice, when you pass State, shouldn&#39;t you pass a pointer? I.e. @State?</p><p>Also, does it still crash if you simplify the function, like remove all the math and just put black pixels.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Thu, 01 Mar 2012 07:18:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Could this be related to the struct return calling convention mess? Try doing this (or the equivalent in Pascal):
</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/ALLEGRO_COLOR"><span class="a">ALLEGRO_COLOR</span></a> c<span class="k2">;</span>
c.r <span class="k3">=</span> c.g <span class="k3">=</span> c.b <span class="k3">=</span> c.a <span class="k3">=</span> <span class="n">1</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/al_put_pixel"><span class="a">al_put_pixel</span></a><span class="k2">(</span>i, j, c<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Thu, 01 Mar 2012 08:41:47 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Oh, good point. And I should have thought of it since I need to work around it in the Python wrapper.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Thu, 01 Mar 2012 17:05:58 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Elias, SiegeLord, it fails in both cases, but trying as SiegeLord says the program raises an ASSERTION:
</p><div class="source-code snippet"><div class="inner"><pre>Microsoft Virtual C<span class="k3">+</span><span class="k3">+</span> Runtime Library

Asertion failed<span class="k3">!</span>

Program: ...\ex_blit.exe
File: ...\bitmap.c
Line: <span class="n">200</span>

expression: bitmap <span class="k3">!</span><span class="k3">=</span> dest <span class="k3">&amp;</span><span class="k3">&amp;</span> bitmap <span class="k3">!</span><span class="k3">=</span> dest-&gt;parent
</pre></div></div><p> Also GDB warns inside of an Allegro function that &quot;bitmap&quot; points to an invalid data space (0x00a00000, VGA? <img src="http://www.allegro.cc/forums/smileys/rolleyes.gif" alt="::)" />).</p><p>I think that&#39;s the problem: it doesn&#39;t assigns correctly the &quot;bitmap&quot;, because <b>it fails in any example that tries to draw anything in a memory bitmap but works if it draws directly on the display (i.e: without changing the target bitmap or using OpenGL only)</b>.  Now I feel as I should say this in the first post... <img src="http://www.allegro.cc/forums/smileys/embarassed.gif" alt=":-[" /></p><p>I&#39;ll check all functions and procedures than assigns/sets bitmap targeting and/or options to see if they&#39;re correct.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/609612/948735#target">Elias</a> said:</div><div class="quote"><p>The only thing I notice, when you pass State, shouldn&#39;t you pass a pointer? I.e. @State?</p></div></div><p> I decided to use a more <i>Pascal-style</i> for the new Allegro.pas version so I used &quot;VAR&quot; that (as FPC documentation says) translates the parameter to a pointer when calling C functions. But I think I should check them too.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Niunio)</author>
		<pubDate>Thu, 01 Mar 2012 17:34:22 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ok, so what did you do for al_put_pixel? Is the color var as well?</p><p>Also, how certain are you that everything works if you don&#39;t use memory bitmaps? If you comment out the one line to make the bitmap a memory bitmap instead of video bitmap in the example, does everything work?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Thu, 01 Mar 2012 18:36:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/609612/948772#target">Elias</a> said:</div><div class="quote"><p>Ok, so what did you do for al_put_pixel? Is the color var as well?</p></div></div><p>No, it isn&#39;t. It doesn&#39;t use a pointer on C so I didn&#39;t in Pascal.
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>Also, how certain are you that everything works if you don&#39;t use memory bitmaps? If you comment out the one line to make the bitmap a memory bitmap instead of video bitmap in the example, does everything work?</p></div></div><p> After read again the documentation, now I&#39;m not sure as it looks like Allegro creates new bitmaps from video memory by default.</p><p>I did some more tests with more examples:</p><p>&quot;ex_line&quot; is the only example that works without any change.</p><p>&quot;ex_gldepth&quot; works if I comment the lines that draws text on the texture.</p><p>&quot;ex_rotate&quot; renders the first frame but then raises a &quot;runtime error 216&quot;. <img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" /></p><p>Similar behaviour for &quot;ex_warp_mouse&quot;: renders the first frame correctly but fails when I move the mouse.  If I comment all mouse events, it runs but raises a &quot;runtime error 217&quot; at exit.</p><p>I&#39;ve look for information about those 216 and 217 runtime error and I find <a href="http://www.articlesbase.com/operating-systems-articles/how-to-fix-runtime-error-217-the-easy-way-1256323.html">that 217 is fixed by register cleaning</a> and 216 is a trojan. <img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" /> So I did updated my antivir (again <img src="http://www.allegro.cc/forums/smileys/rolleyes.gif" alt="::)" />) and started a full scan, but I&#39;m not sure if it&#39;s the problem.<br />__________________________________________</p><p>[edit] Ok, I&#39;ve found an issue:</p><p>Free Pascal optimizes <i>enum</i> sizes but GCC does not optimizes.  This means that Pascal defines <i>enum</i> as BYTE, WORD or LONGWORD but GCC espects all as LONGWORD.  I don&#39;t know if this is enough to corrupt the stack but it seems possible.</p><p>Also, I should verify the <i>bool</i> size.</p><p>I must do more testing.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Niunio)</author>
		<pubDate>Thu, 08 Mar 2012 21:36:58 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If those enums ever hit the stack, any enums going to pascal from C, will push more onto the stack than expected, and going the other way, C will pop off more than expected.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Fri, 09 Mar 2012 00:03:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The Allegro functions likely use &quot;cdecl&quot; or something which means Pascal has to use the C calling convention (which should include enum sizes and things like that - else nothing would work).</p><p>But there&#39;s some border cases like the mentioned return of a struct which happens with a few functions like al_map_rgb and al_get_pixel. Like for example if gcc makes the al_map_rgb in the DLL return the color by putting it into the EAX and EDX registers but Pascal expects it on some stack location... the consequence will be undefined behavior. This hit me in the Python wrapper for example <span class="ref"><sup>[<a href="#">1</a>]</sup></span>
</p><div class="ref-block"><h2>References</h2><ol><li><a href="http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36834">http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36834</a></li></ol></div></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Fri, 09 Mar 2012 01:13:21 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If it helps, we could add alternative versions of those functions which update an output structure, if there aren&#39;t too many.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Wang)</author>
		<pubDate>Tue, 13 Mar 2012 16:39:41 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m still testing and updating (I have no much free time) but I think that the problem affects only some operations. For example, if I remove all pixel drawing<span class="ref"><sup>[<a href="#">1</a>]</sup></span> and text drawing some examples work nice (i.e. the ex_gldepth). But as I said I must do more testing and checking.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/609612/949369#target">Elias</a> said:</div><div class="quote"><p>But there&#39;s some border cases like the mentioned return of a struct which happens with a few functions like al_map_rgb and al_get_pixel. Like for example if gcc makes the al_map_rgb in the DLL return the color by putting it into the EAX and EDX registers but Pascal expects it on some stack location... the consequence will be undefined behavior.</p></div></div><p> It looks as an optimization. Is the Allegro&#39;s DLL &quot;Debug&quot; optimized? If so, how can I deactivate the optimization? I use CMake only to compile and install Allegro. <img src="http://www.allegro.cc/forums/smileys/undecided.gif" alt=":-/" /></p><p>IIRC PASCAL calling standard expects the first atomic parameters (INTEGER, BYTE...) into registers.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/609612/949790#target">Peter Wang</a> said:</div><div class="quote"><p>If it helps, we could add alternative versions of those functions which update an output structure, if there aren&#39;t too many.</p></div></div><p> It may help but what alternative?
</p><div class="ref-block"><h2>References</h2><ol><li>may be it&#39;s related with last Elias&#39; post about Python.</li></ol></div></div>]]>
		</description>
		<author>no-reply@allegro.cc (Niunio)</author>
		<pubDate>Wed, 21 Mar 2012 01:36:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/609612/949794#target">Niunio</a> said:</div><div class="quote"><p>It may help but what alternative?</p></div></div><p>

Well, for example:
</p><div class="source-code snippet"><div class="inner"><pre>al_get_pixel_color<span class="k2">(</span>x, y, <span class="k3">&amp;</span>color<span class="k2">)</span><span class="k2">;</span>
al_get_rgba_color<span class="k2">(</span>r, g, b, a, <span class="k3">&amp;</span>color<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

That&#39;s the only two (plus other forms al_map_rgba) I remember from the Python wrapper. Inside the wrapper I&#39;d then implement those other functions using the new functions instead of calling the DLL versions.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Wed, 21 Mar 2012 02:36:58 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I still don&#39;t understand. The procedures that are problematic are the ones that draw pixels and text, not the ones that retrieve data... <img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Niunio)</author>
		<pubDate>Wed, 21 Mar 2012 03:30:23 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>In the Python wrapper (and anywhere else someone attempts to directly call DLL functions) only those functions (who have a struct as return value) should be affected by the mentioned bug.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Wed, 21 Mar 2012 03:43:21 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ok, I did more testing, tweaking and <a href="http://en.wikipedia.org/wiki/Abracadabra">abracadabring</a> and I think I finally found where the problem is (but I&#39;m not sure why it is).</p><p>As you, Elias, said the problem is the &quot;makecolor&quot; family. If I do this:
</p><pre class="terminal">al_draw_line (a, b, c, d, al_map_rgb_f (1, 1, 1), 1);</pre><p>
it fails, but if I do this:
</p><pre class="terminal">ColorWhite := al_map_rgb_f (1, 1, 1);
al_draw_line (a, b, c, d, ColorWhite, 1);</pre><p>
then it works.</p><p>I suspect the problem is that Free Pascal enables CPU exceptions for data conversion or the optimizations that you said, or both.</p><p>Now, I&#39;ll try a to find a workaround, but I&#39;ve found that <b>font drawing still raises a <i>&quot;Runtime error 217...&quot;</i></b> at exit. <img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" /> But it draws the text correctly using the workaround above.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Niunio)</author>
		<pubDate>Thu, 22 Mar 2012 17:48:51 +0000</pubDate>
	</item>
</rss>
