🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #1841

Multi-thread OR Event-based?

#1841
From: Robert G. Hoover
Date: Wed, 13 Jun 2007 16:34
102 lines
4338 bytes
Hi again,

I've written a test app (in BDS C++ Builder 2006) that creates a BITMAP
structure and then paints it onto the screen every 50 milliseconds via
TTimer and WM_TIMER. Sounds simple enough, right?

Here's the timer function:

// draw video frame
void __fastcall TShellForm::VideoStreamTimerTimer(TObject *Sender)
{
	// increasing image color (black to white, then wrap)
	static unsigned char ThisShade = 0;

	// update image color
	memset(VideoImage->bmBitmap.bmBits,
               ThisShade++,
               VideoImage->WidthBytes * VideoImage->Height);

	// display current image on screen
	VideoImage->DibDraw(hDD, hDC, 0, 0);
}
//---------------------------------------------------------------------------

VideoImage is just a wrapper for a BITMAP structure. Here's my DibDraw
stuff...

// draw bitmap preserving size and aspect ratio
void BitmapImageClass::DibDraw(HDRAWDIB hDD, HDC hDC, int left, int top)
{
	DrawDibDraw(hDD,     						
		    hDC,     						
		    left,							
		    top,    						
		    -1,
		    -1,
		    &(bmInfo.bmiHeader),			
		    bmBitmap.bmBits,   	   			
		    0,     							
		    0,     							
		    bmInfo.bmiHeader.biWidth,    	
		    bmInfo.bmiHeader.biHeight,    	
		    DDF_SAME_DRAW | DDF_SAME_HDC);	
}
//---------------------------------------------------------------------------

I'm also setting it up like so...

// initialize GUI
void __fastcall TShellForm::FormCreate(TObject *Sender)
{
	// create object
	VideoImage = new BitmapImageClass(ClientWidth, ClientHeight, 8);

	// get handle to window canvas
	hDC = GetDC(Handle);

	// open DrawDib library for use
	// and create a DrawDib device context for drawing
	hDD = DrawDibOpen();

	// define DrawDib transformation
	DrawDibBegin(hDD,
		     hDC,
		     -1,
		     -1,
		     &(VideoImage->bmInfo.bmiHeader),
		     VideoImage->Width,
		     VideoImage->Height,
		     DDF_SAME_DRAW | DDF_SAME_HDC);

	// realize palette of DrawDib DC for use with specified DC
//	DrawDibRealize(hDD, hDC, 0);
}
//---------------------------------------------------------------------------

The DrawDibRealize fails and seems not to affect the operation as my
stream does paint as expected.

So, here's the problem.... I've got 2 Pentium machines and 1 DualCore
machine exhibiting the same behavior. This code causes crashes on them
(blue screen of death) with Windows errors BAD_POOL_HEADER,
IRQL_NOT_LESS_OR_EQUAL, PAGE_FAULT_IN_NONPAGED_AREA. This is way outside
my understanding of operating systems and hardware.

I switched from SetDIBitsToDevice() to DrawDibDraw() because of an
earlier discussion about "thread-safe" video routines. There seems to be
no improvement in execution.

And to make matters worse, all my programs run flawlessly on slower
machines. Is it possible that "we" have crossed a yield threshold where
the processors are running faster than WinXP can manage? "Windows XP was
not originally designed to support performance states on multiprocessor
configurations" (http://support.microsoft.com/kb/896256/en-us)

Also, the DualCore runs 10x slower on the frame rate, possibly
indicating that the 2 processors are fighting over the same memory space?

I'm really pulling out my hair on this one... any and all advice
welcome... many thanks!

Rob
Technical Details
Message-ID: <46701cfb@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,27bec389d3c536e6,start
X-Google-Attributes: gid10cc67,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Wed, 13 Jun 2007 12:34:16 -0400
From: "Robert G. Hoover" <not.a.real.address@anywhere.sorry>
User-Agent: Thunderbird 1.5.0.12 (Windows/20070509)
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Multi-thread OR Event-based?
X-Enigmail-Version: 0.94.1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Antivirus: avast! (VPS 000748-5, 06/13/2007), Outbound message
X-Antivirus-Status: Clean
NNTP-Posting-Host: 76.106.54.160
Message-ID: <46701cfb@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1181752571 76.106.54.160 (13 Jun 2007 09:36:11 -0700)
Lines: 102
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail