I'm hitting the "bitmap can't be selected in another DC" assertion in bitmap.cpp
and after putting in some isOk()'s am none the wiser what's causing it.
I'm actually translating the distribution samples/drawing.cpp through another language binding to the wxw libraries
and because it's quite faithful to the original and the original runs fine (under g++ compiler),
it's strange.
the only thing I can think of is that because of the garbage collector of the translated-to language
there will be undeleted objects floating around potentially long after they have gone out of source scope.
or the sample is flawed and the translation somehow forces the issue!
here's the C++ snippet causing the problem (but only in the other language binding):
wxImage img(21, 21, false);
img.Clear(1);
wxBitmap bmp(img);
{
wxMemoryDC mdc(bmp); <--------------------------------- if this is skipped then no assertion
.....
}
bmp.SetMask(new wxMask(bmp, wxColour(1, 1, 1))); <------------- this is where the assert happens if the statement above is also executed
dc.DrawBitmap(bmp, -10, -10, true);
is there something incomplete about the handling of the bitmap?
"bitmap can't be selected in another DC" assertion Topic is solved
-
- Knows some wx things
- Posts: 28
- Joined: Tue Jun 19, 2018 1:05 pm
-
- Part Of The Furniture
- Posts: 4204
- Joined: Sun Jan 03, 2010 5:45 pm
Re: "bitmap can't be selected in another DC" assertion
The documentation clearly states
before using bmp?
Did you try that, i.e., calling...before performing any other operations on the bitmap data, the bitmap must be selected out of the memory DC
Code: Select all
mdc.SelectObject(wxNullBitmap);
-
- Knows some wx things
- Posts: 28
- Joined: Tue Jun 19, 2018 1:05 pm
Re: "bitmap can't be selected in another DC" assertion
ah yes!
I thought as it was written by a lead wxw developer in the day it must have been ok as it was a canonical example.
which contradicts my suspicion there was something with the original code
and then I found some other places where it was missing although there weren't any apparent problems at those sites.
but all good now.
thank you!
I thought as it was written by a lead wxw developer in the day it must have been ok as it was a canonical example.
which contradicts my suspicion there was something with the original code
and then I found some other places where it was missing although there weren't any apparent problems at those sites.
but all good now.
thank you!