[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Gnash-dev] What to do when a dynamic cast fail in librender?
From: |
Sandro Santilli |
Subject: |
Re: [Gnash-dev] What to do when a dynamic cast fail in librender? |
Date: |
Mon, 28 Apr 2014 09:11:20 +0200 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
While I also see a static_cast being probably safe I still like
the auto-testing feature of dynamic_cast. In this specific case
you could obtain the same effect of the explicit check and throw
by dynamically casting to a reference rather than to an object:
const bitmap_info_cairo& binfo = dynamic_cast<
const bitmap_info_cairo& >(*bm); // will throw bad_cast on failure
For testing them, see MovieTester::initTestingRenderers() in
testsuite/MovieTester.cpp. Right now only the first renderer
is used. A TODO comment envisions a multi-renderer testing but
mentions it'd take many changes (pre-rendered objects are stored
in parse state, which would basically trigger bad_cast exceptions
right where you're looking); still you might want to try setting
the order (or single renderer being tested) with some environment
variable or something like that.
--strk;
On Sun, Apr 20, 2014 at 02:46:11PM +0200, Bastiaan Jacques wrote:
> So far as I can tell, all CachedBitmap objects are created by the
> renderer (in createCachedBitmap()), and because that function always
> returns a bitmap_info_cairo, a dynamic_cast does not seem to be
> required. You can just replace it with a static_cast instead of
> checking the dynamic_cast.
>
> Bastiaan
>
> On Sun, 20 Apr 2014, Petter Reinholdtsen wrote:
>
> >diff --git a/librender/cairo/Renderer_cairo.cpp
> >b/librender/cairo/Renderer_cairo.cpp
> >index c597dd4..2e95686 100644
> >--- a/librender/cairo/Renderer_cairo.cpp
> >+++ b/librender/cairo/Renderer_cairo.cpp
> >@@ -299,6 +299,9 @@ struct StyleHandler :
> >boost::static_visitor<cairo_pattern_t*>
> >
> > const bitmap_info_cairo* binfo =
> > dynamic_cast<const bitmap_info_cairo*>(bm);
> >+ if (NULL == binfo) { // CID 1154657, binfo used below
> >+ throw std::bad_cast();
> >+ }
> >
> > cairo_matrix_t mat;
> > init_cairo_matrix(&mat, m);
>
> _______________________________________________
> Gnash-dev mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/gnash-dev
--
() ASCII ribbon campaign -- Keep it simple !
/\ http://strk.keybit.net/rants/ascii_mails.txt