<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>A5 - Can someone figure out why this isn&#39;t working?</title>
		<link>http://www.allegro.cc/forums/view/607716</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Fri, 01 Jul 2011 01:21:15 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I have started to re-code Jump Pacman because the code got very very messy but now I can&#39;t even load an image without it crashing.</p><p>I have attached the entire project without the lib and include directory. (Setup using static libs Allegro 5.0.3)</p><p>Anyone have a clue to why this is happening.</p><p>This is where it seems to break.
</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 "menu.h"</span>
<span class="number">  2</span>
<span class="number">  3</span>Menu::Menu<span class="k2">(</span><span class="k2">)</span>
<span class="number">  4</span><span class="k2">{</span>
<span class="number">  5</span>    <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span> <span class="s">"Menu Started!\n"</span> <span class="k2">)</span><span class="k2">;</span>
<span class="number">  6</span>
<span class="number">  7</span>    game-&gt;gfx-&gt;Load<span class="k2">(</span> <span class="s">"gfx/menu_bg.png"</span> <span class="k2">)</span><span class="k2">;</span> <span class="c">// Crashes with this line.</span>
<span class="number">  8</span><span class="k2">}</span>
<span class="number">  9</span>
<span class="number"> 10</span>Menu::~Menu<span class="k2">(</span><span class="k2">)</span>
<span class="number"> 11</span><span class="k2">{</span>
<span class="number"> 12</span>    <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span> <span class="s">"Menu Stopped!\n"</span> <span class="k2">)</span><span class="k2">;</span>
<span class="number"> 13</span><span class="k2">}</span>
<span class="number"> 14</span>
<span class="number"> 15</span><span class="k1">void</span> Menu::Render<span class="k2">(</span><span class="k2">)</span>
<span class="number"> 16</span><span class="k2">{</span>
<span class="number"> 17</span>
<span class="number"> 18</span><span class="k2">}</span>
</div></div><p>

Hope someone can shed some light on this matter.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Desmond Taylor)</author>
		<pubDate>Wed, 29 Jun 2011 17:49:59 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The usual response is that relative path may not necessarily be where you think it is, i.e. to the executable. Are you checking for file not exists or if the bitmap creation failed?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Walker)</author>
		<pubDate>Wed, 29 Jun 2011 17:58:48 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I am to the archive and it loads that. I know for a fact that the image is in the correct place too. It just seems to crash when calling that function and I&#39;ve written the function that way many times before without error.</p><p>This is what the Load function does.</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="k1">int</span> Graphics::Load<span class="k2">(</span> <span class="k1">const</span> <span class="k1">char</span><span class="k3">*</span> filename <span class="k2">)</span>
<span class="number">  2</span><span class="k2">{</span>
<span class="number">  3</span>    <a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a><span class="k3">*</span> tmpBitmap <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_bitmap"><span class="a">al_load_bitmap</span></a><span class="k2">(</span> filename <span class="k2">)</span><span class="k2">;</span>
<span class="number">  4</span>    <span class="k1">if</span> <span class="k2">(</span> tmpBitmap <span class="k2">)</span>
<span class="number">  5</span>    <span class="k2">{</span>
<span class="number">  6</span>        this-&gt;bitmap.push_back<span class="k2">(</span> tmpBitmap <span class="k2">)</span><span class="k2">;</span>
<span class="number">  7</span>        <span class="k1">return</span> this-&gt;bitmap.size<span class="k2">(</span><span class="k2">)</span> <span class="k3">-</span> <span class="n">1</span><span class="k2">;</span>
<span class="number">  8</span>    <span class="k2">}</span>
<span class="number">  9</span>
<span class="number"> 10</span>    <span class="k1">return</span> <span class="k3">-</span><span class="n">1</span><span class="k2">;</span>
<span class="number"> 11</span><span class="k2">}</span>
</div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Desmond Taylor)</author>
		<pubDate>Wed, 29 Jun 2011 18:01:58 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>When I started using A5 recently I found I had difficulty loading stuff as well. Then I learned that A5 has a path-handling system using ALLEGRO_PATH objects. That seemed to solve my problems.</p><p>You first create an ALLEGRO_PATH object, then use al_get_standard_path() to get the full path of where your executable is, then you can use al_append_path_component() to go deeper into a directory structure and al_set_path_filename() to set the filename.</p><p>Then, to load a file, use al_path_cstr() to convert the contents of an ALLEGRO_PATH object into a string.</p><p>Even if this seems overly complicated, it would be good to learn because you can use al_get_standard_path() to get other path locations suitable for storing global data, accessible by all users, or current-user-specific data.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kris Asick)</author>
		<pubDate>Wed, 29 Jun 2011 18:18:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Did you actually create the game, gfx, and bitmap objects?</p><p>And there&#39;s no shame in using a debugger <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Wed, 29 Jun 2011 18:18:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>@Kris Asick,</p><p>I know that the path is correct :/ I took all of this from my one script version and re-coding it so that I know what&#39;s going on since I got lost in the original one.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607716/923056#target">torhu</a> said:</div><div class="quote"><p>
Did you actually create the game, gfx, and bitmap objects?
</p></div></div><p>

Yes, Convert the *.dat file to a *.zip file and extract it. You&#39;ll notice the images are in there. You can also use 7z to open it as it is.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
And there&#39;s no shame in using a debugger 
</p></div></div><p>

I would but I really have no clue on how to use it :/</p><p>Edit: I get this when I press F8.</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">#0 004B91C2  std::auto_ptr&lt;Graphics&gt;::operator-&gt;(this=0x0) (c:/mingw/bin/../lib/gcc/mingw32/4.5.2/include/c++/backward/auto_ptr.h:195)</span>
<span class="number"> 2</span><span class="p">#1 0040165E  Menu::Menu(this=0x8d8d858) (E:\Projects\Jump Pacman\src\menu.cpp:7)</span>
<span class="number"> 3</span><span class="p">#2 004018B2  Game::Game(this=0xa53a20) (E:\Projects\Jump Pacman\src\game.cpp:38)</span>
<span class="number"> 4</span><span class="p">#3 004015CC  main(argc=1, argv=0xa527d0) (E:\Projects\Jump Pacman\src\main.c:5)</span>
</div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Desmond Taylor)</author>
		<pubDate>Wed, 29 Jun 2011 18:37:30 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I was thinking about the objects in the code, not the data files.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Wed, 29 Jun 2011 18:50:25 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I don&#39;t get what you mean but I have been sat here trying to work some stuff out and I might have the auto_ptr&#39;s setup wrong.</p><p>game.h
</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">#ifndef __GAME_H_INCLUDED</span>
<span class="number">  2</span><span class="p">#define __GAME_H_INCLUDED</span>
<span class="number">  3</span>
<span class="number">  4</span><span class="p">#include "stdafx.h"</span>
<span class="number">  5</span>
<span class="number">  6</span><span class="k1">class</span> Game
<span class="number">  7</span><span class="k2">{</span>
<span class="number">  8</span>    public:
<span class="number">  9</span>        Game<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 10</span>        ~Game<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 11</span>
<span class="number"> 12</span>        <span class="k1">void</span> Run<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 13</span>        <span class="k1">void</span> UpdateEventSystem<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 14</span>        <span class="k1">void</span> Quit<span class="k2">(</span><span class="k2">)</span> <span class="k2">{</span> this-&gt;quit <span class="k3">=</span> <span class="k1">true</span><span class="k2">;</span> <span class="k2">}</span><span class="k2">;</span>
<span class="number"> 15</span>        <span class="k1">void</span> Clear<span class="k2">(</span> <span class="k1">int</span> r <span class="k3">=</span> <span class="n">0</span>, <span class="k1">int</span> g <span class="k3">=</span> <span class="n">0</span>, <span class="k1">int</span> b <span class="k3">=</span> <span class="n">0</span> <span class="k2">)</span><span class="k2">;</span>
<span class="number"> 16</span>        <span class="k1">void</span> Flip<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 17</span>
<span class="number"> 18</span>        <span class="k1">void</span> Error<span class="k2">(</span> <span class="k1">const</span> <span class="k1">char</span><span class="k3">*</span> format, ... <span class="k2">)</span><span class="k2">;</span>
<span class="number"> 19</span>
<div class="highlight"><span class="number"> 20</span>        std::auto_ptr<span class="k3">&lt;</span>Graphics&gt; gfx<span class="k2">;</span> </div><div class="highlight"><span class="number"> 21</span>        std::auto_ptr<span class="k3">&lt;</span>Menu&gt; menu<span class="k2">;</span> </div><span class="number"> 22</span>
<span class="number"> 23</span>    protected:
<span class="number"> 24</span>        <a href="http://www.allegro.cc/manual/ALLEGRO_DISPLAY"><span class="a">ALLEGRO_DISPLAY</span></a><span class="k3">*</span> display<span class="k2">;</span>
<span class="number"> 25</span>        <a href="http://www.allegro.cc/manual/ALLEGRO_TIMER"><span class="a">ALLEGRO_TIMER</span></a><span class="k3">*</span> timer<span class="k2">;</span>
<span class="number"> 26</span>        <a href="http://www.allegro.cc/manual/ALLEGRO_EVENT_QUEUE"><span class="a">ALLEGRO_EVENT_QUEUE</span></a><span class="k3">*</span> queue<span class="k2">;</span>
<span class="number"> 27</span>        <a href="http://www.allegro.cc/manual/ALLEGRO_EVENT"><span class="a">ALLEGRO_EVENT</span></a> event<span class="k2">;</span>
<span class="number"> 28</span>        GAME_STATE state<span class="k2">;</span>
<span class="number"> 29</span>        <span class="k1">bool</span> quit<span class="k2">;</span>
<span class="number"> 30</span>        <span class="k1">bool</span> ticked<span class="k2">;</span>
<span class="number"> 31</span><span class="k2">}</span><span class="k2">;</span>
<span class="number"> 32</span>
<span class="number"> 33</span><span class="k1">extern</span> std::auto_ptr<span class="k3">&lt;</span>Game&gt; game<span class="k2">;</span>
<span class="number"> 34</span>
<span class="number"> 35</span><span class="p">#endif // __GAME_H_INCLUDED</span>
</div></div><p>

game.cpp
</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>Game::Game<span class="k2">(</span><span class="k2">)</span>
<span class="number">  2</span><span class="k2">{</span>
<span class="number">  3</span>    <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span> <span class="s">"Game Started!\n"</span> <span class="k2">)</span><span class="k2">;</span>
<span class="number">  4</span>
<span class="number">  5</span>    <span class="k1">if</span> <span class="k2">(</span> <span class="k3">!</span><a href="http://www.allegro.cc/manual/al_init"><span class="a">al_init</span></a><span class="k2">(</span><span class="k2">)</span> <span class="k2">)</span>
<span class="number">  6</span>        this-&gt;Error<span class="k2">(</span> <span class="s">"Error initializing Allegro."</span> <span class="k2">)</span><span class="k2">;</span>
<span class="number">  7</span>
<span class="number">  8</span>    this-&gt;display <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_display"><span class="a">al_create_display</span></a><span class="k2">(</span> <span class="n">640</span>, <span class="n">480</span> <span class="k2">)</span><span class="k2">;</span>
<span class="number">  9</span>    <span class="k1">if</span> <span class="k2">(</span> <span class="k3">!</span>this-&gt;display <span class="k2">)</span>
<span class="number"> 10</span>        this-&gt;Error<span class="k2">(</span> <span class="s">"Error creating the display."</span> <span class="k2">)</span><span class="k2">;</span>
<span class="number"> 11</span>
<span class="number"> 12</span>    <a href="http://www.allegro.cc/manual/al_set_window_title"><span class="a">al_set_window_title</span></a><span class="k2">(</span> this-&gt;display, <span class="s">"Jump Pacman"</span> <span class="k2">)</span><span class="k2">;</span>
<span class="number"> 13</span>
<span class="number"> 14</span>    this-&gt;timer <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_timer"><span class="a">al_create_timer</span></a><span class="k2">(</span> <a href="http://www.allegro.cc/manual/ALLEGRO_BPS_TO_SECS"><span class="a">ALLEGRO_BPS_TO_SECS</span></a><span class="k2">(</span> <span class="n">60</span> <span class="k2">)</span> <span class="k2">)</span><span class="k2">;</span>
<span class="number"> 15</span>    <span class="k1">if</span> <span class="k2">(</span> <span class="k3">!</span>this-&gt;timer <span class="k2">)</span>
<span class="number"> 16</span>        this-&gt;Error<span class="k2">(</span> <span class="s">"Error creating timer."</span> <span class="k2">)</span><span class="k2">;</span>
<span class="number"> 17</span>
<span class="number"> 18</span>    this-&gt;queue <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_event_queue"><span class="a">al_create_event_queue</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 19</span>    <span class="k1">if</span> <span class="k2">(</span> <span class="k3">!</span>this-&gt;queue <span class="k2">)</span>
<span class="number"> 20</span>        this-&gt;Error<span class="k2">(</span> <span class="s">"Error creating event queue."</span> <span class="k2">)</span><span class="k2">;</span>
<span class="number"> 21</span>
<span class="number"> 22</span>    <a href="http://www.allegro.cc/manual/al_register_event_source"><span class="a">al_register_event_source</span></a><span class="k2">(</span> this-&gt;queue, <a href="http://www.allegro.cc/manual/al_get_display_event_source"><span class="a">al_get_display_event_source</span></a><span class="k2">(</span> this-&gt;display <span class="k2">)</span> <span class="k2">)</span><span class="k2">;</span>
<span class="number"> 23</span>    <a href="http://www.allegro.cc/manual/al_register_event_source"><span class="a">al_register_event_source</span></a><span class="k2">(</span> this-&gt;queue, <a href="http://www.allegro.cc/manual/al_get_timer_event_source"><span class="a">al_get_timer_event_source</span></a><span class="k2">(</span> this-&gt;timer <span class="k2">)</span> <span class="k2">)</span><span class="k2">;</span>
<span class="number"> 24</span>
<span class="number"> 25</span>    <a href="http://www.allegro.cc/manual/al_set_physfs_file_interface"><span class="a">al_set_physfs_file_interface</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 26</span>
<span class="number"> 27</span>    <span class="k1">if</span> <span class="k2">(</span> <span class="k3">!</span>PHYSFS_init<span class="k2">(</span> NULL <span class="k2">)</span> <span class="k2">)</span>
<span class="number"> 28</span>        this-&gt;Error<span class="k2">(</span> <span class="s">"Error with PHYSFS_init()."</span> <span class="k2">)</span><span class="k2">;</span>
<span class="number"> 29</span>
<span class="number"> 30</span>    <span class="k1">if</span> <span class="k2">(</span> <span class="k3">!</span>PHYSFS_addToSearchPath<span class="k2">(</span> <span class="s">"data.dat"</span>, <span class="n">0</span> <span class="k2">)</span> <span class="k2">)</span>
<span class="number"> 31</span>        this-&gt;Error<span class="k2">(</span> <span class="s">"Error with PHYSFS_addToSearchPath()."</span> <span class="k2">)</span><span class="k2">;</span>
<span class="number"> 32</span>
<div class="highlight"><span class="number"> 33</span>    this-&gt;gfx <span class="k3">=</span> std::auto_ptr<span class="k3">&lt;</span>Graphics&gt;<span class="k2">(</span> <span class="k1">new</span> Graphics <span class="k2">)</span><span class="k2">;</span> </div><div class="highlight"><span class="number"> 34</span>    this-&gt;menu <span class="k3">=</span> std::auto_ptr<span class="k3">&lt;</span>Menu&gt;<span class="k2">(</span> <span class="k1">new</span> Menu <span class="k2">)</span><span class="k2">;</span> </div><span class="number"> 35</span>
<span class="number"> 36</span>    <a href="http://www.allegro.cc/manual/al_start_timer"><span class="a">al_start_timer</span></a><span class="k2">(</span> this-&gt;timer <span class="k2">)</span><span class="k2">;</span>
<span class="number"> 37</span>
<span class="number"> 38</span>    this-&gt;state <span class="k3">=</span> GAME_STATE_MENU<span class="k2">;</span>
<span class="number"> 39</span>    this-&gt;quit <span class="k3">=</span> <span class="k1">false</span><span class="k2">;</span>
<span class="number"> 40</span>    this-&gt;ticked <span class="k3">=</span> <span class="k1">true</span><span class="k2">;</span>
<span class="number"> 41</span><span class="k2">}</span>
</div></div><p>

That&#39;s where it is declared and then initialized.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Desmond Taylor)</author>
		<pubDate>Wed, 29 Jun 2011 18:57:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Oh... you&#39;re using PHYSFS... That would&#39;ve been helpful to know ahead of time. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" /></p><p>I took a look at your entire codebase... I know this sounds trivial, but try changing your vector definition in graphics.h to this:</p><p><span class="source-code">std::vector<span class="k3">&lt;</span><span class="k2">(</span><a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a><span class="k3">*</span><span class="k2">)</span><span class="k3">&gt;</span> bitmap<span class="k2">;</span></span></p><p>Dunno if this will help but I seem to recall having issues using pointers and vectors in the past.</p><p>Beyond that, it would help to know exactly which line of Graphics::Load() is crashing the program, whether it&#39;s the actual Allegro load itself or your vector handling commands afterwards.</p><p><b>EDIT:</b> Oh, and I&#39;ve never used auto_ptr objects so if that&#39;s where the problem is then I wouldn&#39;t&#39;ve had a clue. <img src="http://www.allegro.cc/forums/smileys/rolleyes.gif" alt="::)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kris Asick)</author>
		<pubDate>Wed, 29 Jun 2011 18:59:28 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I just tried that and still the same error. :/</p><p>Edit: I was given information on how to use auto_ptr within a class before and can be read on these forums <span class="ref"><sup>[<a href="#">1</a>]</sup></span>. However, I have done it correctly according to that :/</p><p>I&#39;m going to check this by not using auto_ptr and just allocate it myself to see if it gets rid of the error.
</p><div class="ref-block"><h2>References</h2><ol><li><a href="http://www.allegro.cc/forums/thread/607644">http://www.allegro.cc/forums/thread/607644</a></li></ol></div></div>]]>
		</description>
		<author>no-reply@allegro.cc (Desmond Taylor)</author>
		<pubDate>Wed, 29 Jun 2011 19:01:55 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Though... why are you using auto_ptr objects? Just to get around cleanup code? Couldn&#39;t you just use &quot;new&quot; and &quot;delete&quot; commands as usual?</p><p><span class="source-code">gfx <span class="k3">=</span> <span class="k1">new</span> Graphics<span class="k2">;</span></span></p><p>and in Game::~Game():</p><p><span class="source-code"><span class="k1">delete</span> gfx<span class="k2">;</span></span></p><p>I dunno, that just seems simpler to me, and then it would be far more obvious when and where these objects would be created and destroyed.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kris Asick)</author>
		<pubDate>Wed, 29 Jun 2011 19:10:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Funny enough, I just edited my last post saying that I am going to see if that fixes my problem.</p><p><b>EDIT:</b> No that didn&#39;t fix the error meaning I defiantly set that up correctly. I am now out of ideas on what it causing this.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Desmond Taylor)</author>
		<pubDate>Wed, 29 Jun 2011 19:12:27 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Are you absolutely sure that Allegro is initialised before you try to call any Allegro functions? There are no global variables anywhere with constructors that that call Allegro functions?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Wed, 29 Jun 2011 19:22: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/607716/923067#target">Evert</a> said:</div><div class="quote"><p>
Are you absolutely sure that Allegro is initialised before you try to call any Allegro functions? There are no global variables anywhere with constructors that that call Allegro functions?
</p></div></div><p>

Taken from game.cpp
</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 "game.h"</span>
<span class="number">  2</span>
<span class="number">  3</span>std::auto_ptr<span class="k3">&lt;</span>Game&gt; game<span class="k2">;</span>
<span class="number">  4</span>
<span class="number">  5</span>Game::Game<span class="k2">(</span><span class="k2">)</span>
<span class="number">  6</span><span class="k2">{</span>
<span class="number">  7</span>    <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span> <span class="s">"Game Started!\n"</span> <span class="k2">)</span><span class="k2">;</span>
<span class="number">  8</span>
<div class="highlight"><span class="number">  9</span>    <span class="k1">if</span> <span class="k2">(</span> <span class="k3">!</span><a href="http://www.allegro.cc/manual/al_init"><span class="a">al_init</span></a><span class="k2">(</span><span class="k2">)</span> <span class="k2">)</span> </div><span class="number"> 10</span>        this-&gt;Error<span class="k2">(</span> <span class="s">"Error initializing Allegro."</span> <span class="k2">)</span><span class="k2">;</span>
<span class="number"> 11</span>
<span class="number"> 12</span>    this-&gt;display <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_display"><span class="a">al_create_display</span></a><span class="k2">(</span> <span class="n">640</span>, <span class="n">480</span> <span class="k2">)</span><span class="k2">;</span>
<span class="number"> 13</span>    <span class="k1">if</span> <span class="k2">(</span> <span class="k3">!</span>this-&gt;display <span class="k2">)</span>
<span class="number"> 14</span>        this-&gt;Error<span class="k2">(</span> <span class="s">"Error creating the display."</span> <span class="k2">)</span><span class="k2">;</span>
</div></div><p>

This is the first class that is initialized and that initializes Allegro so there is no chance of that happening :/ If I comment out the contents of Graphics::Load() so it only returns -1 then it still gives the error. I don&#39;t think it is to do with allegro :/</p><p>Graphics is initialized after Game but before Menu so it&#39;s defiantly all initialized first.</p><p>I will edit this with an attachment to an executable.</p><p><b>Edit:</b> Added the <a href="http://www.allegro.cc/files/attachment/604411">attachment</a>.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Desmond Taylor)</author>
		<pubDate>Wed, 29 Jun 2011 19:26:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I think I know what the problem is, and the fact it&#39;s letting you compile and link with this going on is... weird.</p><p>Basically, your &quot;game&quot; object should NOT be accessible from menu.cpp.</p><p>Try this:</p><p>1. Remove the following line from menu.cpp:<br /><span class="source-code">game-&gt;gfx-&gt;Load<span class="k2">(</span><span class="s">"gfx/menu_bg.png"</span><span class="k2">)</span><span class="k2">;</span></span></p><p>2. Add the following line after creating your new gfx object in game.cpp:<br /><span class="source-code">this-&gt;gfx-&gt;Load<span class="k2">(</span><span class="s">"gfx/menu_bg.png"</span><span class="k2">)</span><span class="k2">;</span></span>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kris Asick)</author>
		<pubDate>Wed, 29 Jun 2011 19:40:58 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>But I wan&#39;t it to load from menu.cpp like when I get to player I wan&#39;t player.cpp to load the player images.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Desmond Taylor)</author>
		<pubDate>Wed, 29 Jun 2011 19:45:26 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Can you single step through and into your code and see what might be happening, e.g. the objects are null as mentioned, etc.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Walker)</author>
		<pubDate>Wed, 29 Jun 2011 19:57:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If you want to load your graphics from your menu routine, then your menu routine needs to be made completely aware of your graphics object.</p><p>Try this:</p><p><b>game.cpp</b>
</p><div class="source-code snippet"><div class="inner"><pre>this-&gt;gfx <span class="k3">=</span> std::auto_ptr<span class="k3">&lt;</span>Graphics&gt;<span class="k2">(</span> <span class="k1">new</span> Graphics <span class="k2">)</span><span class="k2">;</span>
this-&gt;menu <span class="k3">=</span> std::auto_ptr<span class="k3">&lt;</span>Menu&gt;<span class="k2">(</span> <span class="k1">new</span> Menu <span class="k2">)</span><span class="k2">;</span>
this-&gt;menu-&gt;loadgfx<span class="k2">(</span>this-&gt;gfx<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

<b>menu.cpp</b>
</p><div class="source-code snippet"><div class="inner"><pre><span class="p">#include "menu.h"</span>
<span class="p">#include "graphics.h"</span>

Menu::Menu<span class="k2">(</span><span class="k2">)</span>
<span class="k2">{</span>
  <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span> <span class="s">"Menu Started!\n"</span> <span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span>

<span class="k1">int</span> Menu::loadgfx <span class="k2">(</span>Graphics <span class="k3">*</span>gfx<span class="k2">)</span>
<span class="k2">{</span>
  <span class="k1">return</span> gfx-&gt;Load<span class="k2">(</span> <span class="s">"gfx/menu_bg.png"</span> <span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>

I&#39;m in a rush now and don&#39;t have you code in front of me anymore, but I think you can get the idea. Menu doesn&#39;t have direct access to your game object which explains why the pointer value is 0x0 when inside your menu routine.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kris Asick)</author>
		<pubDate>Wed, 29 Jun 2011 20:06:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I could just do that and pass the gfx pointer into <br />this-&gt;menu = std::auto_ptr&lt;Menu&gt;( new Menu( this-&gt;gfx ) );</p><p>or <br />this-&gt;menu = std::auto_ptr&lt;Menu&gt;( new Menu( this ) ); because I need to get input when I set that class up too xD</p><p>Edit: I don&#39;t know how to step though the code as I don&#39;t know how to use the debugger.</p><p>Edit 2: I am going with passing a pointer to the class constructor and storing a pointer to it.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Desmond Taylor)</author>
		<pubDate>Wed, 29 Jun 2011 20:11:04 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I think you forgot to call <span class="source-code"><a href="http://www.allegro.cc/manual/al_init_image_addon"><span class="a">al_init_image_addon</span></a></span> before you tried to load your graphics. I don&#39;t see it in your Game constructor anywhere. Nevermind, I see it in your Graphics constructor now...</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607716/923060#target">Desmond Taylor</a> said:</div><div class="quote"><p>
</p><div class="source-code snippet"><div class="inner"><pre><span class="p">#0 004B91C2  std::auto_ptr&lt;Graphics&gt;::operator-&gt;(this=0x0) (c:/mingw/bin/../lib/gcc/mingw32/4.5.2/include/c++/backward/auto_ptr.h:195)</span>
<span class="p">#1 0040165E  Menu::Menu(this=0x8d8d858) (E:\Projects\Jump Pacman\src\menu.cpp:7)</span>
<span class="p">#2 004018B2  Game::Game(this=0xa53a20) (E:\Projects\Jump Pacman\src\game.cpp:38)</span>
<span class="p">#3 004015CC  main(argc=1, argv=0xa527d0) (E:\Projects\Jump Pacman\src\main.c:5)</span>
</pre></div></div><p>
</p></div></div><p>

See the part in frame #0 where it says &#39;this = 0x0&#39;. You&#39;re trying to dereference a null pointer somehow. I don&#39;t know how the address of the auto_ptr got to be null though.</p><p>I see what you did.</p><p>src\game.h line 33 :
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">extern</span> std::auto_ptr<span class="k3">&lt;</span>Game&gt; game<span class="k2">;</span>
</pre></div></div><p>

src\game.cpp line 3 :
</p><div class="source-code snippet"><div class="inner"><pre>std::auto_ptr<span class="k3">&lt;</span>Game&gt; game<span class="k2">;</span>
</pre></div></div><p>

src\main.c line 5 :
</p><div class="source-code snippet"><div class="inner"><pre>    std::auto_ptr<span class="k3">&lt;</span>Game&gt; game<span class="k2">(</span> <span class="k1">new</span> Game <span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

If you had turned on all of your compiler warnings, you would have noticed this :<br /><i>src\main.c:5:29: warning: declaration of &#39;game&#39; shadows a global declaration</i><br />(With gcc/MinGW use -Wall and -Wshadow)</p><p>So the reason the Menu constructor is crashing is because it uses the global &#39;game&#39; variable, which has been initialized by the default auto_ptr constructor, which is unable to guess where your object is located, which is why it was trying to dereference a null pointer.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Thu, 30 Jun 2011 10:30:04 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><img src="http://www.allegro.cc/forums/smileys/cheesy.gif" alt=";D" border="0" />, Stupid me. I shall turn on all compiler warnings now. I have a banging headache at the moment so when the paracetamol kicks in I shall work on it.</p><p>Thanks
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Desmond Taylor)</author>
		<pubDate>Thu, 30 Jun 2011 11:51:47 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If you don&#39;t know how to use the debugger, I suggest you do it now before you go any further down your programming path.</p><p>You mentioned pressing F8, are you using Visual Studio Express 2005?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Walker)</author>
		<pubDate>Thu, 30 Jun 2011 15:36:00 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Nope, Code::Blocks 10.05
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Desmond Taylor)</author>
		<pubDate>Thu, 30 Jun 2011 20:29:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;ve never used code blocks but given it&#39;s just a front end to mingw you enable the debugging symbols and hopefully c::b includes the debuger. </p><p>A quick google says go to the compiler options and tick the box &#39;produce debugging symbols&#39;, then everything else is done via the debug menu like start/stop/jump over/jump in (probably keypresses if you look closely enough in the menu).</p><p>That&#39;ll get you started in your code (allegro will still be out of bounds as far as drilling down, but most of the time you don&#39;t need to anyway). Couldn&#39;t be simpler <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Walker)</author>
		<pubDate>Thu, 30 Jun 2011 22:15:30 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks Neil <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><p>Sorry I didn&#39;t reply back so fast I was busy with animating the menu. It looks more like The Simpson&#39;s now.</p><p><span class="remote-thumbnail"><span class="json">{"name":"604415","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/6\/9\/69fb4283685592832ffb2b55f6c0fa22.png","w":640,"h":480,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/6\/9\/69fb4283685592832ffb2b55f6c0fa22"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/6/9/69fb4283685592832ffb2b55f6c0fa22-240.jpg" alt="604415" width="240" height="180" /></span>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Desmond Taylor)</author>
		<pubDate>Fri, 01 Jul 2011 01:21:15 +0000</pubDate>
	</item>
</rss>
