Re: [pygame] event getting corrupted

2009-09-18 Thread Lenard Lindstrom

Bo Jangeborg wrote:



well, there is code after mouse_pos = event_pos.
I would add a assert type(event) is not long
after any function call in mouse_button_up to know when event is 
changed,

then drill down the offending function.

--
claxo

I have only gotten one more trace, and that after several hours of 
testing. That
time I got the same error but in another part of the code. I will try 
to find a pattern,

but I am not hopefull.

Bo)

Hi Bo,

The event object is probably not being overwritten. That would mean a 
reference count problem somewhere, most likely causing a segfault first. 
Is mouse_button_up a true method, declared in a class statement?


Lenard Lindstrom



Re: [pygame] event getting corrupted

2009-09-18 Thread Bo Jangeborg

Lenard Lindstrom skrev:

Bo Jangeborg wrote:



well, there is code after mouse_pos = event_pos.
I would add a assert type(event) is not long
after any function call in mouse_button_up to know when event is 
changed,

then drill down the offending function.

--
claxo

I have only gotten one more trace, and that after several hours of 
testing. That
time I got the same error but in another part of the code. I will try 
to find a pattern,

but I am not hopefull.

Bo)

Hi Bo,

The event object is probably not being overwritten. That would mean a 
reference count problem somewhere, most likely causing a segfault 
first. Is mouse_button_up a true method, declared in a class statement?


Lenard Lindstrom


mouse_button_up is a class method of my Gui class | class Gui(Widget): 
|.  And it only gets called from

within its main_loop method.
I have had another trace where the event had turned into a long within 
that main loop. In that case there also was
other readings from the event object that worked before getting to the 
part where it crashed, without interceding

assignment to the event variable.

So it seems like it could happen at different places without the event 
being assigned to, which makes me think that
the problem doesn't happen in my code. I does seem to be related to 
user input because it only happens when

I have released the mouse button as far as I can remember.

I noticed that there was talk about switching the fastevent module to be 
the default, has that been done ?


Bo)











Re: [pygame] event getting corrupted

2009-09-18 Thread Brian Fisher
I'm a little confused - you said you get a segmentation error, and you
mentioned running a debugger, but you are showing a python error. So do you
get a real segmentation fault? Like bad memory access that drops out of
python and all that? If so, you haven't captured that error in the right
kind of debugger for seg faults (gdb) yet.

Assuming you are getting a seg fault, then that sucks.  If it were me in
that case, I'd probably see if I can set up some system to force the error
to happen. Like say make the game run through the conditions that you see
the error in now, and make it run over night - or maybe set up some kind of
automation to record and playback some play, and again, run it all night.

The reason getting a stable reproducing case is so important, is then you
can binary search this. Like disable all blitting, or turn off the music,
etc.

As far as the python stack trace goes, if you are getting a seg fault, then
the weirdness of the python stack makes it seem likely that memory
corruption happened between the event.pos and event.button lines, as you
pointed out. Is this python stack reproducible? Have you seen it multiple
times? If so, then it seems like it could be code that executes
synchronously between those 2 lines, in which case tossing a ton of asserts
or temp = event.button lines in the mouse_button_up would help you narrow
down the lines that trigger things next time this in-python exception
triggers? If on the other hand you haven't seen it before/can't reporoduce
it, it may just be a red herring, and the corruption could be happening
asynchronously in some other thread - maybe it could be the music?

So what OS and versions of stuff you using when you get the error? Have you
been able to try the code on other platforms? Any other libraries besides
pygame used with this program? Any idea when exactly it started occurring in
relation to your code? Any code of yours that seems like something that
could be causing the problem (like your own c compiled extensions)? I don't
suppose you are blitting a surface to itself anywhere and using Linux?


On Wed, Sep 16, 2009 at 11:36 AM, Bo Jangeborg b...@softwave.se wrote:

 I have seen a troubling error for some time now.
 Occasionally I get a segmentation error with no indication of what
 went wrong. The error is not repeatable in a reliable way and I get
 no error trace. Repeating the error can take hours.

 After seeing this I have tried to pin down, with the debugger running,
 what's going wrong but the nearest I can get is that the event object
 gets turned into a long at different times.

 Running with a debugger I got this trace. I have included the calling
 line were you can see that the event seem to be correct, but at some
 point the event object seem to become corrupted.
 Included is also the code between the call and the eventual point
 of error. I am at loss at what may be going wrong.

 Bo)

 Traceback (most recent call last):
  File C:\Program
 Files\eclipse\plugins\org.python.pydev.debug_1.4.7.2843\pysrc\pydevd.py,
 line 881, in module
   debugger.run(setup['file'], None, None)
  File C:\Program
 Files\eclipse\plugins\org.python.pydev.debug_1.4.7.2843\pysrc\pydevd.py,
 line 710, in run
   execfile(file, globals, locals) #execute the script
  File C:\Projekt\eclipse\Pyos\Program\Solitaire\solitaire.py, line 761,
 in module
   main()
  File C:\Projekt\eclipse\Pyos\Program\Solitaire\solitaire.py, line 80, in
 main
   if screen.main_loop(app):
  File C:\Projekt\eclipse\Pyos\System\widgets\gui.py, line 328, in
 main_loop
   = self.mouse_button_up(event, mob_pos, mousemove)
  File C:\Projekt\eclipse\Pyos\System\widgets\gui.py, line 573, in
 mouse_button_up
   if event.button == 1:
 AttributeError: 'long' object has no attribute 'button'


 elif event.type is MOUSEBUTTONUP:
mob_pos, mousemove, mouse_pos, hit_pos \
= self.mouse_button_up(event, mob_pos, mousemove)



   def mouse_button_up(self, event, mob_pos, mousemove):
   ''' handle mouse button up events'''
   mousebtn_event = False
   mouse_pos = event.pos
   widget, hit_pos = self.mouse_hit_widget(mouse_pos[0],
   mouse_pos[1])
   if widget is None or not widget.enabled:
   self.moving_object = None
   self.repeating_object = None
   self.last_over_drop_widget = None
   else:
   event_data = {'hit_pos':hit_pos, 'over_widget':widget}
   event_data['gui'] = self
   if widget and widget.exists('event_click_release_data'):
   event_data.update(widget.event_click_release_data)
   #InsideButton  (Left)
   if event.button == 1:



   def mouse_hit_widget(self, hit_pos_x, hit_pos_y, draged_widget=None,
   dropreciever=False, mouse_down=False,
 mouse_over=False):
   ''' Return the first valid widget under the mouse pointer'''
   widget_hit, hit_pos = _mouse_hit_widget(self, hit_pos_x, hit_pos_y,
 

Re: [pygame] event getting corrupted

2009-09-18 Thread Bo Jangeborg

Brian Fisher skrev:
I'm a little confused - you said you get a segmentation error, and 
you mentioned running a debugger, but you are showing a python error. 
So do you get a real segmentation fault? Like bad memory access that 
drops out of python and all that? If so, you haven't captured that 
error in the right kind of debugger for seg faults (gdb) yet.


If I am not using the debugger I get a segmentation error. If I use the 
debugger that is integrated with Pydev in Eclipse I do get a

trace, assuming that its the same error, but it seems safe to assume.

Assuming you are getting a seg fault, then that sucks.  If it were me 
in that case, I'd probably see if I can set up some system to force 
the error to happen. Like say make the game run through the conditions 
that you see the error in now, and make it run over night - or maybe 
set up some kind of automation to record and playback some play, and 
again, run it all night.


It would have to playback a user solving a solitaire game which is were 
I have been able to repeat the error infrequently. Got any suggestions

for how to do that in windows ?
The reason getting a stable reproducing case is so important, is then 
you can binary search this. Like disable all blitting, or turn off the 
music, etc.


Yes, I have been trying to find a stable way to repeat it but no luck so 
far.
As far as the python stack trace goes, if you are getting a seg fault, 
then the weirdness of the python stack makes it seem likely that 
memory corruption happened between the event.pos and event.button 
lines, as you pointed out. Is this python stack reproducible? Have you 
seen it multiple times? If so, then it seems like it could be code 
that executes synchronously between those 2 lines, in which case 
tossing a ton of asserts or temp = event.button lines in the 
mouse_button_up would help you narrow down the lines that trigger 
things next time this in-python exception triggers? If on the other 
hand you haven't seen it before/can't reporoduce it, it may just be a 
red herring, and the corruption could be happening asynchronously in 
some other thread - maybe it could be the music?


The error has occurred infrequently for a month or two, not sure when I 
saw it the first time. But since I couldn't repeat it I figured it was a
chance error. I am not using any own threads at all, but there is a 
sound being played when I release the mouse button so that could be a 
factor.
So what OS and versions of stuff you using when you get the error? 
Have you been able to try the code on other platforms? Any other 
libraries besides pygame used with this program? Any idea when exactly 
it started occurring in relation to your code? Any code of yours that 
seems like something that could be causing the problem (like your own 
c compiled extensions)? I don't suppose you are blitting a surface to 
itself anywhere and using Linux?


I am using the latests stable pygame, and python 2.5 on a Windows Vista 
Dual Core machine. The only other c extension that I use is
Psyco, but that should be disabled when running the debugger. I am not 
blitting surfaces to it self . I am however blitting to subsurfaces
which I remember could cause a problem in some previous version of 
Pygame. So I set some print statements to see if the crash happend

while blitting but no luck there.



Re: [pygame] event getting corrupted

2009-09-18 Thread Lenard Lindstrom

Bo Jangeborg wrote:

Lenard Lindstrom skrev:

Bo Jangeborg wrote:



well, there is code after mouse_pos = event_pos.
I would add a assert type(event) is not long
after any function call in mouse_button_up to know when event is 
changed,

then drill down the offending function.

--
claxo

I have only gotten one more trace, and that after several hours of 
testing. That
time I got the same error but in another part of the code. I will 
try to find a pattern,

but I am not hopefull.

Bo)

Hi Bo,

The event object is probably not being overwritten. That would mean a 
reference count problem somewhere, most likely causing a segfault 
first. Is mouse_button_up a true method, declared in a class statement?


Lenard Lindstrom


mouse_button_up is a class method of my Gui class | class Gui(Widget): 
|.  And it only gets called from

within its main_loop method.
I have had another trace where the event had turned into a long within 
that main loop. In that case there also was
other readings from the event object that worked before getting to the 
part where it crashed, without interceding

assignment to the event variable.

So it seems like it could happen at different places without the event 
being assigned to, which makes me think that
the problem doesn't happen in my code. I does seem to be related to 
user input because it only happens when

I have released the mouse button as far as I can remember.

I noticed that there was talk about switching the fastevent module to 
be the default, has that been done ?


Bo)


Hi,

We did not make fastevent the default because it was not that fast. Have 
you tried using it? I believe the module is a drop-in replacement for 
event. This would tell use if the problem is with the event module 
specifically. And by default Python 2.x will use int's when possible. A 
long is created only when necessary. Is there any place in your program 
where you create a long?


Lenard



Re: [pygame] event getting corrupted

2009-09-16 Thread claudio canepa
On Wed, Sep 16, 2009 at 3:36 PM, Bo Jangeborg b...@softwave.se wrote:

 I have seen a troubling error for some time now.
 Occasionally I get a segmentation error with no indication of what
 went wrong. The error is not repeatable in a reliable way and I get
 no error trace. Repeating the error can take hours.

 After seeing this I have tried to pin down, with the debugger running,
 what's going wrong but the nearest I can get is that the event object
 gets turned into a long at different times.

 Running with a debugger I got this trace. I have included the calling
 line were you can see that the event seem to be correct, but at some
 point the event object seem to become corrupted.
 Included is also the code between the call and the eventual point
 of error. I am at loss at what may be going wrong.

 Bo)

 Traceback (most recent call last):
  File C:\Program
 Files\eclipse\plugins\org.python.pydev.debug_1.4.7.2843\pysrc\pydevd.py,
 line 881, in module
   debugger.run(setup['file'], None, None)
  File C:\Program
 Files\eclipse\plugins\org.python.pydev.debug_1.4.7.2843\pysrc\pydevd.py,
 line 710, in run
   execfile(file, globals, locals) #execute the script
  File C:\Projekt\eclipse\Pyos\Program\Solitaire\solitaire.py, line 761,
 in module
   main()
  File C:\Projekt\eclipse\Pyos\Program\Solitaire\solitaire.py, line 80, in
 main
   if screen.main_loop(app):
  File C:\Projekt\eclipse\Pyos\System\widgets\gui.py, line 328, in
 main_loop
   = self.mouse_button_up(event, mob_pos, mousemove)
  File C:\Projekt\eclipse\Pyos\System\widgets\gui.py, line 573, in
 mouse_button_up
   if event.button == 1:
 AttributeError: 'long' object has no attribute 'button'






 elif event.type is MOUSEBUTTONUP:
mob_pos, mousemove, mouse_pos, hit_pos \
= self.mouse_button_up(event, mob_pos, mousemove)




 a ha

def mouse_button_up(self, event, mob_pos, mousemove):

  ''' handle mouse button up events'''
   mousebtn_event = False
   mouse_pos = event.pos
   widget, hit_pos = self.mouse_hit_widget(mouse_pos[0],
   mouse_pos[1])
   if widget is None or not widget.enabled:
   self.moving_object = None
   self.repeating_object = None
   self.last_over_drop_widget = None
   else:
   event_data = {'hit_pos':hit_pos, 'over_widget':widget}
   event_data['gui'] = self
   if widget and widget.exists('event_click_release_data'):
   event_data.update(widget.event_click_release_data)
   #InsideButton  (Left)
   if event.button == 1:


a ha
Well, from where comes event ?

--
claudio


Re: [pygame] event getting corrupted

2009-09-16 Thread Bo Jangeborg



a ha
Well, from where comes event ?


event = pyg_event.poll()

but note that a long can't have attributes and 13 lines above the
error point I do :

mouse_pos = event.pos

and it works at that time


Re: [pygame] event getting corrupted

2009-09-16 Thread Henrique Nakashima
def _mouse_hit_widget(wid, hit_pos_x, hit_pos_y, draged_widget=None,
dropreciever=False):

Shouldn't there be a self as first parameter?

On Wed, Sep 16, 2009 at 17:18, Bo Jangeborg b...@softwave.se wrote:

 a ha
 Well, from where comes event ?

 event = pyg_event.poll()

 but note that a long can't have attributes and 13 lines above the
 error point I do :

 mouse_pos = event.pos

 and it works at that time



Re: [pygame] event getting corrupted

2009-09-16 Thread Bo Jangeborg

Henrique Nakashima skrev:

def _mouse_hit_widget(wid, hit_pos_x, hit_pos_y, draged_widget=None,
dropreciever=False):

Shouldn't there be a self as first parameter?

  

No, its an independent function.

Bo)


Re: [pygame] event getting corrupted

2009-09-16 Thread claudio canepa
On Wed, Sep 16, 2009 at 5:18 PM, Bo Jangeborg b...@softwave.se wrote:


  a ha
 Well, from where comes event ?


 event = pyg_event.poll()

 but note that a long can't have attributes and 13 lines above the
 error point I do :

 mouse_pos = event.pos

 and it works at that time


pyg_event.poll is pygame.event.poll ?
If the only fountain for events were the pygame event queue, the traceback
coulnt happen:

a)
elif event.type is MOUSEBUTTONUP:
   - dont, raises, so is not a long

b) the flow comes to
_,_,_ = self.mouse_button_up(event, mob_pos, mousemove)

c)into method mouse_button_up event will become a local variable. That
variable is not assigned, at least in the code you show here.

d) the flow progress to the line
if event.button == 1:
where it raises AttributeError: 'long' object has no attribute 'button'

I see two possibilities here:

1. You snipped some code where event is assigned

2. ( wild possibility) the functions called in mouse_button_up will produce
a *second* call with other parameters to the same function, and that call
has a wrong event parameter. But, why the traceback not show additional
calls in that case?

--
claxo


Re: [pygame] event getting corrupted

2009-09-16 Thread Bo Jangeborg

claudio canepa skrev:



On Wed, Sep 16, 2009 at 5:18 PM, Bo Jangeborg b...@softwave.se 
mailto:b...@softwave.se wrote:



a ha
Well, from where comes event ?


event = pyg_event.poll()

but note that a long can't have attributes and 13 lines above the
error point I do :

mouse_pos = event.pos

and it works at that time


pyg_event.poll is pygame.event.poll ?

Yes

If the only fountain for events were the pygame event queue, the 
traceback coulnt happen:


a)
elif event.type is MOUSEBUTTONUP:
   - dont, raises, so is not a long

b) the flow comes to
_,_,_ = self.mouse_button_up(event, mob_pos, mousemove)

c)into method mouse_button_up event will become a local variable. That 
variable is not assigned, at least in the code you show here. 


d) the flow progress to the line
if event.button == 1:
where it raises AttributeError: 'long' object has no attribute 'button'

I see two possibilities here:

1. You snipped some code where event is assigned


No , you can see all the code, and event is not being assigned to.
2. ( wild possibility) the functions called in mouse_button_up will 
produce a *second* call with other parameters to the same function, 
and that call has a wrong event parameter. But, why the traceback not 
show additional calls in that case?

No , there are no such recursive calls to mouse_button_up
besides if the incoming event parameter was a long it should fail at 
mouse_pos = event.pos


My guess is that there is something over writing the event object at a 
lower level, possibly

caused by something I am doing.
Bo)


Re: [pygame] event getting corrupted

2009-09-16 Thread claudio canepa
On Wed, Sep 16, 2009 at 6:33 PM, Bo Jangeborg b...@softwave.se wrote:

 claudio canepa skrev:



 On Wed, Sep 16, 2009 at 5:18 PM, Bo Jangeborg b...@softwave.se mailto:
 b...@softwave.se wrote:


a ha
Well, from where comes event ?


event = pyg_event.poll()

but note that a long can't have attributes and 13 lines above the
error point I do :

mouse_pos = event.pos

and it works at that time


 pyg_event.poll is pygame.event.poll ?

 Yes

  If the only fountain for events were the pygame event queue, the traceback
 coulnt happen:

 a)
 elif event.type is MOUSEBUTTONUP:
   - dont, raises, so is not a long

 b) the flow comes to
 _,_,_ = self.mouse_button_up(event, mob_pos, mousemove)

 c)into method mouse_button_up event will become a local variable. That
 variable is not assigned, at least in the code you show here.
 d) the flow progress to the line
 if event.button == 1:
 where it raises AttributeError: 'long' object has no attribute 'button'

 I see two possibilities here:

 1. You snipped some code where event is assigned

  No , you can see all the code, and event is not being assigned to.

 2. ( wild possibility) the functions called in mouse_button_up will
 produce a *second* call with other parameters to the same function, and that
 call has a wrong event parameter. But, why the traceback not show additional
 calls in that case?

 No , there are no such recursive calls to mouse_button_up
 besides if the incoming event parameter was a long it should fail at
 mouse_pos = event.pos

 My guess is that there is something over writing the event object at a
 lower level, possibly
 caused by something I am doing.
 Bo)


well, there is code after mouse_pos = event_pos.
I would add a
assert type(event) is not long
after any function call in mouse_button_up to know when event is changed,
then drill down the offending function.

--
claxo


Re: [pygame] event getting corrupted

2009-09-16 Thread Bo Jangeborg



well, there is code after mouse_pos = event_pos.
I would add a 
assert type(event) is not long

after any function call in mouse_button_up to know when event is changed,
then drill down the offending function.

--
claxo

I have only gotten one more trace, and that after several hours of 
testing. That
time I got the same error but in another part of the code. I will try to 
find a pattern,

but I am not hopefull.

Bo)