<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Strange Behaviour In My Program</title>
		<link>http://www.allegro.cc/forums/view/564450</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Thu, 09 Feb 2006 08:00:58 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;ve been moving some code around, rearranging stuff so that my game runs at the correct speed, regardless of the machine. While working on this, I stumbled upon a problem.</p><p>I make use of a counter that updates the screen at the refresh-rate, and I moved some blits into the function that is associated with that counter. But my screen was acting funny, so I figured out that I had two copies of the blits and forgot the delete the old ones. So to make sure nothing gets screwed up further, I comment-out the two lines that are my blits.</p><p>Now when I run the program, it seems to do it&#39;s normal thing, but there&#39;s something weird going on. When I move the player around, his Y velocity stays zero AT ALL TIMES. He can ride on air and never fall.</p><p>Now if I uncomment the two blits I have, suddenly the YVelocity works and the player becomes platform driven again.</p><p>Can anyone make any sense of this? Why is my YVelocity counter not working because of the original copy of the blits not being there? It&#39;s as if there&#39;s some memory problem and something is modifying my YVelocity counter without me telling it to...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Damian Grove)</author>
		<pubDate>Mon, 06 Feb 2006 13:31:41 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>With some code we will see more of your problem.<br />Post it using the <a href="http://www.allegro.cc/mockup.html">Code Tags</a>, and if it is a smart bug, perhaps somebody could help.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (GullRaDriel)</author>
		<pubDate>Mon, 06 Feb 2006 14:05:15 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well here&#39;s my timer function:</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">void</span> RefreshUpdate<span class="k2">(</span><span class="k1">void</span><span class="k2">)</span>
<span class="k2">{</span>
    <span class="k1">static</span> <span class="k1">int</span> last_retrace_count<span class="k2">;</span>
    <span class="k1">if</span><span class="k2">(</span>Closing <span class="k3">=</span><span class="k3">=</span> <span class="n">0</span> <span class="k3">&amp;</span><span class="k3">&amp;</span> last_retrace_count <span class="k3">&lt;</span> <a href="http://www.allegro.cc/manual/retrace_count" target="_blank"><span class="a">retrace_count</span></a><span class="k2">)</span>
    <span class="k2">{</span>
        <a href="http://www.allegro.cc/manual/masked_blit" target="_blank"><span class="a">masked_blit</span></a><span class="k2">(</span>objPlayer1.Layer, objPlayer1.LayerB, <span class="n">0</span>, <span class="n">0</span>, <span class="n">0</span>, <span class="n">0</span>, X_RESOLUTION, Y_RESOLUTION<span class="k2">)</span><span class="k2">;</span>
        <a href="http://www.allegro.cc/manual/masked_blit" target="_blank"><span class="a">masked_blit</span></a><span class="k2">(</span>objPlayer1.LayerH, objPlayer1.LayerB, <span class="n">0</span>, <span class="n">0</span>, <span class="n">0</span>, <span class="n">0</span>, X_RESOLUTION, Y_RESOLUTION<span class="k2">)</span><span class="k2">;</span>
        <a href="http://www.allegro.cc/manual/blit" target="_blank"><span class="a">blit</span></a><span class="k2">(</span>objPlayer1.LayerB, <a href="http://www.allegro.cc/manual/screen" target="_blank"><span class="a">screen</span></a>, <span class="n">0</span>, <span class="n">0</span>, <span class="n">0</span>, <span class="n">0</span>, X_RESOLUTION, Y_RESOLUTION<span class="k2">)</span><span class="k2">;</span>
        clear<span class="k2">(</span>objPlayer1.LayerH<span class="k2">)</span><span class="k2">;</span>
        last_retrace_count <span class="k3">=</span> <a href="http://www.allegro.cc/manual/retrace_count" target="_blank"><span class="a">retrace_count</span></a><span class="k2">;</span>
        Refresh<span class="k3">+</span><span class="k3">+</span><span class="k2">;</span>
    <span class="k2">}</span>
<span class="k2">}</span>
<a href="http://www.allegro.cc/manual/END_OF_FUNCTION" target="_blank"><span class="a">END_OF_FUNCTION</span></a><span class="k2">(</span>RefreshUpdate<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>



And here&#39;s where I&#39;ve setup the counter and such in the main() function:</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/LOCK_VARIABLE" target="_blank"><span class="a">LOCK_VARIABLE</span></a><span class="k2">(</span>Refresh<span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/LOCK_FUNCTION" target="_blank"><span class="a">LOCK_FUNCTION</span></a><span class="k2">(</span>RefreshUpdate<span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/install_int_ex" target="_blank"><span class="a">install_int_ex</span></a><span class="k2">(</span><span class="k3">&amp;</span>RefreshUpdate, BPS_TO_TIMER<span class="k2">(</span><span class="c">/*get_refresh_rate()*/</span><span class="n">70</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>



And here&#39;s the section of code there I commented-out two blits (because I put them in my timer function):</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">if</span><span class="k2">(</span>CompMode <span class="k3">=</span><span class="k3">=</span> <span class="n">0</span><span class="k2">)</span>
<span class="k2">{</span>
    <span class="k1">while</span><span class="k2">(</span>Tic <span class="k3">=</span><span class="k3">=</span> <span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
    Tic <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span>
    <span class="k3">+</span><span class="k3">+</span>FrameTic<span class="k2">;</span>
    <span class="c">//masked_blit(objPlayer1.Layer, objPlayer1.LayerB, 0, 0, 0, 0, X_RESOLUTION, Y_RESOLUTION);</span>
    <span class="c">//masked_blit(objPlayer1.LayerH, objPlayer1.LayerB, 0, 0, 0, 0, X_RESOLUTION, Y_RESOLUTION);</span>
<span class="k2">}</span>
</pre></div></div><p>



And as for what changes the YVelocity variable, that&#39;s in my CheckTopCollision function. I would show you that, but the code is on my other computer right now and that&#39;s a lot to retype, and because there&#39;s a lot to it, I make use of a lot of code that probably wouldn&#39;t make any sense to anyone (lots of math specific to the collision detection and engine). But at the moment at least, I can tell you that the function does update the YVelocity and is in no way associated with the timer I created.</p><p>I should note that the YVelocity variable is part of the objPlayer1 structure which has many other variables, including the Layer, LayerH, and LayerB bitmaps.</p><p>I should also note that while trying some profiling by adding the -pf option to GCC, I found that the YVelocity wouldn&#39;t update then either... unless I gave one of my variables a &#39;register&#39; class type. I don&#39;t know why, but somehow &#39;int&#39; made YVelocity always zero and &#39;register int&#39; made YVelocity work just fine.</p><p>I&#39;ve never seen anything like this before. If anyone still doesn&#39;t know by the time I can get my code over to this computer, I&#39;ll post it here and hopefully we can go from there.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Damian Grove)</author>
		<pubDate>Mon, 06 Feb 2006 14:27:33 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Move the blitting code out of the timer function! Actually, the timer function should be as short as possible.</p><p>Apart from that, did you make sure the timer will be installed after a gfx mode is set and all bitmaps valid? On a similar note, did you make sure that the timer will stop executing once either gfx mode is reset or any of those bitmaps destroyed?</p><p>Mind that last_retrace_count is uninitialized!</p><p>But don&#39;t bother about these things, because you should really move the drawing stuff out of your timer.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I&#39;ve never seen anything like this before.
</p></div></div><p>

There is a reason ... <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Indeterminatus)</author>
		<pubDate>Mon, 06 Feb 2006 17:27:29 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well I understand everything you&#39;ve said, but I want to disagree that that has anything to do with what&#39;s causing the problem, because as I mentioned, the YVelocity remained zero in the case where I used the &#39;pg&#39; option to compile/link, unless I made one of my int values a &#39;register int&#39;. Then suddenly YVelocity would change like it was supposed to. So I&#39;m not really seeing how it would explain that.</p><p>To confirm some thing, the &#39;Closing&#39; variable is initalized at -1 until I get my bitmaps and such loaded, then it is set to 0 so that my timer will work. When I begin shutting down, it is set to 1 so that it won&#39;t try to blit while closing allegro and deleting the bitmaps from memory.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Damian Grove)</author>
		<pubDate>Tue, 07 Feb 2006 01:50:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It&#39;s perhaps some brackets you have badly positioned ?<br />Attach a zip file with the whole code, and if you want i&#39;ll give it a test and post my feedbacks/error founds/ if there are any.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (GullRaDriel)</author>
		<pubDate>Tue, 07 Feb 2006 14:50:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Alrighty, I finally got around to getting some files uploaded.</p><p>Complete engine:<br /><a href="http://www.shadowsoft-games.com/saxman/Engine.zip">http://www.shadowsoft-games.com/saxman/Engine.zip</a></p><p>MAIN.EXE source code:<br /><a href="http://www.shadowsoft-games.com/saxman/Code.zip">http://www.shadowsoft-games.com/saxman/Code.zip</a></p><p>The only file I excluded from Engine.zip was a file called NewDrug.ogg. I am not sure if the engine will run without this file or not... if not, you can just grab any random OGG file and put in it&#39;s place.</p><p>Also, I&#39;ll tell your ahead of time that I&#39;m a sloppy coder. I took about 20 minutes commenting several parts of my code to try and make it easier to understand, but I don&#39;t know if that was enough. I also realize that half of the code should be split up into several source files -- I&#39;m not very good about getting that to work for some reason (I don&#39;t know much about linking one source file to another), so I&#39;ve been holding off on that and working in one file for now.</p><p>I moved the blits out of the timer since that seemed to improve performance a thousand-fold anyway, and although the YVelocity works now, it still stops working under specific conditions:</p><p>- When I compile the source using the &quot;-pg&quot; option<br />- When the steel reinforcement object comes into view (you&#39;ll know when this happens because the player will glide on air)</p><p>In fact, you can use Object.exe to delete the steel-reinforcement object out of the level, and you&#39;ll see that the YVelocity suddenly works again.</p><p>Oh, and one final note -- when you load the engine, it will ask for what I call a &#39;prefix&#39;. Just type &quot;EHZ&quot; (without the quotes) and press enter. It should work just fine. Otherwise, it will give you an error saying files can&#39;t be found.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Damian Grove)</author>
		<pubDate>Wed, 08 Feb 2006 01:43:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I have download the whole thing and i&#39;m under testing.</p><p>EDIT: For sure it&#39;s strange, but it&#39;s <s>for sure</s> something inside the code !
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (GullRaDriel)</author>
		<pubDate>Wed, 08 Feb 2006 02:33:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I smell faulty dealing with memory (this would be my first guess), but I haven&#39;t looked at the code, so I can&#39;t tell for sure (obviously <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Indeterminatus)</author>
		<pubDate>Wed, 08 Feb 2006 02:59:28 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Anyone happen to have any ideas yet? I know Gull was under testing. I agree that it&#39;s probably a memory leak of some sort. I just wish I could figure out what I did wrong &gt;_&lt;
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Damian Grove)</author>
		<pubDate>Thu, 09 Feb 2006 08:00:58 +0000</pubDate>
	</item>
</rss>
