Converting from wximage to wxbitmap

1,916 views
Skip to first unread message

alanf

unread,
Apr 24, 2011, 2:41:44 PM4/24/11
to wx-users
Hoping someone can help here as new to this.

First in the below, I have m_bitmap as a wxbitmap type previously
defined but not used.

Now in code I do the following lines (by the way the "test.jpg" file
does exist and looks good).


wxImage image1( wxT("test.jpg") ); // works fine

m_bitmap = wxBitmap(image1, -1); // bombs out with a segmentation
fault


note: wxInitAllImageHandlers(); was already execute during app
initialization.

Does anyone have any clues as to why this is happening?

Thanks in Advance for Help!

Vadim Zeitlin

unread,
Apr 24, 2011, 2:46:55 PM4/24/11
to wx-u...@googlegroups.com
On Sun, 24 Apr 2011 11:41:44 -0700 (PDT) alanf <alanfm...@gmail.com> wrote:

a> Hoping someone can help here as new to this.
a>
a> First in the below, I have m_bitmap as a wxbitmap type previously
a> defined but not used.
a>
a> Now in code I do the following lines (by the way the "test.jpg" file
a> does exist and looks good).
a>
a>
a> wxImage image1( wxT("test.jpg") ); // works fine

Are you sure? Did you check whether image1.IsOk() returns true?

a> m_bitmap = wxBitmap(image1, -1); // bombs out with a segmentation
a> fault

I don't see how could this crash, in the worst case it should create an
invalid bitmap. Are you sure you don't pass "&image1" to wxBitmap ctor or
something like this? Also notice that the trailing -1 is unnecessary, it's
the default anyhow.

If you don't find a problem in your code, please post at least the stack
dump at the moment of the crash. And ideally, as usual, a patch allowing to
reproduce the bug in a sample.

Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/

alanf

unread,
Apr 24, 2011, 3:42:37 PM4/24/11
to wx-users
Ok, Still a run time bomg, during debug it shows a seg fault and I've
changed the code a little to the below (by the way this is in a draw
procedure called during a wxprintout scenario after it displays the
print dialog):

wxImage image1( wxT("test.jpg") );
if (image1.Ok()) // returns ok
m_bitmap = wxBitmap(image1); // this bombs, see stack listing
below code
if (m_bitmap.Ok()) {
dc.SetBackground(*wxWHITE_BRUSH);
dc.Clear();
dc.DrawBitmap( o_bitmap, 10, 10 );

} //etc.

Stack Listing:
#0 00408347 wxObject::Ref(this=0x19c, clone=...) (../../src/common/
object.cpp:328)
#1 005CA04C wxObject::operator=(this=0x19c, other=...) (C:/wxWidgets/
include/wx/object.h:426)
#2 005A94D8 wxGDIObject::operator=(this=0x19c) (C:/wxWidgets/include/
wx/gdiobj.h:30)
#3 005A7370 wxGDIImage::operator=(this=0x19c) (C:/wxWidgets/include/wx/
msw/gdiimage.h:131)
#4 005C89F0 wxBitmap::operator=(this=0x19c) (C:/wxWidgets/include/wx/
msw/bitmap.h:38)
#5 004023AE ppFrame::Draw(this=0x0, dc=...) (C:\Users\alan\Desktop\APRI
\pp\ppMain.cpp:303)
#6 00402DE1 MyPrintout::DrawPageOne(this=0x28f2b4) (C:\Users\alan
\Desktop\APRI\pp\ppMain.cpp:534)
#7 00402C1B MyPrintout::OnPrintPage(this=0x28f2b4, page=1) (C:\Users
\alan\Desktop\APRI\pp\ppMain.cpp:425)
#8 004CB0B9 wxWindowsPrinter::Print(this=0x3ca8f00, parent=0x3ca4068,
printout=0x28f2b4, prompt=true) (../../src/msw/printwin.cpp:253)
#9 00437354 wxPrinter::Print(this=0x28f1c4, parent=0x3ca4068,
printout=0x28f2b4, prompt=true) (../../src/common/prntbase.cpp:408)
#10 00402A20 ppFrame::OnPrint(this=0x3ca4068) (C:\Users\alan\Desktop
\APRI\pp\ppMain.cpp:406)
#11 0040D994 wxAppConsole::HandleEvent (this=0x270b780,
handler=0x3ca4068, func=(void (wxEvtHandler::*)(wxEvtHandler *,
wxEvent &) (../../src/common/appbase.cpp:322)
#12 0043F91F wxEvtHandler::ProcessEventIfMatches(entry=...,
handler=0x3ca4068, event=...) (../../src/common/event.cpp:1239)
#13 0043FF0D wxEvtHandler::SearchDynamicEventTable(this=0x3ca4068,
event=...) (../../src/common/event.cpp:1421)
#14 0043FAAE wxEvtHandler::ProcessEvent(this=0x3ca4068, event=...)
(../../src/common/event.cpp:1297)
#15 0045513F wxWindowBase::TryParent(this=0x3ca49e8, event=...) (../../
src/common/wincmn.cpp:2661)
#16 0043FB46 wxEvtHandler::ProcessEvent(this=0x3ca49e8, event=...)
(../../src/common/event.cpp:1314)
#17 0042DEBE wxControl::ProcessCommand(this=0x3ca49e8, event=...)
(../../src/msw/control.cpp:334)
#18 0042EEB7 wxButton::SendClickEvent(this=0x3ca49e8) (../../src/msw/
button.cpp:476)
#19 0042EF22 wxButton::MSWCommand(this=0x3ca49e8, param=0) (../../src/
msw/button.cpp:505)
#20 0041FCD3 wxFrame::HandleCommand(this=0x3ca4068, id=100, cmd=0,
control=0x393131c) (../../src/msw/frame.cpp:958)
#21 00420035 wxFrame::MSWWindowProc(this=0x3ca4068, message=273,
wParam=100, lParam=59970332) (../../src/msw/frame.cpp:1051)
#22 00415A7C wxWndProc(hWnd=0xcb10a8, message=273, wParam=100,
lParam=59970332) (../../src/msw/window.cpp:2618)
#23 769B62FA USER32!OffsetRect() (C:\Windows\syswow64\user32.dll:??)
#24 00000000 0x00cb10a8 in strtod() (??:??)
#25 769B6D3A USER32!IsWindow() (C:\Windows\syswow64\user32.dll:??)
#26 0041599F wxWindowCreationHook::~wxWindowCreationHook(this=0x111,
__in_chrg=<value optimized out>) (../../src/msw/window.cpp:2591)
#27 00000000 0x00cb10a8 in strtod() (??:??)
#28 769B965E USER32!GetKeyboardLayoutNameW() (C:\Windows
\syswow64\user32.dll:??)
#29 00000000 0x00000000 in ??() (??:??)

On Apr 24, 11:46 am, Vadim Zeitlin <va...@wxwidgets.org> wrote:
>  application_pgp-signature_part
> < 1KViewDownload

Catalin

unread,
Apr 24, 2011, 5:04:54 PM4/24/11
to wx-u...@googlegroups.com
#5 004023AE    ppFrame::Draw(this=0x0, dc=...) (C:\Users\alan\Desktop\APRI
\pp\ppMain.cpp:303)

The 
ppFrame pointer there looks invalid.

Regards,
C

alanf

unread,
Apr 25, 2011, 5:06:43 PM4/25/11
to wx-users
Thanks guys, turns out I had defined a var in the wrong place.
Reply all
Reply to author
Forward
0 new messages