Out of memory when creating TextureBrush

  • Thread starter Thread starter CroDude
  • Start date Start date
C

CroDude

Heya all!

I have a weird problem when creating a texture brush in a Paint event.
When program gets to the line where I'm creating a new TextureBrush object,
it crashes with OutOfMemory exception.

Here's the code:

private void pnl_DrawSurface_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{
// Set InterpolationMode for image drawing
e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;

base.OnPaint (e);

// Draw previewImage onto the panel
if(this.previewImage != null)
{
this.displayRectangle = GetDisplayRectangle(this.previewImage);
this.CenterDisplayRectangle();

TextureBrush texBrush = new TextureBrush((Image)this.previewImage);
e.Graphics.FillRectangle(texBrush, this.displayRectangle);
}
}

Every object is valid (displayRectangle, previewImage ... they are not
nulls).
What a heck could be a problem here ???

Thanks in advance!
 
Look at your Call Stack window. I would look for your error to be caused by
some unexpected recursiveness. For instance, perhaps your
CenterDisplayRectangle() method is triggering another Paint event.

HTH

DalePres
MCAD, MCDBA, MCSE
 
Thanks Dale! I'll look into that.

Dale Preston said:
Look at your Call Stack window. I would look for your error to be caused by
some unexpected recursiveness. For instance, perhaps your
CenterDisplayRectangle() method is triggering another Paint event.

HTH

DalePres
MCAD, MCDBA, MCSE
 
Back
Top