<?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[Beschädigung des Heaps?]]></title><description><![CDATA[<p>Hallo,<br />
ich habe ein merkwürdiges Problem:<br />
Mein Programm stürzt immer an anderen Stellen(je nachdem was ich für Parameter bei der Funktion übergebe) mit folgender Fehlermeldung ab.</p>
<blockquote>
<p>Windwos hat einen Haltepunkt ausgelöst.<br />
Dies kann auf eine Bescädigung des Heaps zurückzuführen zu sein, die auf ein Problem in ssbb.exe oder in einer der geladenen DLLs hinweist.</p>
</blockquote>
<p>Die Funktion sieht so aus:(ich habe die Stellen an denen er abstürzt markiert und den Funktionparameter w, bei dem es an der Stelle passiert, dazu geschrieben. p und h=10 bleiben immer gleich)</p>
<pre><code class="language-cpp">COLORREF TableReader::GetFontColor(POINT p, short w, short h){
	MeasureDuration dura;

	hdc = GetDC(hwnd);
	HDC _2hdc = CreateCompatibleDC(this-&gt;hdc);//HDC to put the hidden window in
	HBITMAP hbmp = CreateCompatibleBitmap(hdc,p.x+w+2,p.y+h+30);

	SelectObject(_2hdc,hbmp);
	PrintWindow(hwnd,_2hdc,0);

	HDC hdcMem = CreateCompatibleDC(_2hdc);//hdc to copy the needed part of the hidden window in(stored in _2hdc)
	HBITMAP hbmp2 = CreateCompatibleBitmap(_2hdc,w,h);//bmp with hidden window
	SelectObject(hdcMem, hbmp2);
	BitBlt(hdcMem, 0,0,w,h, _2hdc, p.x+2,p.y+30, SRCCOPY);

	byte BytePerPixel =3;
	byte* bBytes;
	bBytes= new byte[w*h*BytePerPixel];
      BITMAPINFO* bmInfo = new BITMAPINFO();				
      bmInfo-&gt;bmiHeader.biSize = 40;
      bmInfo-&gt;bmiHeader.biWidth = w;
      bmInfo-&gt;bmiHeader.biHeight = h;
      bmInfo-&gt;bmiHeader.biPlanes = 1;
      bmInfo-&gt;bmiHeader.biBitCount = BytePerPixel*8;
      bmInfo-&gt;bmiHeader.biCompression = BI_RGB;
      bmInfo-&gt;bmiHeader.biSizeImage = 0;
      bmInfo-&gt;bmiHeader.biXPelsPerMeter = 0;
      bmInfo-&gt;bmiHeader.biYPelsPerMeter = 0;
      bmInfo-&gt;bmiHeader.biClrUsed = 0;
      bmInfo-&gt;bmiHeader.biClrImportant = 0;

	GetDIBits(hdcMem, hbmp2, 0,h, bBytes, bmInfo, DIB_RGB_COLORS);
	DeleteObject(hbmp);
	DeleteObject(hbmp2);

	long reds=0, greens=0, blues=0;
	int totalCount=0;

	short arrsize=100, curMax=-1;
	ColorCount curColor;
	short *colorCount=NULL;
	COLORREF* colors=NULL;
	colors = new COLORREF[arrsize]; //&lt;&lt;----- stürzt ab bei w=51
	colorCount = new short[arrsize];

	for(int i=0; i&lt;arrsize; i++)
	{
		colors[i]=0;
		colorCount[i]=0;
	}

	long totalPixelCount =0;
	for(short y=0; y&lt;h; y++)	
		for(short x=0; x&lt;w; x++){
			int pos = y*w*BytePerPixel+x*BytePerPixel;
			curColor.color = RGB(bBytes[pos+2],bBytes[pos+1],bBytes[pos+0]);
			bool found;
			found= false;
			for(int i=0; i&lt;arrsize; i++){
				totalPixelCount++;
				if(curColor.color == colors[i]){
					colorCount[i]++;
					found = true;
					curMax = i;
					break;
				}	
			}

			if(!found){
				if(curMax+1&gt;=arrsize){////Expand the array
					arrsize+=100;
					short *tempCount=NULL;
					tempCount = new short[arrsize];
					COLORREF* tempColors=NULL;
					tempColors= new COLORREF[arrsize];

					for (int i=0; i&lt;=curMax; i++) {//copy array content
						tempCount[i] = colorCount[i]; 
						tempColors[i] = colors[i];						
					}
					delete [] colors;
					delete [] colorCount;
					colors = tempColors;
					colorCount= tempCount;
					for (int i=curMax; i&lt;arrsize;i++){
						colors[i]=0;
						colorCount[i]=0;
					}
				}
				curMax++;
				curColor.count = 1;
				colors[curMax] =curColor.color;
				colorCount[curMax]=1;
			}

			reds+=GetRValue(curColor.color);
			greens+=GetGValue(curColor.color);
			blues+=GetBValue(curColor.color);
			totalCount++;
		}
	if(curMax==1)
	{		
		if(colorCount[0]&gt;colorCount[1])
			return colors[1];
		else return colors[0];
	}
	COLORREF colortest=RGB(125,50,200);
	double red_avg, green_avg, blue_avg;
	red_avg = reds/totalCount;
	green_avg = greens/totalCount;
	blue_avg = blues/totalCount;

	DWORD red, green, blue;
	double diff=0,maxDiff=0;
	COLORREF fontColor=0;

	for(int i=0; i&lt;=curMax; i++){
		red=GetRValue(colors[i]);
		green=GetGValue(colors[i]);
		blue=GetBValue(colors[i]);
		diff = abs(red-red_avg)+abs(green-green_avg)+abs(blue-blue_avg);
		if(diff&gt;maxDiff){
			maxDiff = diff;
			fontColor = colors[i];
		}
	}

	DeleteDC(_2hdc);
	DeleteDC(hdcMem);
	delete [] colorCount;
	delete [] colors;
	delete [] bBytes; //&lt;&lt;----- stürzt ab bei w=61 oder w=30

	return fontColor;
}
</code></pre>
<p>Bei w=20 oder w=120 stürzt er z.b. nicht ab.<br />
Gibt natürlich noch mehr Kombinationen, wo er abstürzt oder nicht.</p>
<p>Jemand eine Idee, woran das liegt? Ich denke ja, ich reservie und/oder gebe den Speicher falsch frei.</p>
<p>Danke im voraus<br />
veio</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/206757/beschädigung-des-heaps</link><generator>RSS for Node</generator><lastBuildDate>Sat, 10 Oct 2026 15:53:19 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/206757.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 28 Feb 2008 16:21:16 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Beschädigung des Heaps? on Thu, 28 Feb 2008 16:27:06 GMT]]></title><description><![CDATA[<p>Hallo,<br />
ich habe ein merkwürdiges Problem:<br />
Mein Programm stürzt immer an anderen Stellen(je nachdem was ich für Parameter bei der Funktion übergebe) mit folgender Fehlermeldung ab.</p>
<blockquote>
<p>Windwos hat einen Haltepunkt ausgelöst.<br />
Dies kann auf eine Bescädigung des Heaps zurückzuführen zu sein, die auf ein Problem in ssbb.exe oder in einer der geladenen DLLs hinweist.</p>
</blockquote>
<p>Die Funktion sieht so aus:(ich habe die Stellen an denen er abstürzt markiert und den Funktionparameter w, bei dem es an der Stelle passiert, dazu geschrieben. p und h=10 bleiben immer gleich)</p>
<pre><code class="language-cpp">COLORREF TableReader::GetFontColor(POINT p, short w, short h){
	MeasureDuration dura;

	hdc = GetDC(hwnd);
	HDC _2hdc = CreateCompatibleDC(this-&gt;hdc);//HDC to put the hidden window in
	HBITMAP hbmp = CreateCompatibleBitmap(hdc,p.x+w+2,p.y+h+30);

	SelectObject(_2hdc,hbmp);
	PrintWindow(hwnd,_2hdc,0);

	HDC hdcMem = CreateCompatibleDC(_2hdc);//hdc to copy the needed part of the hidden window in(stored in _2hdc)
	HBITMAP hbmp2 = CreateCompatibleBitmap(_2hdc,w,h);//bmp with hidden window
	SelectObject(hdcMem, hbmp2);
	BitBlt(hdcMem, 0,0,w,h, _2hdc, p.x+2,p.y+30, SRCCOPY);

	byte BytePerPixel =3;
	byte* bBytes;
	bBytes= new byte[w*h*BytePerPixel];
      BITMAPINFO* bmInfo = new BITMAPINFO();				
      bmInfo-&gt;bmiHeader.biSize = 40;
      bmInfo-&gt;bmiHeader.biWidth = w;
      bmInfo-&gt;bmiHeader.biHeight = h;
      bmInfo-&gt;bmiHeader.biPlanes = 1;
      bmInfo-&gt;bmiHeader.biBitCount = BytePerPixel*8;
      bmInfo-&gt;bmiHeader.biCompression = BI_RGB;
      bmInfo-&gt;bmiHeader.biSizeImage = 0;
      bmInfo-&gt;bmiHeader.biXPelsPerMeter = 0;
      bmInfo-&gt;bmiHeader.biYPelsPerMeter = 0;
      bmInfo-&gt;bmiHeader.biClrUsed = 0;
      bmInfo-&gt;bmiHeader.biClrImportant = 0;

	GetDIBits(hdcMem, hbmp2, 0,h, bBytes, bmInfo, DIB_RGB_COLORS);
	DeleteObject(hbmp);
	DeleteObject(hbmp2);

	long reds=0, greens=0, blues=0;
	int totalCount=0;

	short arrsize=100, curMax=-1;
	ColorCount curColor;
	short *colorCount=NULL;
	COLORREF* colors=NULL;
	colors = new COLORREF[arrsize]; //&lt;&lt;----- stürzt ab bei w=51
	colorCount = new short[arrsize];

	for(int i=0; i&lt;arrsize; i++)
	{
		colors[i]=0;
		colorCount[i]=0;
	}

	long totalPixelCount =0;
	for(short y=0; y&lt;h; y++)	
		for(short x=0; x&lt;w; x++){
			int pos = y*w*BytePerPixel+x*BytePerPixel;
			curColor.color = RGB(bBytes[pos+2],bBytes[pos+1],bBytes[pos+0]);
			bool found;
			found= false;
			for(int i=0; i&lt;arrsize; i++){
				totalPixelCount++;
				if(curColor.color == colors[i]){
					colorCount[i]++;
					found = true;
					curMax = i;
					break;
				}	
			}

			if(!found){
				if(curMax+1&gt;=arrsize){////Expand the array
					arrsize+=100;
					short *tempCount=NULL;
					tempCount = new short[arrsize];
					COLORREF* tempColors=NULL;
					tempColors= new COLORREF[arrsize];

					for (int i=0; i&lt;=curMax; i++) {//copy array content
						tempCount[i] = colorCount[i]; 
						tempColors[i] = colors[i];						
					}
					delete [] colors;
					delete [] colorCount;
					colors = tempColors;
					colorCount= tempCount;
					for (int i=curMax; i&lt;arrsize;i++){
						colors[i]=0;
						colorCount[i]=0;
					}
				}
				curMax++;
				curColor.count = 1;
				colors[curMax] =curColor.color;
				colorCount[curMax]=1;
			}

			reds+=GetRValue(curColor.color);
			greens+=GetGValue(curColor.color);
			blues+=GetBValue(curColor.color);
			totalCount++;
		}
	if(curMax==1)
	{		
		if(colorCount[0]&gt;colorCount[1])
			return colors[1];
		else return colors[0];
	}
	COLORREF colortest=RGB(125,50,200);
	double red_avg, green_avg, blue_avg;
	red_avg = reds/totalCount;
	green_avg = greens/totalCount;
	blue_avg = blues/totalCount;

	DWORD red, green, blue;
	double diff=0,maxDiff=0;
	COLORREF fontColor=0;

	for(int i=0; i&lt;=curMax; i++){
		red=GetRValue(colors[i]);
		green=GetGValue(colors[i]);
		blue=GetBValue(colors[i]);
		diff = abs(red-red_avg)+abs(green-green_avg)+abs(blue-blue_avg);
		if(diff&gt;maxDiff){
			maxDiff = diff;
			fontColor = colors[i];
		}
	}

	DeleteDC(_2hdc);
	DeleteDC(hdcMem);
	delete [] colorCount;
	delete [] colors;
	delete [] bBytes; //&lt;&lt;----- stürzt ab bei w=61 oder w=30

	return fontColor;
}
</code></pre>
<p>Bei w=20 oder w=120 stürzt er z.b. nicht ab.<br />
Gibt natürlich noch mehr Kombinationen, wo er abstürzt oder nicht.</p>
<p>Jemand eine Idee, woran das liegt? Ich denke ja, ich reservie und/oder gebe den Speicher falsch frei.</p>
<p>Danke im voraus<br />
veio</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1464866</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1464866</guid><dc:creator><![CDATA[veio]]></dc:creator><pubDate>Thu, 28 Feb 2008 16:27:06 GMT</pubDate></item><item><title><![CDATA[Reply to Beschädigung des Heaps? on Thu, 28 Feb 2008 17:13:53 GMT]]></title><description><![CDATA[<p>ich hab keine ahnung was es sein kann, aber wäre es wirklich möglich (ich hab keinen plan!), dass du dir den heap zerschossen hast?!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1464923</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1464923</guid><dc:creator><![CDATA[XaTrIxX]]></dc:creator><pubDate>Thu, 28 Feb 2008 17:13:53 GMT</pubDate></item><item><title><![CDATA[Reply to Beschädigung des Heaps? on Thu, 28 Feb 2008 17:56:56 GMT]]></title><description><![CDATA[<p>das geht?^^</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1464971</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1464971</guid><dc:creator><![CDATA[veio]]></dc:creator><pubDate>Thu, 28 Feb 2008 17:56:56 GMT</pubDate></item><item><title><![CDATA[Reply to Beschädigung des Heaps? on Thu, 28 Feb 2008 19:10:02 GMT]]></title><description><![CDATA[<p>Achja, ich sehe gerade bei w=51 ist es eine andere Fehlermeldung:</p>
<blockquote>
<p>Eine nicht behandelte Ausnahme des Typs &quot;System.Runtime.InteropServices.SEhExpception&quot; ist in sspb.exe aufgetreten.</p>
<p>Zusätzliche Informationen: Eine externe Komponente hat eine Ausnahme ausgelöst.</p>
</blockquote>
<p>lf help <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1465021</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1465021</guid><dc:creator><![CDATA[veio]]></dc:creator><pubDate>Thu, 28 Feb 2008 19:10:02 GMT</pubDate></item><item><title><![CDATA[Reply to Beschädigung des Heaps? on Thu, 28 Feb 2008 19:40:10 GMT]]></title><description><![CDATA[<p>Jetzt ist dein Heap hin und du muss dir nen neuen kaufen. :p</p>
<p>Du schreibst wahrscheinlich irgendwo über arraygerenzen raus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1465044</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1465044</guid><dc:creator><![CDATA[Codeness]]></dc:creator><pubDate>Thu, 28 Feb 2008 19:40:10 GMT</pubDate></item><item><title><![CDATA[Reply to Beschädigung des Heaps? on Thu, 28 Feb 2008 22:02:11 GMT]]></title><description><![CDATA[<p>Nutzt du Threads?<br />
Ne andere Lösung fällt mir da echt nicht ein...<br />
&quot;Eine externe Komponente hat eine Ausnahme ausgelöst.&quot; =&gt; iwo musst du wo nen try-catch drumpacken, kann das sein?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1465143</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1465143</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Thu, 28 Feb 2008 22:02:11 GMT</pubDate></item><item><title><![CDATA[Reply to Beschädigung des Heaps? on Thu, 28 Feb 2008 22:12:55 GMT]]></title><description><![CDATA[<p>ne, ist single threaded.<br />
und keine ahnung, wo ich da nen try catch block einbinden sollte.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1465148</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1465148</guid><dc:creator><![CDATA[veio]]></dc:creator><pubDate>Thu, 28 Feb 2008 22:12:55 GMT</pubDate></item><item><title><![CDATA[Reply to Beschädigung des Heaps? on Thu, 28 Feb 2008 22:30:05 GMT]]></title><description><![CDATA[<p>Schräges Problem..</p>
<p>Dazu fällt mir nur das ein:</p>
<p>&quot;Wenn der RAM leuchtet und brennt, der Programmierer aus dem Zimmer rennt.&quot; <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="😃"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1465157</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1465157</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Thu, 28 Feb 2008 22:30:05 GMT</pubDate></item><item><title><![CDATA[Reply to Beschädigung des Heaps? on Thu, 28 Feb 2008 23:31:19 GMT]]></title><description><![CDATA[<p>also wenn du die zeilen weglässt geht es auch mit den werten? ich glaube nämlich noch nicht daran ;P</p>
<p>//edit:<br />
hat leider nix damit zu tun... ^^</p>
<pre><code class="language-cpp">short *colorCount=NULL; //wieso?
    COLORREF* colors=NULL; //wieso?
    colors = new COLORREF[arrsize];
    colorCount = new short[arrsize]; 
/*
    short *colorCount = new COLORREF[arrsize]; //&lt;&lt;----- stürzt ab bei w=51 
    COLORREF* colors = new short[arrsize]; 
*/
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1465167</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1465167</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Thu, 28 Feb 2008 23:31:19 GMT</pubDate></item><item><title><![CDATA[Reply to Beschädigung des Heaps? on Thu, 28 Feb 2008 23:38:33 GMT]]></title><description><![CDATA[<p>unskilled schrieb:</p>
<blockquote>
<p>also wenn du die zeilen weglässt geht es auch mit den werten? ich glaube nämlich noch nicht daran ;P</p>
<p>//edit:<br />
hat leider nix damit zu tun... ^^</p>
<pre><code class="language-cpp">short *colorCount=NULL; //wieso?
    COLORREF* colors=NULL; //wieso?
    colors = new COLORREF[arrsize];
    colorCount = new short[arrsize]; 
/*
    short *colorCount = new COLORREF[arrsize]; //&lt;&lt;----- stürzt ab bei w=51 
    COLORREF* colors = new short[arrsize]; 
*/
</code></pre>
</blockquote>
<p>Wenn ich das und alles was mit colors und colorCount zusammenhängt auskommentiere, stürzt er wie bei den anderen Werten bei &quot;delete [] bBytes&quot; ab.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1465168</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1465168</guid><dc:creator><![CDATA[veio]]></dc:creator><pubDate>Thu, 28 Feb 2008 23:38:33 GMT</pubDate></item><item><title><![CDATA[Reply to Beschädigung des Heaps? on Fri, 29 Feb 2008 07:49:41 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>Der Speicher für die Bitmap ist zu klein. Jede Zeile der Bitmap beginnt an einer durch 4 teilbaren Adresse. Falls nötig werden dummy-Bytes eingefügt, für die du keinen Speicher reserviert hast.<br />
So müsste es funktionieren:</p>
<pre><code class="language-cpp">bBytes= new byte[((w*BytePerPixel+3)&amp;~3)*h];
</code></pre>
<p>Gruss Chris</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1465205</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1465205</guid><dc:creator><![CDATA[Chrisi_K]]></dc:creator><pubDate>Fri, 29 Feb 2008 07:49:41 GMT</pubDate></item><item><title><![CDATA[Reply to Beschädigung des Heaps? on Fri, 29 Feb 2008 07:57:36 GMT]]></title><description><![CDATA[<p>ich meinte, du solltest erst ma nur das delete auskommentieren und sagen, obs dann geht ^^ aber anscheind is jz dein prob eh gelöst ^^</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1465210</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1465210</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Fri, 29 Feb 2008 07:57:36 GMT</pubDate></item><item><title><![CDATA[Reply to Beschädigung des Heaps? on Fri, 29 Feb 2008 09:40:51 GMT]]></title><description><![CDATA[<p>bislang konnt ich das Programm mit der Änderung nicht zum abstürzen bringen...scheint also des Rätsels Lösung zu sein.<br />
Danke!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1465241</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1465241</guid><dc:creator><![CDATA[veio]]></dc:creator><pubDate>Fri, 29 Feb 2008 09:40:51 GMT</pubDate></item></channel></rss>