I am using 5th edition sdk to see if our application would work on it. Initially it was written for 3rd MR edition. I managed to crash 5th edition emulator when my code uses gradient brush. (by the way – our code works fine on 3rd edition)
I have a label control which has a custom background drawer. Here is the function which performs the gradient brush drawing.
EXPORT_C void CGradientBackground::Draw(
CWindowGc& aGc,
const CCoeControl& /*aControl*/,
const TRect& aRect) const
{
aGc.SetPenStyle(CGraphicsContext::ENullPen);
if(iTop==iBottom)
{
//Normal fill
aGc.SetBrushColor(iTop);
aGc.SetBrushStyle(CGraphicsContext::ESolidBrush);
aGc.DrawRect(aRect);
} else
{
TInt brushWidth = aRect.Height();
if(iOrientation==ColorUtils::EBitmapOrientationHorizontal)
brushWidth = aRect.Width();
//Create gradient brush
CFbsBitmap* pBrush = THEMECLASS::CreateGradientBrush(
iOrientation, brushWidth,iTop,iBottom);
if(pBrush)
{
aGc.UseBrushPattern(pBrush);
aGc.SetBrushStyle(CGraphicsContext::EPatternedBrush);
aGc.SetBrushOrigin(TPoint(0,0));
//Draw the brush bitmap
aGc.DrawRect(aRect);
aGc.DiscardBrushPattern();
delete pBrush;
}
} // end if(iTop==iBottom)
aGc.SetPenStyle(CGraphicsContext::ESolidPen);
aGc.SetBrushStyle(CGraphicsContext::ENullBrush);
}
The function itself executes with no problem but when after it finishes the emulator crashes with the following error:
148.750 BitGdi internal Panic EBitgdiPanicInvalidBitmap, in file RECT.CPP @ line 360
148.750 Assert condition = "brushbitmap != NULL"
148.750 Thread wserv.exe::Wserv Panic BITGDI 13
148.750 FAULT: KERN 0x00000004 (4)
It looks to me that line aGc.DiscardBrushPattern(); does not reset internal brushbitmap pointer. I tried adding aGc.SetBrushStyle(CGraphicsContext::ENullBrush); before discarding the brush and after (before deleting the brush) but it does not make any difference. Is it a bug or I am missing something and how can I solve it? As I said the error only comes up on 5th edition emulator.



