Im working on a small paint program and ive run into the odd problem
that when i draw more than ~9930 lines on the screen, all my lines
disappear.
ive isolated the problem into a tiny bit of code which can be found
here:
the program has an array of lines which it draws on the screen
counting from 9900 and up. as it gets to about 9950 lines or so, then
suddenly they all disapear
im using dc.DrawLinesList() to draw the lines, but i (sometimes) get a
similar problem when "manually" drawing the lines one by one. you can
switch to this method of drawing by changing to "drawLines2()" on line
24. if it manages to draw all the lines, try switching to another app
and then back and it wont redraw.
Is this a bug in wxPython, or is it something else that is pulling my
leg? (some event that tries to redraw or something)
* You are not binding EVT_PAINT to your handler so even if the drawing
is correctly done to the buffer bitmap it won't be displayed when the
window is refreshed. This is also the reason it is not displaying
anything, because the drawing is being done to your buffer before the
window is shown, and then you are never displaying the buffer.
* At the time that initBuffer is called it is likely that the window
size is still small (because there hasn't been an iteration of the
main loop to deliver the size events to the frame where it will resize
the child window to fit) so your buffer bitmap will be created with a
too small size. You should probably bind the window's EVT_SIZE event
and recreate your buffer there.
* Calling drawBuffer each time through the inner loop in testline is
going to take a horrendously long time as it will be creating a DC and
redrawing every line segment up to that point, over and over and over
again. If you really need to draw each segment as you add them to the
list then the best thing to do is to only draw the one being added.
The rest of them are already in the buffer bitmap.
Robin
···
On Jun 8, 12:37 am, Mr Nilsson <super.infra...@gmail.com> wrote:
Im working on a small paint program and ive run into the odd problem
that when i draw more than ~9930 lines on the screen, all my lines
disappear.
ive isolated the problem into a tiny bit of code which can be found
here:
the program has an array of lines which it draws on the screen
counting from 9900 and up. as it gets to about 9950 lines or so, then
suddenly they all disapear
im using dc.DrawLinesList() to draw the lines, but i (sometimes) get a
similar problem when "manually" drawing the lines one by one. you can
switch to this method of drawing by changing to "drawLines2()" on line
24. if it manages to draw all the lines, try switching to another app
and then back and it wont redraw.
Is this a bug in wxPython, or is it something else that is pulling my
leg? (some event that tries to redraw or something)
Hi
Thanks for looking at my problem, please let me comment your comments:
1. My bad, i accidentally cut away the line where i bind the paint
event to onPaint().
I put it back into the code ( http://gust.parknet.se/_python/bug2.py
). Problem is, the lines still disappear.
2. Are you sure about this? Im not calling the the initBuffer() in the
drawingArea's init, i call it AFTER the frame has been maximised. if
this wasnt right then we wouldnt see any lines at all, correct? Also,
it wouldnt explain why the 9950 first lines look ok, and they then all
disappear?
3. Im very much aware that the code is inefficient. BUT thats the
point of this script! to show that after a certain number of lines
pumped into the drawlineslist() they are suddenly not shown anymore.
Cheers
Gustaf
···
On Jun 8, 6:33 pm, Robin Dunn <ro...@alldunn.com> wrote:
On Jun 8, 12:37 am, Mr Nilsson <super.infra...@gmail.com> wrote:
> Im working on a small paint program and ive run into the odd problem
> that when i draw more than ~9930 lines on the screen, all my lines
> disappear.
> ive isolated the problem into a tiny bit of code which can be found
> here:
> the program has an array of lines which it draws on the screen
> counting from 9900 and up. as it gets to about 9950 lines or so, then
> suddenly they all disapear
> im using dc.DrawLinesList() to draw the lines, but i (sometimes) get a
> similar problem when "manually" drawing the lines one by one. you can
> switch to this method of drawing by changing to "drawLines2()" on line
> 24. if it manages to draw all the lines, try switching to another app
> and then back and it wont redraw.
> Is this a bug in wxPython, or is it something else that is pulling my
> leg? (some event that tries to redraw or something)
You have a few problems in your sample:
* You are not binding EVT_PAINT to your handler so even if the drawing
is correctly done to the buffer bitmap it won't be displayed when the
window is refreshed. This is also the reason it is not displaying
anything, because the drawing is being done to your buffer before the
window is shown, and then you are never displaying the buffer.
* At the time that initBuffer is called it is likely that the window
size is still small (because there hasn't been an iteration of the
main loop to deliver the size events to the frame where it will resize
the child window to fit) so your buffer bitmap will be created with a
too small size. You should probably bind the window's EVT_SIZE event
and recreate your buffer there.
* Calling drawBuffer each time through the inner loop in testline is
going to take a horrendously long time as it will be creating a DC and
redrawing every line segment up to that point, over and over and over
again. If you really need to draw each segment as you add them to the
list then the best thing to do is to only draw the one being added.
The rest of them are already in the buffer bitmap.
Hi
...
3. Im very much aware that the code is inefficient. BUT thats the
point of this script! to show that after a certain number of lines
pumped into the drawlineslist() they are suddenly not shown anymore.
Seem a problem in the create process of 10000 pen objects.
Try changing in 'drawLines' method:
for i in range(0,len(subLines)):
pens.append(wx.Pen('black', 2, wx.SOLID))
to:
BlackPen = wx.Pen('black', 2, wx.SOLID)
for i in range(0,len(subLines)):
pens.append(BlackPen)
Regards
···
--
*****************************************
Oswaldo Hernández
oswaldo (@) soft-com (.) es
*****************************************
PD:
Antes de imprimir este mensaje, asegúrese de que es necesario.
El medio ambiente está en nuestra mano.
No one should be surprised that this fails. Each call to wx.Pen
creates a new GDI pen object, and the number of handles available for
GDI objects is limited. This code is essentially consuming all of the
GDI object handles. You can cause similar problems by creating tens
of thousands of windows in a single application.
So, this is not a wxPython bug, it's a usage problem.
···
On Jun 9, 6:52 am, Oswaldo Hernández <lis...@soft-com.es> wrote:
Mr Nilsson escribió:
> Hi
> ...
> 3. Im very much aware that the code is inefficient. BUT thats the
> point of this script! to show that after a certain number of lines
> pumped into the drawlineslist() they are suddenly not shown anymore.
Seem a problem in the create process of 10000 pen objects.
...
for i in range\(0,len\(subLines\)\):
pens\.append\(wx\.Pen\('black', 2, wx\.SOLID\)\)
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
Thank you all for clearing this out, it makes sense now.
Gustaf
···
On Jun 10, 7:02 pm, Tim Roberts <t...@probo.com> wrote:
On Jun 9, 6:52 am, Oswaldo Hernández <lis...@soft-com.es> wrote:
> Mr Nilsson escribió:
> > Hi
> > ...
> > 3. Im very much aware that the code is inefficient. BUT thats the
> > point of this script! to show that after a certain number of lines
> > pumped into the drawlineslist() they are suddenly not shown anymore.
> Seem a problem in the create process of 10000 pen objects.
>...
> for i in range(0,len(subLines)):
> pens.append(wx.Pen('black', 2, wx.SOLID))
No one should be surprised that this fails. Each call to wx.Pen
creates a new GDI pen object, and the number of handles available for
GDI objects is limited. This code is essentially consuming all of the
GDI object handles. You can cause similar problems by creating tens
of thousands of windows in a single application.
So, this is not a wxPython bug, it's a usage problem.
--
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.
2. Are you sure about this? Im not calling the the initBuffer() in the
drawingArea's init, i call it AFTER the frame has been maximised. if
this wasnt right then we wouldnt see any lines at all, correct?
Just because the frame is maximized does not mean that it has resized the child widgets to match yet. That happens in the next size event and that may or may not have happened by the time you are creating the buffer and drawing.
···
* At the time that initBuffer is called it is likely that the window
size is still small (because there hasn't been an iteration of the
main loop to deliver the size events to the frame where it will resize
the child window to fit) so your buffer bitmap will be created with a
too small size. You should probably bind the window's EVT_SIZE event
and recreate your buffer there.