Double Buffering question
-
I am trying to implement double buffering in a form, and I am getting a crash. I have a fix for the crash but I don't know if it's "correct". To enable double buffering, I call this function from the form's constructor:
System::Void enable_double_buffering()
{
using System::Windows::Forms::ControlStyles;SetStyle(static\_cast<ControlStyles>(ControlStyles::DoubleBuffer | ControlStyles::UserPaint | ControlStyles::AllPaintingInWmPaint), true); UpdateStyles();
}
My Paint handler looks like this:
System::Void PlotDisplayWindow_Paint(System::Object* /*sender*/, System::Windows::Forms::PaintEventArgs* e)
{
using System::Drawing::Graphics;Graphics\* g = e->Graphics; // draw an image g->Dispose();
}
If I do not enable double buffering, then it works fine, but with flickering. With double buffering, I get the following exception:
************** Exception Text **************
System.ArgumentException: Invalid parameter used.
at System.Drawing.Graphics.EndContainer(GraphicsContainer container)
at System.Windows.Forms.DibGraphicsBufferManager.ReleaseBuffer(GraphicsBuffer buffer)
at System.Windows.Forms.GraphicsBuffer.Dispose()
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)If I comment out the
g->Dispose();
line in the Paint handler, then I do not get the crash. Is it correct/acceptable not to dispose of the Graphics object after painting? -- Marcus Kwok -
I am trying to implement double buffering in a form, and I am getting a crash. I have a fix for the crash but I don't know if it's "correct". To enable double buffering, I call this function from the form's constructor:
System::Void enable_double_buffering()
{
using System::Windows::Forms::ControlStyles;SetStyle(static\_cast<ControlStyles>(ControlStyles::DoubleBuffer | ControlStyles::UserPaint | ControlStyles::AllPaintingInWmPaint), true); UpdateStyles();
}
My Paint handler looks like this:
System::Void PlotDisplayWindow_Paint(System::Object* /*sender*/, System::Windows::Forms::PaintEventArgs* e)
{
using System::Drawing::Graphics;Graphics\* g = e->Graphics; // draw an image g->Dispose();
}
If I do not enable double buffering, then it works fine, but with flickering. With double buffering, I get the following exception:
************** Exception Text **************
System.ArgumentException: Invalid parameter used.
at System.Drawing.Graphics.EndContainer(GraphicsContainer container)
at System.Windows.Forms.DibGraphicsBufferManager.ReleaseBuffer(GraphicsBuffer buffer)
at System.Windows.Forms.GraphicsBuffer.Dispose()
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)If I comment out the
g->Dispose();
line in the Paint handler, then I do not get the crash. Is it correct/acceptable not to dispose of the Graphics object after painting? -- Marcus Kwokricecake wrote:
If I comment out the g->Dispose(); line in the Paint handler, then I do not get the crash. Is it correct/acceptable not to dispose of the Graphics object after painting?
General rule is you should not be calling Dispose on objects that you didnt create :)**
How xacc.ide transforms text to colored words on the screen
Intel PentuimM (aka Centrino) undervolting**
-
ricecake wrote:
If I comment out the g->Dispose(); line in the Paint handler, then I do not get the crash. Is it correct/acceptable not to dispose of the Graphics object after painting?
General rule is you should not be calling Dispose on objects that you didnt create :)**
How xacc.ide transforms text to colored words on the screen
Intel PentuimM (aka Centrino) undervolting**