DC error

The application I have goes into an endless loop of these two errors. It is rare enough that it took me 6 months to even replicate what the user was reporting to me, so I figured I would post them here and see if anyone can point me in a direction to look for whats causing it.

Traceback (most recent call last):

File "C:\Documents and Settings\Owner\Desktop\openrpg dev\openrpg1\orpg\mapper

\map.py", line 286, in on_paint

self.layers['bg'].layerDraw(dc,scale,topleft,clientsize)

File "C:\Documents and Settings\Owner\Desktop\openrpg dev\openrpg1\orpg\mapper

\background.py", line 216, in layerDraw

dc.Blit(posx,posy,w-cr-cl,h-cb-ct,dc2,cl,ct)

File “C:\Python24\lib\site-packages\wx-2.6-msw-ansi\wx_gdi.py”, line 3240, in

Blit

return _gdi_.DC_Blit(*args, **kwargs)

wx._core.PyAssertionError: C++ assertion “wxAssertFailure” failed in …\src\m

sw\dc.cpp(2584): failed to get raw data in wxAlphaBlend

Traceback (most recent call last):

File "C:\Documents and Settings\Owner\Desktop\openrpg dev\openrpg1\orpg\mapper

\map.py", line 286, in on_paint

self.layers['bg'].layerDraw(dc,scale,topleft,clientsize)

File "C:\Documents and Settings\Owner\Desktop\openrpg dev\openrpg1\orpg\mapper

\background.py", line 138, in layerDraw

dc2.SelectObject(self.bg_bmp)

File “C:\Python24\lib\site-packages\wx-2.6-msw-ansi\wx_gdi.py”, line 4275, in

SelectObject

return _gdi_.MemoryDC_SelectObject(*args, **kwargs)

wx._core.PyAssertionError: C++ assertion “wxAssertFailure” failed in …\src\m

sw\dcmemory.cpp(133): Couldn’t select a bitmap into wxMemoryDC

Dj Gilcrease wrote:

The application I have goes into an endless loop of these two errors. It is rare enough that it took me 6 months to even replicate what the user was reporting to me, so I figured I would post them here and see if anyone can point me in a direction to look for whats causing it.

Traceback (most recent call last):
  File "C:\Documents and Settings\Owner\Desktop\openrpg dev\openrpg1\orpg\mapper
\map.py", line 286, in on_paint
    self.layers['bg'].layerDraw(dc,scale,topleft,clientsize)
  File "C:\Documents and Settings\Owner\Desktop\openrpg dev\openrpg1\orpg\mapper
\background.py", line 216, in layerDraw
    dc.Blit(posx,posy,w-cr-cl,h-cb-ct,dc2,cl,ct)
  File "C:\Python24\lib\site-packages\wx-2.6-msw-ansi\wx\_gdi.py", line 3240, in
Blit
    return _gdi_.DC_Blit(*args, **kwargs)
wx._core.PyAssertionError: C++ assertion "wxAssertFailure" failed in ..\..\src\m
sw\dc.cpp(2584): failed to get raw data in wxAlphaBlend

What kind of DC is dc2? Does it's Ok() return True?

Traceback (most recent call last):
  File "C:\Documents and Settings\Owner\Desktop\openrpg dev\openrpg1\orpg\mapper
\map.py", line 286, in on_paint
    self.layers['bg'].layerDraw(dc,scale,topleft,clientsize)
  File "C:\Documents and Settings\Owner\Desktop\openrpg dev\openrpg1\orpg\mapper
\background.py", line 138, in layerDraw
    dc2.SelectObject(self.bg_bmp)
  File "C:\Python24\lib\site-packages\wx-2.6-msw-ansi\wx\_gdi.py", line 4275, in
SelectObject
    return _gdi_.MemoryDC_SelectObject(*args, **kwargs)
wx._core.PyAssertionError: C++ assertion "wxAssertFailure" failed in ..\..\src\m
sw\dcmemory.cpp(133): Couldn't select a bitmap into wxMemoryDC

Does self.bg_bmp.Ok() return True? Is the bitmap already selected into another DC?

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

What kind of DC is dc2? Does it’s Ok() return True?

dc2 = wx.MemoryDC()
yes

Does self.bg_bmp.Ok() return True? Is the bitmap already selected into
another DC?

yes

I actually figured out what the problem was and fixed it. The problem was when I load a new BG image I first draw a “loading” image since it is pulling the background image off the internet it can sometimes take a while to pull down a large image. The issue was due to the fact that I was trying to draw the loading image at (0, 0) of the window, not just (0,0) of the viewable area. So if I has scrolled down and to the right before trying to load BG image the dc.Blit was getting something like

dc.Blit(500, 350, -500, -350, dc2, 500, 350)

and negative height and negative width dont work so well :slight_smile:

Here is the code for the section, maybe someone can point out ways it can be improved

def layerDraw(self, dc, scale, topleft, size):
    if self.bg_bmp == None:
        return False

    if not self.bg_bmp.Ok():
        return False

    dc2 = wx.MemoryDC

()
dc2.SelectObject(self.bg_bmp)

    topLeft = [int(topleft[0]/scale), int(topleft[1]/scale)]
    topRight = [int((topleft[0]+size[0]+1)/scale)+1, int((topleft[1]+size[1]+1)/scale)+1]

    bmpW = self.bg_bmp.GetWidth()
    bmpH = self.bg_bmp.GetHeight()

    x = 0
    y = 0

    if x < topLeft[0]:
        posx = topLeft[0]
        cl = topLeft[0]-x
    else:

        cl = 0
        posx = x

    if y < topLeft[1]:
        posy = topLeft[1]
        ct = topLeft[1]-y
    else:
        ct = 0
        posy = y

    if x+bmpW > topRight[0]:

        cr = x+bmpW-topRight[0]
    else:
        cr = 0

    if y+bmpH > topRight[1]:
        cb = y+bmpH-topRight[1]
    else:
        cb = 0

    newW = bmpW-cr-cl

    newH = bmpH-cb-ct

    if newW < 0:
        newW = 0
    if newH < 0:
        newH = 0

    dc.DrawBitmap(self.bg_bmp, posx, posy)
    dc.Blit(posx, posy, newW, newH, dc2, cl, ct)

    dc2.SelectObject(wx.NullBitmap)
    del dc2
    return True
···

On 10/19/06, Robin Dunn robin@alldunn.com wrote: