Program stops with assert ""IsOk()"" failed in Draw(): invalid bitmap

9 views
Skip to first unread message

Jason Liam

unread,
Aug 20, 2021, 1:34:19 PMAug 20
to wx-u...@googlegroups.com
Hi i am trying to display an image inside a wxPanel but getting an assert described in the subject line. I am using almost the same code as given: https://wiki.wxwidgets.org/An_image_panel
wxWidgets 3.1.5 on Ubuntu 18.04 64 bit.
Also, using the return value from the statement image.LoadFile(m_file, m_format) is 1 as printed on the console.
The following is the content of the log file that is generated:
ASSERT INFO:
../src/gtk/bitmap.cpp(1375): assert ""IsOk()"" failed in Draw(): invalid bitmap

BACKTRACE:
[1] wxBitmap::Draw(_cairo*, int, int, bool, wxColour const*, wxColour const*) const
[2] wxGTKCairoDCImpl::DoDrawBitmap(wxBitmap const&, int, int, bool)
[3] wxDC::DrawBitmap(wxBitmap const&, int, int, bool)
[4] wxImagePanel::render(wxDC&)
[5] wxImagePanel::paintEvent(wxPaintEvent&)
[6] wxEvtHandler::ProcessEventIfMatchesId(wxEventTableEntryBase const&, wxEvtHandler*, wxEvent&)
[7] wxEvtHandler::SearchDynamicEventTable(wxEvent&)
[8] wxEvtHandler::TryHereOnly(wxEvent&)
[9] wxEvtHandler::ProcessEventLocally(wxEvent&)
[10] wxEvtHandler::ProcessEvent(wxEvent&)
[11] wxEvtHandler::SafelyProcessEvent(wxEvent&)
[12] wxWindow::GTKSendPaintEvents(_cairo*)
[13] g_closure_invoke
[14] g_signal_emit_valist
[15] g_signal_emit
[16] gtk_container_propagate_draw
[17] g_closure_invoke
[18] g_signal_emit_valist
[19] g_signal_emit
[20] gtk_container_propagate_draw
[21] g_closure_invoke
[22] g_signal_emit_valist
[23] g_signal_emit
[24] gtk_container_propagate_draw
[25] gtk_container_propagate_draw
[26] g_closure_invoke
[27] g_signal_emit_valist
[28] g_signal_emit
[29] gtk_container_propagate_draw
[30] g_closure_invoke
[31] g_signal_emit_valist
[32] g_signal_emit
[33] gtk_container_propagate_draw
[34] g_closure_invoke
[35] g_signal_emit_valist
[36] g_signal_emit
[37] gtk_container_propagate_draw
[38] g_closure_invoke
[39] g_signal_emit_valist
[40] g_signal_emit
[41] gtk_container_propagate_draw
[42] g_closure_invoke
[43] g_signal_emit_valist
[44] g_signal_emit
[45] gtk_container_propagate_draw
[46] g_closure_invoke
[47] g_signal_emit_valist
[48] g_signal_emit
[49] gtk_container_propagate_draw
[50] g_closure_invoke
[51] g_signal_emit_valist
[52] g_signal_emit
[53] gtk_container_propagate_draw
[54] g_closure_invoke
[55] g_signal_emit_valist
[56] g_signal_emit
[57] gtk_container_propagate_draw
[58] gtk_container_propagate_draw
[59] gtk_main_do_event
[60] g_closure_invoke
[61] g_signal_emit_valist
[62] g_signal_emit
[63] g_main_context_dispatch
[64] g_main_loop_run
[65] gtk_main
[66] wxGUIEventLoop::DoRun()
[67] wxEventLoopBase::Run()
[68] wxAppConsoleBase::MainLoop()
[69] wxEntry(int&, wchar_t**)
[70] main
[71] __libc_start_main
[72] _start

How should I resolve this? I have a wxPanel of a given size and it has a vertical sizer. Then I add this wxImagePanel instance to that vertical sizer.


Vadim Zeitlin

unread,
Aug 20, 2021, 1:39:19 PMAug 20
to wx-u...@googlegroups.com
On Fri, 20 Aug 2021 23:04:06 +0530 Jason Liam wrote:

JL> Hi i am trying to display an image inside a wxPanel but getting an assert
JL> described in the subject line.

Sorry for a maybe stupid question, but I'd genuinely like to understand:
is the assert message unclear? I.e. do you have any problem with
understanding what it says?

JL> https://wiki.wxwidgets.org/An_image_panel
JL> wxWidgets 3.1.5 on Ubuntu 18.04 64 bit.
JL> Also, using the return value from the statement image.LoadFile(m_file,
JL> m_format) is 1 as printed on the console.
JL> The following is the content of the log file that is generated:
JL> ASSERT INFO:
JL> ../src/gtk/bitmap.cpp(1375): assert ""IsOk()"" failed in Draw(): invalid
JL> bitmap
JL>
JL> BACKTRACE:
JL> [1] wxBitmap::Draw(_cairo*, int, int, bool, wxColour const*, wxColour
JL> const*) const
JL> [2] wxGTKCairoDCImpl::DoDrawBitmap(wxBitmap const&, int, int, bool)
JL> [3] wxDC::DrawBitmap(wxBitmap const&, int, int, bool)
JL> [4] wxImagePanel::render(wxDC&)
[...]
JL> How should I resolve this?

To me it seems absolutely clear that you need to avoid passing an invalid,
i.e. uninitialized, bitmap to DrawBitmap() that you call from your render()
function. But, again, I'd be curious to know if the assert message could
have been any more clear so that it would be clear to everybody.

Regards,
VZ

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

Jason Liam

unread,
Aug 20, 2021, 2:25:00 PMAug 20
to wx-u...@googlegroups.com
I passed the uninitialized(or default initialized) ``resized`` variable to the drawbitmap() function. First I was trying to see the result of the resizing example given in the wxWidget site but then decided to try out the "without resizing" example first. And in doing so i forgot to change the "resized" argument to the "image" argument. So after changing the argument to "image" the program works.
Reply all
Reply to author
Forward
0 new messages