[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] I\'m getting BSOD while using PyGame.
> Hello, I\'m new to the list. ( Can I use HTML formatting to make it easier
> to
> read my code, or if this is text only, what\'s the best way to paste it? )
It is prefered plain text, not HTML.
If the code is long, usually is beter as an attachement, with the little parts you want to comment also into the body of mail. ( yours it not too long).
If the code is very long, and or needs media file, put a compresed archive somewhere and post the link.
> I\'ve started on a very basic game, right now all it does is blit tiles to
> the screen. I used a NumPy tutorial to create a 2D array to store tileID\'s
> for rendering. But running it, caused my computer to get a Blue Screen Of
> Death.
>
> The code was \"x = ones( ( 3, 4 ) )\"
Not enought context to tell wat was going . What is \'ones\' ?
> I was surprised because I was running my game in windowed mode, if I called
> blit() witih an invalid value, or accessed an array out of bounds, I
> thought
> it would at worst crash to desktop. I have also tried the game Snowballz, (
> it uses PyGame ) So my first guess was that it was NumPy that did it.
>
> I removed NumPy, creating my own basic 2D array class that seems to be
> working correctly stand-alone. I started to place it into my tile code, and
> I got the BSOD again. Now I know it\'s not NumPy. The wierd thing is even
> when it crashes, it seems to render the tileset at least once. Sometimes it
> had been running for a few seconds ( at 60 renders per second ), but once
> it
> was the very first render that crashed.
>
> What can I do to figure out what is causing the crash? I took a look at my
> computer -> event viewer and there were no errors or warnings.
>
> This is the code used to render the tileset. The rest of the code in the
> program I\'ve used in other tests I\'ve done, and they haven\'t crashed. The
> member .data() is an instance of my Array2D() class.
>
> Do you need any more information? ( I wasn\'t sure if I should attach the
> source code, or use one of those websites, or HTML formatting or what. )
>
> computer: win32 winXP, AMD Athlon 64 X2 Dual core 4600+
>
> Thanks,
> --
> jake
>
> [ code starts here ]
>
> # file: Map.py : snippet: class Map(), method .render()
> def render(self):
> \"\"\"render the map to screen\"\"\"
> for y in range( 0, self.tiles_y ):
> for x in range( 0, self.tiles_x):
you can spare the 0, when range has only one param it asumes begin at 0
> tile_id = self.data.get( x, y ) # will equal rand value
> 0..3
>
> dest_rect = pygame.Rect( x*self.tile_w, y*self.tile_h,
> self.tile_w, self.tile_h )
>
> src_rect = pygame.Rect( tile_id*self.tile_w,
> 0,
> self.tile_w, self.tile_h )
>
> # blit it
> self.screen.blit( self.tileset, dest_rect, src_rec )
seems ok, if self.tileset is initialized to a pygame surface anywhere
>
> # file: Array2D.py
> # code seems to work, but there could be a bug. Also wasn\'t sure if
> # return \'None\' is the correct thing to do on a failed .get()
>
> class Array2D:
> \"\"\"Simple 2D array without math operations.\"\"\"
>
> def __init__(self, cols, rows):
> \"\"\"Initialize array size [cols][rows]\"\"\"
> self.resize(cols, rows)
>
> def resize(self, cols, rows):
> \"\"\"resize array, works same way as constructor arguments\"\"\"
> # populate: None\'s
> self.__rows = rows
> self.__cols = cols
> self.__data = [ [None for row in range(rows)] for col in
> range(cols)
> ]
Why the names begins with \'__\' ? Usually its only used to hide members.
To the readers convey the sense \'We play tricks with this members, dont touch\'
> def get(self, x, y):
> \"\"\"get the value at the offset
>
> for now, if invalid bounds, then return None\"\"\"
> if self.validIndex( x, y ):
> return self.__data[x][y]
> return None # maybe throw exception? Haven\'t learned about them
> yet.
>
> def set(self, x, y, value):
> \"\"\"set the value at the offset
>
> for now, if invalid bounds, then return None\"\"\"
> if self.validIndex( x, y ):
> self.__data[x][y] = value
> # todo: else throw exception / error but doesn\'t need to halt
> program.
Returns None any time
> def validIndex( self, x, y ):
> \"\"\"Check if the index [x][y] is valid or not\"\"\"
> if x < 0: return False
> if y < 0: return False
> if x >= self.cols(): return False
> if y >= self.rows(): return False
> return True
Its ok, but you could use
def validIndex(self,x,y):
return (0<=x<self.__cols) and (0<=y<self.__rows)
> def cols(self):
> \"\"\"return number of cols\"\"\"
> return self.__cols
>
> def rows(self):
> \"\"\"return number of rows\"\"\"
> return self.__rows
>
> def Print(self):
> \"\"\"output data to console for testing\"\"\"
> print \"\\nArray2D = {\"
> for y in range( 0, self.rows() ):
> for x in range( 0, self.cols() ):
> print \"\\t\", self.get(x, y), \", \",
>
> print \"\"
> print \"}\\n\"
>
> --
> Jake
>
This class seems to perform as desired, but in Python style seems unnecesary:
what about
#function)
def makeMatrix(cols,rows):
return [ [None for row in range(rows)] for col in range(cols) ]
m=makeMatrix(4,5) #create a matrix
# len(m) is cols
# len(m[0]) is rows
m[0][0] =\'0_0\'
m[0][1] =\'0_1\'
m[1][0] =\'1_0\'
print m
__________________________________
Registrate desde http://servicios.arnet.com.ar/registracion/registracion.asp?origenid=9 y participá de todos los beneficios del Portal Arnet.