[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[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? )

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 ) )"

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 ):                               
                               
                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_rect )


# 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) ]
           
    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.
   
    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
   
    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