<?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[Problem mit delete[ ], please help!]]></title><description><![CDATA[<p>Tag alle zusammen und noch nen Gesundes Neues!</p>
<p>Also folgendes, ich habe hier eine Klasse die als Eigenschaft einen Pointer vom typ einer selbst definierten Struktur hat. In einer Methode der Klasse allociere ich mit dem Zeiger ein beliebig großes array:</p>
<pre><code class="language-cpp">// delete[ ] this-&gt;m_Part;
    // this-&gt;m_Part = 0;
    this-&gt;m_Part = new PuzzelPart[ this-&gt;m_iLevel ];
</code></pre>
<p>So nun kann ich mit dem Zeiger und dem allocierten Speicher arbeiten. Beschliesst jetzt aber der Benutzer das Level zu erhohen oder zu senken, brauche ich je nach dem mehr/weniger Speicher, also will ich dann erst einmal den alten Speicher auf den der Zeiger zeigt frei geben, versuche ich das aber so:</p>
<pre><code class="language-cpp">delete[ ] this-&gt;m_Part;
     this-&gt;m_Part = 0;
</code></pre>
<p><div class="plugin-markdown"><input type="checkbox" id="checkbox63884" /><label for="checkbox63884">raus und sagt folgendes.</label></div></p>
<pre><code>Windows has triggered a breakpoint in Desktop_Drawing.exe.

This may be due to a corruption of the heap, which indicates a bug in Desktop_Drawing.exe or any of the DLLs it has loaded.

This may also be due to the user pressing F12 while Desktop_Drawing.exe has focus.

The output window may have more diagnostic information.
[quote]

weiter:
</code></pre>
<p>---------------------------<br />
Microsoft Visual C++ Debug Library<br />
---------------------------<br />
Debug Assertion Failed!</p>
<p>Program: ...tudio 2008\Projects\Desktop_Drawing\Debug\Desktop_Drawing.exe<br />
File: f:\dd\vctools\crt_bld\self_x86\crt\src\dbgheap.c<br />
Line: 1317</p>
<p>Expression: _CrtIsValidHeapPointer(pUserData)</p>
<p>For information on how your program can cause an assertion<br />
failure, see the Visual C++ documentation on asserts.</p>
<p>(Press Retry to debug the application)<br />
---------------------------<br />
Abbrechen Wiederholen Ignorieren<br />
---------------------------<br />
[code]</p>
<p>Hat einer ne Idee wie ich das in den griff bekomme?</p>
<p>Danke schon mal.</p>
<p>Gruß Tobi.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/201731/problem-mit-delete-please-help</link><generator>RSS for Node</generator><lastBuildDate>Tue, 06 Oct 2026 03:21:38 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/201731.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 03 Jan 2008 14:09:31 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problem mit delete[ ], please help! on Thu, 03 Jan 2008 14:09:31 GMT]]></title><description><![CDATA[<p>Tag alle zusammen und noch nen Gesundes Neues!</p>
<p>Also folgendes, ich habe hier eine Klasse die als Eigenschaft einen Pointer vom typ einer selbst definierten Struktur hat. In einer Methode der Klasse allociere ich mit dem Zeiger ein beliebig großes array:</p>
<pre><code class="language-cpp">// delete[ ] this-&gt;m_Part;
    // this-&gt;m_Part = 0;
    this-&gt;m_Part = new PuzzelPart[ this-&gt;m_iLevel ];
</code></pre>
<p>So nun kann ich mit dem Zeiger und dem allocierten Speicher arbeiten. Beschliesst jetzt aber der Benutzer das Level zu erhohen oder zu senken, brauche ich je nach dem mehr/weniger Speicher, also will ich dann erst einmal den alten Speicher auf den der Zeiger zeigt frei geben, versuche ich das aber so:</p>
<pre><code class="language-cpp">delete[ ] this-&gt;m_Part;
     this-&gt;m_Part = 0;
</code></pre>
<p><div class="plugin-markdown"><input type="checkbox" id="checkbox63884" /><label for="checkbox63884">raus und sagt folgendes.</label></div></p>
<pre><code>Windows has triggered a breakpoint in Desktop_Drawing.exe.

This may be due to a corruption of the heap, which indicates a bug in Desktop_Drawing.exe or any of the DLLs it has loaded.

This may also be due to the user pressing F12 while Desktop_Drawing.exe has focus.

The output window may have more diagnostic information.
[quote]

weiter:
</code></pre>
<p>---------------------------<br />
Microsoft Visual C++ Debug Library<br />
---------------------------<br />
Debug Assertion Failed!</p>
<p>Program: ...tudio 2008\Projects\Desktop_Drawing\Debug\Desktop_Drawing.exe<br />
File: f:\dd\vctools\crt_bld\self_x86\crt\src\dbgheap.c<br />
Line: 1317</p>
<p>Expression: _CrtIsValidHeapPointer(pUserData)</p>
<p>For information on how your program can cause an assertion<br />
failure, see the Visual C++ documentation on asserts.</p>
<p>(Press Retry to debug the application)<br />
---------------------------<br />
Abbrechen Wiederholen Ignorieren<br />
---------------------------<br />
[code]</p>
<p>Hat einer ne Idee wie ich das in den griff bekomme?</p>
<p>Danke schon mal.</p>
<p>Gruß Tobi.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1429986</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1429986</guid><dc:creator><![CDATA[T0bi]]></dc:creator><pubDate>Thu, 03 Jan 2008 14:09:31 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit delete[ ], please help! on Thu, 03 Jan 2008 14:21:29 GMT]]></title><description><![CDATA[<p>Scheinst vorher schon außerhalb des gültigen Bereichs deines Arrays zu kommen...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1429996</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1429996</guid><dc:creator><![CDATA[*D*Evil]]></dc:creator><pubDate>Thu, 03 Jan 2008 14:21:29 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit delete[ ], please help! on Thu, 03 Jan 2008 14:21:34 GMT]]></title><description><![CDATA[<p>Du hast dir irgendwie den Speicher kaputt geschrieben. Steht ja auch in der Meldung. Z.B. in dem du außerhalb des reservierten Speicherbereiches geschrieben hast.</p>
<p>Warum benutzt du eigentlich nicht einfach vector und die at()-Methode? Dann passiert sowas nicht...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1429997</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1429997</guid><dc:creator><![CDATA[Artchi]]></dc:creator><pubDate>Thu, 03 Jan 2008 14:21:34 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit delete[ ], please help! on Thu, 03 Jan 2008 14:30:48 GMT]]></title><description><![CDATA[<p>Alles wegen der Übung, deswegen wollt ich einfach mal new[] und delte[] verwenden.</p>
<p>Hier sind die einzigen Funktionen mit dem ich mit dem Pointer arbeite:</p>
<pre><code class="language-cpp">void CPuzzel::m_UpdatePuzzelParts( int xPos, int yPos ) {

    int iCounter = 0;

    for( int i = 0; i &lt; this-&gt;m_iLevel; i++ ) {

        for( int j = 0; j &lt; this-&gt;m_iLevel; j++ ) {

            this-&gt;m_Part[ iCounter ].iID.x = j;
            this-&gt;m_Part[ iCounter ].iID.y = i;

            // ***** Clear old rgn *****
            this-&gt;m_Part[ iCounter ].hPartRgn = 0;

            this-&gt;m_Part[ iCounter ].hPartRgn = ::CreateRectRgn( xPos + ( j * ( this-&gt;m_Bmp.bmWidth / this-&gt;m_iLevel + 3 ) ), 
                                                                 yPos + ( i * ( this-&gt;m_Bmp.bmHeight / this-&gt;m_iLevel + 3 ) ),
                                                                 ( xPos + ( j * ( this-&gt;m_Bmp.bmWidth / this-&gt;m_iLevel + 3 ) ) + ( this-&gt;m_Bmp.bmWidth / this-&gt;m_iLevel ) ),
                                                                 ( yPos + ( i * ( this-&gt;m_Bmp.bmHeight / this-&gt;m_iLevel + 3 ) ) + ( this-&gt;m_Bmp.bmHeight / this-&gt;m_iLevel ) ));

            iCounter++;
        }
    }
}

void CPuzzel::m_MergePuzzelParts( ) {

    int iCounter = 0;
    bool bOK;

    // ***** Clear old Ids *****
    for( int i = 0; i &lt; ( this-&gt;m_iLevel * this-&gt;m_iLevel ); i++ ) {

        this-&gt;m_Part[ i ].iID.x = -1; 
        this-&gt;m_Part[ i ].iID.y = -1;
    }

    do {

        bOK = true;

        this-&gt;m_Part[ iCounter ].iID.x = rand( ) % this-&gt;m_iLevel; 
        this-&gt;m_Part[ iCounter ].iID.y = rand( ) % this-&gt;m_iLevel; 

        for( int i = 0; i &lt; ( this-&gt;m_iLevel * this-&gt;m_iLevel ); i++ ) {

            if( i == iCounter )
                continue;

            if( ( this-&gt;m_Part[ iCounter ].iID.x == this-&gt;m_Part[ i ].iID.x ) &amp;&amp; 
                ( this-&gt;m_Part[ iCounter ].iID.y == this-&gt;m_Part[ i ].iID.y ) ) {

                    bOK = false;
                    break;
            }
        }

        if( bOK )
            iCounter++;

    } while( iCounter &lt; ( this-&gt;m_iLevel * this-&gt;m_iLevel ) );

    // ***** Isnt merged *****
    if( m_bPuzzelComplete( ) ) {

        m_MergePuzzelParts( );
    }
}

void CPuzzel::m_SwapPuzzel( int first, int second ) {

    PuzzelPart temp = this-&gt;m_Part[ first ];

    this-&gt;m_Part[ first ].iID = this-&gt;m_Part[ second ].iID;
    this-&gt;m_Part[ second ].iID = temp.iID;
}
</code></pre>
<p>Wo mach ich da jetzt nen fehler?</p>
<p>Gruß Tobi.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1430005</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1430005</guid><dc:creator><![CDATA[T0bi]]></dc:creator><pubDate>Thu, 03 Jan 2008 14:30:48 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit delete[ ], please help! on Thu, 03 Jan 2008 14:33:53 GMT]]></title><description><![CDATA[<p>Na der Fehler ist leicht:</p>
<pre><code class="language-cpp">for( int i = 0; i &lt; this-&gt;m_iLevel; i++ ) {

        for( int j = 0; j &lt; this-&gt;m_iLevel; j++ ) {
</code></pre>
<p>Das ergibt m_iLevel * m_iLevel durchgänge(iCounter++). Du hast aber nur einen Bereich von m_iLevel reserviert <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<pre><code class="language-cpp">this-&gt;m_Part = new PuzzelPart[ this-&gt;m_iLevel * this-&gt;m_iLevel];
</code></pre>
<p>und es geht <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1430010</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1430010</guid><dc:creator><![CDATA[*D*Evil]]></dc:creator><pubDate>Thu, 03 Jan 2008 14:33:53 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit delete[ ], please help! on Thu, 03 Jan 2008 14:34:39 GMT]]></title><description><![CDATA[<p>Wenn ich das richtig sehe allokierst Du m_iLevel mal Speicherplatz, greifst dann aber auf m_iLevel^2 Elemente zu.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1430011</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1430011</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Thu, 03 Jan 2008 14:34:39 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit delete[ ], please help! on Thu, 03 Jan 2008 14:38:17 GMT]]></title><description><![CDATA[<p>oh verdammt stimmt, jetzt seh ich es auch <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="😃"
    /> d.h. es muss so heissen:</p>
<pre><code class="language-cpp">this-&gt;m_Part = new PuzzelPart[ this-&gt;m_iLevel * this-&gt;m_iLevel ];
</code></pre>
<p>Okay danke euch.</p>
<p>Gru0 Tobi.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1430015</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1430015</guid><dc:creator><![CDATA[T0bi]]></dc:creator><pubDate>Thu, 03 Jan 2008 14:38:17 GMT</pubDate></item></channel></rss>