Il Sat, 31 Jan 2004 13:03:18 +0100 Jouke Visser <jouke@...> ha scritto:
Hello,
> A few months ago I mentioned that my application (pVoice) crashed at
> shutdown. After some fooling around I found (at that time) that the
> error occurred at the line in Bitmap.XS where (within the DESTROY
> sub)
> it says 'delete THIS'.
> At that time (with wxPerl 0.15) removing that line seemed to
> 'solve' the
> problem (which of course, as Mattia mentioned) it didn't, but it
> just
> hid the error, probably causing more problems in the long run.
>
> I just installed a new PC, started with ActivePerl 5.8.2 (instead of
> 5.6.1 which I used when I first worked on the problem), downloaded
> and
> compiled wxWindows 2.4.2 with Unicode and MSLU, downloaded,
> modified (in
> the same way as described above) and compiled wxPerl 0.18, and now
> my
> 'solution' indeed causes a lot of problems, more specifically it has
> unpredictable effects on repainting the screen (some parts aren't
> updated, others are), but the crashing still doesn't happen :). No
> need
> to say that this is worse than an error when you shut down your
> application.
This is probably Windows running out of bitmap handles. Out of curiosity
which Windows wersion is it?
> However, I continued debugging, tried all kinds of things in the
> Wx::Bitmap::DESTROY XS subroutine (using code from other classes'
> DESTROY subroutines), but to no avail.
>
> Finally I re-read the documentation on wxBitmap, more specifically
> the
> part where it describes the destructor. There it says you shouldn't
> destroy a Bitmap that is used in a Memory Device Context. This may
> be
> the source of my problem. All of my Wx::Bitmap-s are used within a
> Memory Device Context!
>
> Now the question arises: How can I prevent these bitmaps to be
> destroyed
> if they're used within a Memory Device context??
> Is it possible to query if the Bitmap has been used in such a way
> within
> de DESTROY subroutine?
You can't determine in the destroy if the bitmap is still in use in some
memory DC. Your only option is to wrap your memory DC in some kind of data
structure and store the currently selected bitmap therein. Then
when you destroy the data structure you can call $dc->SelectObject( wxNullBitmap )
just before destroying the DC. This assumes you pass Wx::MemoryDC around.
In the simple case:
my $memdc = Wx::MemoryDC->new ...;
$memdc->SelectObject( $bmp );
# draw
$memdc->SelectObject( wxNullBitmap );
there is no need of the auxiliary data structure.
HTH
Mattia
|