<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Deleting moved memory crashes</title>
		<link>http://www.allegro.cc/forums/view/601206</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sat, 22 Aug 2009 13:32:57 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><b>Original post updated</b> -- <b>2009/08/22</b></p><p>Thanks for the help so far all.  This is the current working version... sorry if only a few of you can compile it.  It compiles and runs on my Mac, at least.</p><p>I&#39;ve uploaded a more recent source code if anyone wants to check it out.  It now supports mouse control.</p><p>It doesn&#39;t take all of the parameters from &quot;config.xml&quot; yet like I want, and there are still several things hard-coded, but those things are being removed as I continue.</p><p>Please post feedback as you have them; I always welcome comments.</p><p><span class="source-code"><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span><span class="k3">=</span></span></p><p>I&#39;ve been trying to get that <a href="http://www.allegro.cc/forums/thread/600857">bubble</a> <a href="http://www.allegro.cc/forums/thread/601039">popping</a> game done for a while.</p><p>The version I have uploaded to this post isn&#39;t interactive yet, but it&#39;s not going to be very hard to actually implement a mouse (it may take less than a day to add support for that).</p><p>I tried compiling it on Windows, since I know the majority of you are on Windows, and I&#39;ll probably want my game to be Windows-based more than Mac-based, but for some reason, the <b>src/TimeKeeper.cpp</b> complains about DWORD not being defined when compiling with gcc unless I <span class="source-code"><span class="p">#include "winalleg.h"</span></span> right above line 34:
</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"> 30</span><span class="p">#  ifdef HAVE_SCHED_H</span>
<span class="number"> 31</span><span class="p">#    include &lt;sched.h&gt;</span>
<span class="number"> 32</span><span class="p">#  endif</span>
<span class="number"> 33</span><span class="p">#else // !defined(_WIN32)</span>
<span class="number"> 34</span><span class="p">#  include &lt;mmsystem.h&gt;</span>
<span class="number"> 35</span><span class="k1">static</span> <span class="k1">unsigned</span> <span class="k1">long</span> <span class="k1">int</span> lastTime <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span>
<span class="number"> 36</span><span class="k1">static</span> LARGE_INTEGER     qpcLastTime<span class="k2">;</span>
</div></div><p>

like this:</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"> 30</span><span class="p">#  ifdef HAVE_SCHED_H</span>
<span class="number"> 31</span><span class="p">#    include &lt;sched.h&gt;</span>
<span class="number"> 32</span><span class="p">#  endif</span>
<span class="number"> 33</span><span class="p">#else // !defined(_WIN32)</span>
<span class="number"> 34</span><span class="p">#  include &lt;winalleg.h&gt;</span>
<span class="number"> 35</span><span class="p">#  include &lt;mmsystem.h&gt;</span>
<span class="number"> 36</span><span class="k1">static</span> <span class="k1">unsigned</span> <span class="k1">long</span> <span class="k1">int</span> lastTime <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span>
<span class="number"> 37</span><span class="k1">static</span> LARGE_INTEGER     qpcLastTime<span class="k2">;</span>
</div></div><p>

and even then, I&#39;m still getting a few other compiling errors (but not as many).</p><p>Anyway, the problem I&#39;m facing is in Arena::~Arena().</p><p>Arena contains three <span class="source-code">std::list<span class="k3">&lt;</span>Ball<span class="k3">*</span><span class="k3">&gt;</span></span> lists.
</p><ul><li><p><b>pBalls</b> have infinite lifespans, unless they get popped.  They bonce around the screen freely.</p></li><li><p><b>pPoppedBalls</b> have about a 3-second lifespan, and pBalls can collide with them.  They are immobile (pBalls become pPoppedBalls themselves when they collide, and themselves become immobile)</p></li><li><p><b>pRemovedBalls</b> are removed from the arena completely, and no testing at all are done with them.  It would be the same thing if I were to free their memory as soon as they enter this group, but for efficiency reasons, deleting the memory is not done till the Arena is destroyed at the end.</p></li></ul><p>

To move the balls from one list to another, I locate the ball in question, then use the <span class="source-code">std::splice<span class="k2">(</span><span class="k2">)</span></span> command to transfer from one list to another.  I am STILL able to &quot;see&quot; all the balls in pBalls and pPoppedBalls through the lifetime of the game (I know, because they continue to pop each other and bounce around), so I know the pointers aren&#39;t invalidated.</p><p>However, when I go in and try to <b>delete</b> the memory within Arena::~Arena() on destruction, I am only able to do so on pBalls without causing a SEGFAULT.  If I try to do it on pPoppedBalls or pRemovedBalls, I get errors (I had to <span class="source-code"><span class="p">#if 0...#endif</span></span> those sections out).  This is bad, though, because this is a HUGE memory leak, and I intend on having multiple levels and rounds of gameplay (like if you hit &quot;R&quot;, you get to start a new round...</p><p>This compiles on my Mac without problem using the makefile, but if anyone else can take a look and give me some help, I&#39;d appreciate it.  Cookies!</p><p>P.S. If this looks like a fun project, and someone wants to help with <b>any</b> part of it (sounds, graphics, ... anything ...), I&#39;d love it!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (OnlineCop)</author>
		<pubDate>Mon, 10 Aug 2009 21:19:54 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m guessing that&#39;s because you only have one version of each Ball* obj created. When you move them from list to list you are only moving a pointer not the actual object. So when you try to delete the same obj more than once, that&#39;s where your segfault comes in.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Tomoso)</author>
		<pubDate>Mon, 10 Aug 2009 21:28:24 +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/601206/824857#target">Tomoso</a> said:</div><div class="quote"><p>When you move them from list to list you are only moving a pointer not the actual object.</p></div></div><p>
That&#39;s actually what I was intending to do.  Instead of doing an expensive move, I just want to reassign who &quot;owns&quot; the pointer so it can do all the updates.</p><p>pBalls.size() shows that there are the correct number of balls in it: 50, 25, 10, etc.  And pPoppedBalls.size() increases correctly.  When I&#39;m calling update(), the balls within pBalls are moving and the balls within pPoppedBalls are growing, shrinking, and being removed correctly, so I at least know that the pointers are going to the actual Ball* objects...</p><p>So am I actually trying to double-delete the same memory?</p><p>Also, when I try to delete the memory, I usually do this:
</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>std::list<span class="k3">&lt;</span>Ball<span class="k3">*</span><span class="k3">&gt;</span><span class="k2">:</span><span class="k2">:</span>iterator itr<span class="k2">;</span>
<span class="number">  2</span><span class="k1">for</span> <span class="k2">(</span>itr <span class="k3">=</span> pBalls.begin<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span> itr <span class="k3">!</span><span class="k3">=</span> pBalls.end<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span> <span class="k3">+</span><span class="k3">+</span>itr<span class="k2">)</span>
<span class="number">  3</span><span class="k2">{</span>
<span class="number">  4</span>  Ball<span class="k3">*</span> ball <span class="k3">=</span> <span class="k3">*</span>itr<span class="k2">;</span>
<span class="number">  5</span>  <span class="k1">if</span> <span class="k2">(</span>ball<span class="k2">)</span>
<span class="number">  6</span>  <span class="k2">{</span>
<span class="number">  7</span>    <span class="k1">delete</span> ball<span class="k2">;</span>
<span class="number">  8</span>    ball <span class="k3">=</span> NULL<span class="k2">;</span>
<span class="number">  9</span>  <span class="k2">}</span>
<span class="number"> 10</span><span class="k2">}</span>
<span class="number"> 11</span>
<span class="number"> 12</span><span class="k1">for</span> <span class="k2">(</span>itr <span class="k3">=</span> pPoppedBalls.begin<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span> itr <span class="k3">!</span><span class="k3">=</span> pPoppedBalls.end<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span> <span class="k3">+</span><span class="k3">+</span>itr<span class="k2">)</span>
<span class="number"> 13</span><span class="k2">{</span>
<span class="number"> 14</span>  Ball<span class="k3">*</span> ball <span class="k3">=</span> <span class="k3">*</span>itr<span class="k2">;</span>
<span class="number"> 15</span>  <span class="k1">if</span> <span class="k2">(</span>ball<span class="k2">)</span>
<span class="number"> 16</span>  <span class="k2">{</span>
<span class="number"> 17</span>    <span class="k1">delete</span> ball<span class="k2">;</span>
<span class="number"> 18</span>    ball <span class="k3">=</span> NULL<span class="k2">;</span>
<span class="number"> 19</span>  <span class="k2">}</span>
<span class="number"> 20</span><span class="k2">}</span>
</div></div><p>

So the memory should be freed and then it should be set to NULL, shouldn&#39;t it?  Then if the next loop (from within pPoppedBalls) gets to the same address, wouldn&#39;t it point to NULL instead of to an address?  Or has my logic failed me?</p><p>Should, instead of passing a <b>Ball*</b> around, I be passing the actual <b>Ball</b> object around?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (OnlineCop)</author>
		<pubDate>Mon, 10 Aug 2009 22:35:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If I&#39;m honest I&#39;ve never used <span class="source-code">std::list</span> I prefer vectors, since most of what I want to do doesn&#39;t matter if I can move back and forth or not at will. I also don&#39;t use iterators, again because I haven&#39;t found a use for them where I desperatley required one. </p><p>I use vectors like so below:</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="p">#include &lt;cstdlib&gt;</span>
<span class="number">  2</span><span class="p">#include &lt;iostream&gt;</span>
<span class="number">  3</span><span class="p">#include &lt;vector&gt;</span>
<span class="number">  4</span>
<span class="number">  5</span><span class="k1">using</span> <span class="k1">namespace</span> std<span class="k2">;</span>
<span class="number">  6</span>
<span class="number">  7</span><span class="k1">int</span> main<span class="k2">(</span><span class="k1">int</span> argc, <span class="k1">char</span> <span class="k3">*</span>argv<span class="k2">[</span><span class="k2">]</span><span class="k2">)</span>
<span class="number">  8</span><span class="k2">{</span>
<span class="number">  9</span>    vector<span class="k3">&lt;</span><span class="k1">int</span><span class="k3">*</span><span class="k3">&gt;</span> somevector<span class="k2">;</span>
<span class="number"> 10</span>    
<span class="number"> 11</span>    <span class="k1">int</span> <span class="k3">*</span>a <span class="k3">=</span> <span class="k1">new</span> <span class="k1">int</span><span class="k2">(</span><span class="n">10</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 12</span>    <span class="k1">int</span> <span class="k3">*</span>b <span class="k3">=</span> <span class="k1">new</span> <span class="k1">int</span><span class="k2">(</span><span class="n">20</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 13</span>    <span class="k1">int</span> <span class="k3">*</span>c <span class="k3">=</span> <span class="k1">new</span> <span class="k1">int</span><span class="k2">(</span><span class="n">30</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 14</span>    <span class="k1">int</span> <span class="k3">*</span>d <span class="k3">=</span> <span class="k1">new</span> <span class="k1">int</span><span class="k2">(</span><span class="n">40</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 15</span>    
<span class="number"> 16</span>    <span class="k1">int</span> <span class="k3">*</span>o <span class="k3">=</span> a<span class="k2">;</span>
<span class="number"> 17</span>    
<span class="number"> 18</span>    somevector.push_back<span class="k2">(</span>a<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 19</span>    somevector.push_back<span class="k2">(</span>b<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 20</span>    somevector.push_back<span class="k2">(</span>c<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 21</span>    somevector.push_back<span class="k2">(</span>d<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 22</span>    
<span class="number"> 23</span>    <span class="c">/* Remove *a from vector */</span>
<span class="number"> 24</span>    <span class="k1">for</span> <span class="k2">(</span><span class="k1">int</span> i <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> i <span class="k3">&lt;</span> somevector.size<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span> i<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 25</span>      <span class="k1">if</span> <span class="k2">(</span>somevector.at<span class="k2">(</span>i<span class="k2">)</span> <span class="k3">=</span><span class="k3">=</span> o<span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 26</span>        somevector.erase<span class="k2">(</span>somevector.begin<span class="k2">(</span><span class="k2">)</span> <span class="k3">+</span> i<span class="k2">)</span><span class="k2">;</span> <span class="c">/* Pointer only removed from vector */</span>
<span class="number"> 27</span>      <span class="k2">}</span>
<span class="number"> 28</span>    <span class="k2">}</span>
<span class="number"> 29</span>    
<span class="number"> 30</span>    <span class="c">/* Print vector */</span>
<span class="number"> 31</span>    cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"B, C, D"</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> endl<span class="k2">;</span>
<span class="number"> 32</span>    <span class="k1">for</span> <span class="k2">(</span><span class="k1">int</span> i <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> i <span class="k3">&lt;</span> somevector.size<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span> i<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 33</span>      cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="k3">*</span>somevector.at<span class="k2">(</span>i<span class="k2">)</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> endl<span class="k2">;</span>
<span class="number"> 34</span>    <span class="k2">}</span>
<span class="number"> 35</span>    
<span class="number"> 36</span>    <span class="c">/* Printe *a */</span>
<span class="number"> 37</span>    cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"A: "</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="k3">*</span>a <span class="k3">&lt;</span><span class="k3">&lt;</span> endl<span class="k2">;</span>
<span class="number"> 38</span>    
<span class="number"> 39</span>    <span class="c">/* Delete everything within vector */</span>
<span class="number"> 40</span>    <span class="k1">for</span> <span class="k2">(</span><span class="k1">int</span> i <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> i <span class="k3">&lt;</span> somevector.size<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span> i<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 41</span>        <span class="k1">delete</span> somevector.at<span class="k2">(</span>i<span class="k2">)</span><span class="k2">;</span>    <span class="c">/* Deletes the actual object but not the pointer within */</span>
<span class="number"> 42</span>        somevector.at<span class="k2">(</span>i<span class="k2">)</span> <span class="k3">=</span> NULL<span class="k2">;</span>    <span class="c">/* the vector */</span>
<span class="number"> 43</span>    <span class="k2">}</span>
<span class="number"> 44</span>    somevector.clear<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span> <span class="c">/* Clears all pointers within the vector */</span>
<span class="number"> 45</span>    
<span class="number"> 46</span>    cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"Vector Size: "</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> somevector.size<span class="k2">(</span><span class="k2">)</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> endl<span class="k2">;</span> <span class="c">/* Should be 0 */</span>
<span class="number"> 47</span>    
<span class="number"> 48</span>    <span class="k1">delete</span> a<span class="k2">;</span>
<span class="number"> 49</span>    
<span class="number"> 50</span>    <a href="http://www.delorie.com/djgpp/doc/libc/libc_802.html" target="_blank">system</a><span class="k2">(</span><span class="s">"PAUSE"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 51</span>    <span class="k1">return</span> EXIT_SUCCESS<span class="k2">;</span>
<span class="number"> 52</span><span class="k2">}</span>
</div></div><p>

ps, In my defense I might have made some errors in my haste, not garunteed to work!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Tomoso)</author>
		<pubDate>Mon, 10 Aug 2009 23:12:22 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The fallback case for Timekeeper::sleep seems to be on all the time.<br />Nothing is happening with it, but each ball contains an Arena pointer (that is invalidated after the first delete).<br />BTW what happened to <a href="http://www.allegro.cc/forums/thread/599614">other bubble popping game?</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (weapon_S)</author>
		<pubDate>Mon, 10 Aug 2009 23:14:31 +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/601206/824865#target">OnlineCop</a> said:</div><div class="quote"><p>
So the memory should be freed and then it should be set to NULL, shouldn&#39;t it? Then if the next loop (from within pPoppedBalls) gets to the same address, wouldn&#39;t it point to NULL instead of to an address? Or has my logic failed me?
</p></div></div><p>

From that description, yes, your logic has failed you. If you have a pointer to the same object in more than one list, then you are pretty much screwed. (Each list contains <i>a copy</i> of the pointer, setting one to NULL couldn&#39;t possible affect others.)</p><p>You&#39;d need something smarter, like reference-counted pointers (std::tr1::shared_ptr/boost::shared_ptr) which delete the shared object when the last shared_ptr to it goes out of scope.</p><p>Or you might store all the pointers in one list that you don&#39;t mess around with, and finally delete everything in that and not elsewhere.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (anonymous)</author>
		<pubDate>Tue, 11 Aug 2009 01:17:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><b>weapon_S</b>:
</p><ol><li><p>TimeKeeper::sleep is a poor substitute for allegro&#39;s <span class="source-code"><a href="http://www.allegro.cc/manual/rest" target="_blank"><span class="a">rest</span></a><span class="k2">(</span><span class="k2">)</span></span>.  I had actually started this project with &quot;correct&quot; allegro timing, using the examples off of the <a href="http://wiki.allegro.cc/index.php?title=Timers">allegro wiki</a> as a basis, but for some reason, didn&#39;t see any sort of difference in CPU usage.  Maybe the Mac&#39;s Activity Monitor just lies and it was working fine and I didn&#39;t know it.</p><p>The way that I implemented TimeKeeper::sleep() is to &quot;sleep&quot; based on how much time the game wants to give back to the CPU, depending on the framerate.  So if you play with the + and - keys on the keypad and push the framerate down to near zero, you&#39;ll notice that the amount of &quot;sleep&quot; time increases to almost a full second when FPS drops to 1 frame per second, and down to 1/200th of a second when FPS is 200 (give or take a little for some other processing).  It&#39;s probably a horrible way to do an allegro <span class="source-code"><a href="http://www.allegro.cc/manual/rest" target="_blank"><span class="a">rest</span></a><span class="k2">(</span><span class="k2">)</span></span> workaround, but I didn&#39;t really know what else to do for it.</p></li><li><p>I actually had the other bubble popping game compile well on my Mac, and it looked pretty decent for an early beta.  Then I uploaded it to the Linux lab for our professors to grade and it bombed when we tried to compile it and get it to show off my all-night last-minute feature additions.  So I felt badly and haven&#39;t looked at it again.  <b>*sigh*</b>  Maybe it needs a good revival.  We&#39;ll see.</p></li></ol><p>

EDIT 1:<br /><b>anonymous</b>: That approach might actually be the best way to go.  I can assign everything and stick it in a <span class="source-code">std::vector<span class="k3">&lt;</span>Ball<span class="k3">*</span><span class="k3">&gt;</span></span>.  Then, I&#39;ll point to everything with the various <span class="source-code">std::list<span class="k3">&lt;</span>Ball<span class="k3">*</span><span class="k3">&gt;</span></span> lists (I use lists because they get removed randomly and don&#39;t want to shuffle the memory around, which is what using <span class="source-code">std::vector<span class="k3">&lt;</span>Ball<span class="k3">*</span><span class="k3">&gt;</span></span> would be doing), and just free memory from the main vector in the <span class="source-code">Arena::~Arena<span class="k2">(</span><span class="k2">)</span></span>.  Is that correct?  That&#39;s actually a pretty good idea...</p><p>EDIT 2:<br /><b>anonymous</b>: Your solution works.  I tested it with no balls popped, a few balls popped, all balls popped, all balls popped and removed from the field, and restarting the game multiple times.  All balls&#39; destructors were called in order, and it shows that everything is being destroyed correctly.  Thanks for the simple solution.  I should update my OP with the new code so others can play with my code and make feature improvement suggestions!</p><p>EDIT 3:<br />I&#39;ve updated the attached zip file for the <b>original post</b>, if anyone is able to compile and run the program.  <b>anonymous</b>, were you able to compile the program, or were you just looking through the code?</p><p>It now supports mouse!  Score isn&#39;t implemented, and there&#39;s no way I&#39;m plunging into sound support at this point (I&#39;ve <b>never</b> been able to do sound, so if there are volunteers, you&#39;ll get 100% of the viewable space on any credits screen for your own logo under the &quot;sound&quot; section <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" /><img src="http://www.allegro.cc/forums/smileys/kiss.gif" alt=":-*" /><img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />), but take a look (for those who can).</p><p>And if anyone can help me get this so it will compile on Windows (and other platforms), I&#39;d love::) you too.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (OnlineCop)</author>
		<pubDate>Tue, 11 Aug 2009 09:57:24 +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/601206/824886#target">OnlineCop</a> said:</div><div class="quote"><p>
anonymous, were you able to compile the program, or were you just looking through the code?
</p></div></div><p>

I wasn&#39;t able to compile it (MinGW 4.4.1) and just read the description of your problem. (When I get a makefile, I&#39;m supposed to run make in that directory? - The damned thing didn&#39;t find &lt;allegro.h&gt; in the compiler&#39;s main include folder with all related errors.) When I tried with the IDE I got the DWORD error with older code, and errors concerning various missing string functions with the newer version (xml code) regardless how the control macros were set (missing str(n)casecmp with _XMLWINDOWS commented and missing _strnicmp etc otherwise).</p><p>But looking at the source, you seem to have a lot of faith in setting pointers to NULL <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /> E.g in destructors - this may only help you catch errors where you access an already deleted object (it&#39;s members will be NULL), as long as that memory doesn&#39;t happen to be occupied by some new object.</p><p>---</p><p>Ok, added the compiler&#39;s include path to the makefile. Now I get an error with:</p><div class="source-code snippet"><div class="inner"><pre><span class="c">//ball.h line 15:</span>
BallConstraints::BallConstraints<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>

<span class="c">//should be: BallConstraints();</span>
</pre></div></div><p>

Beyond that it is back to the errors with stricmp and such.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (anonymous)</author>
		<pubDate>Wed, 12 Aug 2009 01:09:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><b>anonymous</b>, when I tried on Windows, it said that I was missing winmm.lib, so I uploaded (to the original post) a version where the makefile defaults to Windows and links to winmm, if you have it.</p><p>Yes, you need to be in the same directory as the makefile to build.  From the command prompt, I usually do the following:
</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>cd prince_popper
<span class="number">  2</span>C:\some_dir\prince_popper&gt;make depend
<span class="number">  3</span>g<span class="k3">+</span><span class="k3">+</span> <span class="k3">-</span>MM <span class="k3">-</span>MG <span class="k3">-</span>I.<span class="k3">/</span>include .<span class="k3">/</span>src<span class="c">/*.cpp &gt; _depend.tmp</span>
<span class="number">  4</span><span class="c">sed -e "s/^\([a-zA-Z0-9_]*\)\.o:/./obj/\1\.o:/" _depend.tmp &gt; ./obj/makefile.dep</span>
<span class="number">  5</span><span class="c">rm -rf _depend.tmp</span>
<span class="number">  6</span><span class="c"></span>
<span class="number">  7</span><span class="c">C:\some_dir\prince_popper&gt;make</span>
<span class="number">  8</span><span class="c">g++ -o "obj/Arena.o" -c -W -Wall -Wno-unused -pg -g3 -ggdb3 -O0 -DDEBUG -I./include ./src/Arena.cpp</span>
<span class="number">  9</span><span class="c">g++ -o "obj/Ball.o" -c -W -Wall -Wno-unused -pg -g3 -ggdb3 -O0 -DDEBUG -I./include ./src/Ball.cpp</span>
<span class="number"> 10</span><span class="c">g++ -o "obj/BallKeyframe.o" -c -W -Wall -Wno-unused -pg -g3 -ggdb3 -O0 -DDEBUG -I./include ./src/BallKeyframe.cpp</span>
<span class="number"> 11</span><span class="c">g++ -o "obj/Game.o" -c -W -Wall -Wno-unused -pg -g3 -ggdb3 -O0 -DDEBUG -I./include ./src/Game.cpp</span>
<span class="number"> 12</span><span class="c">g++ -o "obj/Main.o" -c -W -Wall -Wno-unused -pg -g3 -ggdb3 -O0 -DDEBUG -I./include ./src/Main.cpp</span>
<span class="number"> 13</span><span class="c">g++ -o "obj/TimeKeeper.o" -c -W -Wall -Wno-unused -pg -g3 -ggdb3 -O0 -DDEBUG -I./include ./src/TimeKeeper.cpp</span>
<span class="number"> 14</span><span class="c">g++ -o "obj/Timer.o" -c -W -Wall -Wno-unused -pg -g3 -ggdb3 -O0 -DDEBUG -I./include ./src/Timer.cpp</span>
<span class="number"> 15</span><span class="c">g++ -o "obj/xmlParser.o" -c -W -Wall -Wno-unused -pg -g3 -ggdb3 -O0 -DDEBUG -I./include ./src/xmlParser.cpp</span>
<span class="number"> 16</span><span class="c">g++ -o "./bin/test" -W -Wall -g3 -ggdb3 -O0 -pg ./obj/Arena.o ./obj/Ball.o ./obj/BallKeyframe.o ./obj/Game.o ./obj/Main.o ./obj/TimeKeeper.o ./obj/Timer.o ./obj/xmlParser.o  -lalld -lwinmm</span>
<span class="number"> 17</span><span class="c"></span>
<span class="number"> 18</span><span class="c">C:\some_dir\prince_popper&gt;</span>
</div></div><p>

You&#39;ll need <b>sed</b> for the &quot;make depend&quot; part, <b>liballd.lib</b> and <b>libwinmm.lib</b> (or <b>liballd.a</b> and <b>libwinmm.a</b>, depending on how your system names library files) in your library path, and whatever dependencies stricmp was complaining about earlier.</p><p>Thanks about noting the problem with Ball.h&#39;s &quot;BallConstraints::BallConstraints();&quot;... why the compiler didn&#39;t yell at me, I don&#39;t know.  Thanks.</p><p>This now compiles and runs fine on my WinXP with no modifications.  Can anyone else test and try this version?  Again, attachment is on the OP.</p><p>Feedback welcome and appreciated!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (OnlineCop)</author>
		<pubDate>Wed, 12 Aug 2009 04:38:00 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Nice.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (TeamTerradactyl)</author>
		<pubDate>Wed, 19 Aug 2009 00:02:04 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Updated original attachment again.</p><p>I <i>really</i> would like to learn Events one of these days.  But for everyone (anyone?) interested in this project or thread, here are a few changes:</p><ul><li><p>Balls no longer constrained to just 30, 45, and 60-degree movement; now any angle between 30-60 degrees in any of the four quadrants is used.</p></li><li><p>Scores should now update correctly.</p></li><li><p>Everything is moving toward being more data-driven than hard-coded (even if it&#39;s not fully implemented, the framework is &quot;getting there&quot; to handle it).</p></li><li><p>FPS starts at a default of 30 instead of 200 now (can be upped to 200 and lowered to 1 with the keypad +/- keys).</p></li><li><p>All <span class="source-code"><span class="k1">float</span></span>s replaced with <span class="source-code"><span class="k1">double</span></span>s to reduce rounding errors.</p></li><li><p>Other changes.  I&#39;ve been working on this a while...  Should have kept a running log...</p></li></ul><p>

Comments on the current version always welcome, and if this DOES compile for others out there, let me know.</p><p>Controls: Left mouse click (you can only &quot;drop&quot; a ball onto a playing field once per round... the whole point of the game: maximize your score).</p><p><span class="source-code"><a href="http://www.allegro.cc/manual/key" target="_blank"><span class="a">key</span></a><span class="k2">[</span>KEY_R<span class="k2">]</span></span>: Reset field, play another round/level<br /><span class="source-code"><a href="http://www.allegro.cc/manual/key" target="_blank"><span class="a">key</span></a><span class="k2">[</span>KEY_P<span class="k2">]</span></span>: Debugging key for now: Pause gameplay (won&#39;t pause &quot;popped&quot; bubbles: can be a disadvantage)<br /><span class="source-code"><a href="http://www.allegro.cc/manual/key" target="_blank"><span class="a">key</span></a><span class="k2">[</span>KEY_U<span class="k2">]</span></span>: Debugging key for now: Unpause gameplay, unless a game is over<br /><span class="source-code"><a href="http://www.allegro.cc/manual/key" target="_blank"><span class="a">key</span></a><span class="k2">[</span>KEY_F<span class="k2">]</span></span>: Toggle between fullscreen and windowed mode<br /><span class="source-code"><a href="http://www.allegro.cc/manual/key" target="_blank"><span class="a">key</span></a><span class="k2">[</span>KEY_Q<span class="k2">]</span>, <a href="http://www.allegro.cc/manual/key" target="_blank"><span class="a">key</span></a><span class="k2">[</span>KEY_ESC<span class="k2">]</span></span>: quit the program</p><p>You can also use some command-line arguments to change a few of the settings.  Like the dimensions of the arena (a long narrow strip would make it very easy to win, hint-hint).  You can find those by reading through the source code yourself. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (OnlineCop)</author>
		<pubDate>Sat, 22 Aug 2009 13:32:57 +0000</pubDate>
	</item>
</rss>
