<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Crash mit boost::ptr_vector]]></title><description><![CDATA[<pre><code class="language-cpp">class NLRenderManager
{
   typedef boost::ptr_vector&lt;NLAnimation*&gt; NLAnimationList;

   //.........
}

void NLRenderManager::onRender(const u32 delta)
{
   //...............
	for ( size_t i = 0; i &lt; m_animationList.size(); i++ )
	{
		NLAnimation* obj = m_animationList[i];
		obj-&gt;renderObject();  // &lt;- crasht hier
		obj-&gt;update(delta);
	}
}
</code></pre>
<p>Selber Code mit std::vector funktioniert tadellos.</p>
<blockquote>
<p>First-chance exception at 0x655f3cb5 (NightLightDLL-d.dll) in NLSandbox-d.exe: 0xC0000005: Access violation reading location 0x46e8f43f.<br />
Unhandled exception at 0x655f3cb5 (NightLightDLL-d.dll) in NLSandbox-d.exe: 0xC0000005: Access violation reading location 0x46e8f43f.</p>
</blockquote>
<p>Wie man am Bild sieht, scheint auch der Member m_frame nicht mehr vorhanden zu sein... bzw der Speicher dazu fehlt.<br />
<a href="http://img340.imageshack.us/img340/1463/debugger.jpg" rel="nofollow">http://img340.imageshack.us/img340/1463/debugger.jpg</a><br />
rya.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/274147/crash-mit-boost-ptr_vector</link><generator>RSS for Node</generator><lastBuildDate>Thu, 27 Aug 2026 19:04:54 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/274147.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 20 Sep 2010 18:27:42 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Crash mit boost::ptr_vector on Mon, 20 Sep 2010 18:27:42 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">class NLRenderManager
{
   typedef boost::ptr_vector&lt;NLAnimation*&gt; NLAnimationList;

   //.........
}

void NLRenderManager::onRender(const u32 delta)
{
   //...............
	for ( size_t i = 0; i &lt; m_animationList.size(); i++ )
	{
		NLAnimation* obj = m_animationList[i];
		obj-&gt;renderObject();  // &lt;- crasht hier
		obj-&gt;update(delta);
	}
}
</code></pre>
<p>Selber Code mit std::vector funktioniert tadellos.</p>
<blockquote>
<p>First-chance exception at 0x655f3cb5 (NightLightDLL-d.dll) in NLSandbox-d.exe: 0xC0000005: Access violation reading location 0x46e8f43f.<br />
Unhandled exception at 0x655f3cb5 (NightLightDLL-d.dll) in NLSandbox-d.exe: 0xC0000005: Access violation reading location 0x46e8f43f.</p>
</blockquote>
<p>Wie man am Bild sieht, scheint auch der Member m_frame nicht mehr vorhanden zu sein... bzw der Speicher dazu fehlt.<br />
<a href="http://img340.imageshack.us/img340/1463/debugger.jpg" rel="nofollow">http://img340.imageshack.us/img340/1463/debugger.jpg</a><br />
rya.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1954956</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1954956</guid><dc:creator><![CDATA[[[global:former_user]]]]></dc:creator><pubDate>Mon, 20 Sep 2010 18:27:42 GMT</pubDate></item><item><title><![CDATA[Reply to Crash mit boost::ptr_vector on Mon, 20 Sep 2010 18:43:58 GMT]]></title><description><![CDATA[<p>Naja, ein pointer_vector auf Pointer ist nicht wirklich sinnvoll. Muss du hier wirklich einen vector von Pointern auf Pointer speichern?</p>
<p>Phil</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1954963</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1954963</guid><dc:creator><![CDATA[PhilippM]]></dc:creator><pubDate>Mon, 20 Sep 2010 18:43:58 GMT</pubDate></item><item><title><![CDATA[Reply to Crash mit boost::ptr_vector on Mon, 20 Sep 2010 18:45:16 GMT]]></title><description><![CDATA[<p>Meiner Meinung nach sollte es <code>boost::ptr_vector&lt;NLAnimation&gt;</code> heißen. Als Template-Argument verwendest du dann den Datentyp selbst und nicht einen Zeiger darauf - die Elemente von ptr_vector sind dann Zeiger auf Objekte diesen Typs (und nicht Zeiger auf Zeiger auf Objekte). Wo wäre sonst der Unterschied zu <code>boost::vector&lt;NLAnimation*&gt;</code> ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1954964</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1954964</guid><dc:creator><![CDATA[~~eddi~~]]></dc:creator><pubDate>Mon, 20 Sep 2010 18:45:16 GMT</pubDate></item><item><title><![CDATA[Reply to Crash mit boost::ptr_vector on Mon, 20 Sep 2010 18:46:04 GMT]]></title><description><![CDATA[<p>Ich habe den Eindruck, dass es da einige Missverständnisse Deinerseits gibt. Lies Dir nochmal durch, wozu boost::ptr_vector gut ist und wie man ihn benutzt. Ich finde es auch komisch, dass Du std::vector&lt;T*&gt; mit boost::ptr_vector&lt;T*&gt; vergleichst.</p>
<p>Zeig dochmal, wie Du den Vektor füllst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1954965</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1954965</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Mon, 20 Sep 2010 18:46:04 GMT</pubDate></item><item><title><![CDATA[Reply to Crash mit boost::ptr_vector on Mon, 20 Sep 2010 18:53:27 GMT]]></title><description><![CDATA[<p>Okay, also so geht es:</p>
<pre><code class="language-cpp">class NLRenderManager
{
   typedef boost::ptr_vector&lt;NLAnimation&gt; NLAnimationList;

   //.........
}

void NLRenderManager::onRender(const u32 delta)
{
   //...............
    for ( size_t i = 0; i &lt; m_animationList.size(); i++ )
    {
        NLAnimation&amp; obj = m_animationList[i];
        obj.renderObject(); 
        obj.update(delta);
    }
}
</code></pre>
<p>Die Doku gibt leider zu der Klasse nicht viel her. Deswegen war ich hier etwas verwirrt.</p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/8090">@KK</a><br />
Gefüllt wird der Vector mit Zeigern auf Objekte die auf dem Heap liegen, also mit new erzeugt wurden. Ich habe dazu in ##c++ auf freenode gefragt, was mir hier helfen könnte, dass ich die ganzen objekte nicht ständig beim zerstören mit delete durchlaufen muss. Das ist so gewollt, da die Klasse NLRenderManager den Besitz dieser Objekte übernimmt. Ich dachte erst an auto_ptr aber die gehen ja nicht in vector. Mir wurde dann ptr_vector empfohlen, da dieser genau dieses Verhalten hat.<br />
So meine Idee und Überlegung.<br />
rya.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1954970</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1954970</guid><dc:creator><![CDATA[[[global:former_user]]]]></dc:creator><pubDate>Mon, 20 Sep 2010 18:53:27 GMT</pubDate></item><item><title><![CDATA[Reply to Crash mit boost::ptr_vector on Mon, 20 Sep 2010 19:23:35 GMT]]></title><description><![CDATA[<p>Scorcher24 schrieb:</p>
<blockquote>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/8090">@KK</a><br />
Gefüllt wird der Vector mit Zeigern auf Objekte</p>
</blockquote>
<p>Das ist mir zu ungenau. Es beantwortet meine Frage nicht. Aber Dein Problem hat sich ja anscheinend erledigt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1954980</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1954980</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Mon, 20 Sep 2010 19:23:35 GMT</pubDate></item><item><title><![CDATA[Reply to Crash mit boost::ptr_vector on Mon, 20 Sep 2010 19:36:58 GMT]]></title><description><![CDATA[<p>krümelkacker schrieb:</p>
<blockquote>
<p>Scorcher24 schrieb:</p>
<blockquote>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/8090">@KK</a><br />
Gefüllt wird der Vector mit Zeigern auf Objekte</p>
</blockquote>
<p>Das ist mir zu ungenau. Es beantwortet meine Frage nicht. Aber Dein Problem hat sich ja anscheinend erledigt.</p>
</blockquote>
<p>Das Problem ja, aber was genau möchtest Du denn wissen?<br />
Ein Anwendungsbeispiel:</p>
<pre><code class="language-cpp">// ----------------------------------------
	// Create Animation
	// ---------------------------------------- 
	NLAnimation* anim = new NLAnimation(&quot;Munchkin&quot;);
	for ( int i = 1; i &lt;= 4; i ++ )
	{
		std::stringstream framename;
		framename &lt;&lt; &quot;Frame&quot; &lt;&lt; i;

		std::stringstream texname;
		texname &lt;&lt; &quot;f&quot; &lt;&lt; i;

		NLAnimationFrame* f = new NLAnimationFrame(i, NLVector2f(300.0f,300.0f), NLVector2f(100.0f,100.0f), NLVector2f(0.0f,0.0f), NLLayerConstants::MAP_DETAIL, framename.str().c_str());
		f-&gt;setTexture(g_resGrp, texname.str().c_str());
		f-&gt;setBlending(true);
		anim-&gt;addFrame(f);
	}
    anim-&gt;setAnimationFps(4);
    anim-&gt;startAnimation();
	renderMgr.add(anim);
</code></pre>
<p>.add fügt die Animation über push_back hinzu.... oder auch:</p>
<pre><code class="language-cpp">NLQuad* background = new NLQuad(SystemController().getWindow().getSettings().getSizef(), 
									NLVector2f(0.0f,0.0f), NLVector2f(0.0f,0.0f), NLLayerConstants::BACKGROUND, &quot;Background&quot;);
    background-&gt;setTexture(g_resGrp, &quot;Background&quot;);
    background-&gt;setBlending(false);
    renderMgr.add(background);
</code></pre>
<p>Beantwortet das die Frage? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /><br />
Ansonsten formulier sie doch bitte anders.. steh iwie aufm Schlauch.</p>
<p>edit:<br />
Aber in der Doku steht:<br />
The most important aspect of a pointer container is that it manages memory for you. This means that you in most cases do not need to worry about deleting memory.<br />
<a href="http://www.boost.org/doc/libs/1_33_1/libs/ptr_container/doc/tutorial.html" rel="nofollow">http://www.boost.org/doc/libs/1_33_1/libs/ptr_container/doc/tutorial.html</a><br />
Und genau das ist doch, was ich möchte...<br />
rya.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1954982</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1954982</guid><dc:creator><![CDATA[[[global:former_user]]]]></dc:creator><pubDate>Mon, 20 Sep 2010 19:36:58 GMT</pubDate></item><item><title><![CDATA[Reply to Crash mit boost::ptr_vector on Mon, 20 Sep 2010 19:44:09 GMT]]></title><description><![CDATA[<p>Scorcher24 schrieb:</p>
<blockquote>
<p>.add fügt die Animation über push_back hinzu....</p>
</blockquote>
<p>Und genau diesen Code hätte ich sehen wollen.</p>
<p>Denn folgendes funzt einfach nicht:</p>
<pre><code class="language-cpp">boost::ptr_vector&lt;int*&gt; schwachfug;
schwachfug.push_back(new int);
</code></pre>
<p>Aber anscheinend hast Du <em>irgendwas</em> anderes gemacht, was sich kompilieren ließ.</p>
<p>Scorcher24 schrieb:</p>
<blockquote>
<p>Und genau das ist doch, was ich möchte...</p>
</blockquote>
<p>Ja dann ist ja gut. :p</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1954984</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1954984</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Mon, 20 Sep 2010 19:44:09 GMT</pubDate></item><item><title><![CDATA[Reply to Crash mit boost::ptr_vector on Mon, 20 Sep 2010 19:50:24 GMT]]></title><description><![CDATA[<p>krümelkacker schrieb:</p>
<blockquote>
<p>Scorcher24 schrieb:</p>
<blockquote>
<p>.add fügt die Animation über push_back hinzu....</p>
</blockquote>
<p>Und genau diesen Code hätte ich sehen wollen.</p>
<p>Denn folgendes funzt einfach nicht:</p>
<pre><code class="language-cpp">boost::ptr_vector&lt;int*&gt; schwachfug;
schwachfug.push_back(new int);
</code></pre>
<p>Aber anscheinend hast Du <em>irgendwas</em> anderes gemacht, was sich kompilieren ließ.</p>
</blockquote>
<p>Eh... das wäre ja dummfug in meinem context. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61b.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_tongue"
      title=":P"
      alt="😛"
    /></p>
<pre><code class="language-cpp">void NLRenderManager::add( NLAnimation* anim )
{
	if (!NightLight::search_duplicate&lt;NLAnimation*&gt;(anim))
             m_animationList.push_back(anim);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1954986</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1954986</guid><dc:creator><![CDATA[[[global:former_user]]]]></dc:creator><pubDate>Mon, 20 Sep 2010 19:50:24 GMT</pubDate></item></channel></rss>