473,405 Members | 2,279 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Out of memory when creating TextureBrush

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!
Nov 16 '05 #1
2 4697
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

"CroDude" <di***********@zg.htnet.hr> wrote in message
news:d1**********@news1.xnet.hr...
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!

Nov 16 '05 #2
Thanks Dale! I'll look into that.

"Dale Preston" <da******@nospam.nospam> wrote in message
news:Om**************@TK2MSFTNGP15.phx.gbl...
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

"CroDude" <di***********@zg.htnet.hr> wrote in message
news:d1**********@news1.xnet.hr...
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!


Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jason Callas | last post by:
I was doing starting some experimenting with the GC and ran into the following odd result. I created an object and my used memory went up by almost 11k but when I cleared it and forced a collection...
0
by: foos | last post by:
Hello, Hopefully someone here can help me. I'm not sure what I am doing wrong, but I am getting an Out Of Memory exception when I try to use a TextureBrush. I have simplified my code to...
2
by: Ray Cassick \(Home\) | last post by:
I have been beating myself up over trying to locate what I thought was a memory leak in MY code but based upon what I have seen I can't be sure that it IS my fault or something strange with DOTNET....
6
by: Michael Isaacs | last post by:
Regarding use of enum's, I am wondering what the cost of memory is when creating the enumeration on the calling side, and then using it on the function/method side. See example below. If I...
7
by: Jeffrey Melloy | last post by:
I have a couple users trying to install Postgres on OS X. To the best of my knowledge, both of them are using 7.4.5/10.3.5, and got identical errors while trying to init the database: Reducing...
2
by: Robert | last post by:
Hello javascript group readers, I have a question regarding how to prevent memory leaks in Internet Explorer when using closures. I already knew about the circular reference problem, and until...
4
by: Tomassus | last post by:
Hi there, I have a problem with dynamic memory allocation. I know that it would have been easier to use vectors methods, but i want to know what i do here wrong. This is one of my methods in...
11
by: Alex | last post by:
Hello all, I have a main form(say "form1") .i want to display another form(say "form2") on occuring of an event (say a button click) and want to hide it after some time so that it will again...
0
by: Mitch | last post by:
Im trying to do a simple 3d project and I dont want to use dx or xna. Im using DrawPoly to draw my meshes, and trying to use FillPolygon and a texturebrush to fill the polys with a image. The image...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.