diff --git a/src/emu/emucore.c b/src/emu/emucore.c index d4c970223fe..a3cf0d660cc 100644 --- a/src/emu/emucore.c +++ b/src/emu/emucore.c @@ -12,16 +12,14 @@ #include "emu.h" -void bitch_bad_cast(const std::type_info &src_type, const std::type_info &dst_type) +void report_bad_cast(const std::type_info &src_type, const std::type_info &dst_type) { - fprintf(stderr, "Error: bad downcast<> or device<>. Tried to convert a %s to a %s, which are incompatible.\n", + throw emu_fatalerror("Error: bad downcast<> or device<>. Tried to convert a %s to a %s, which are incompatible.\n", src_type.name(), dst_type.name()); - abort(); } -void bitch_bad_device_cast(const device_t *dev, const std::type_info &dst_type) +void report_bad_device_cast(const device_t *dev, const std::type_info &dst_type) { - fprintf(stderr, "Error: bad downcast<> or device<>. Tried to convert the device %s of type %s to a %s, which are incompatible.\n", + throw emu_fatalerror("Error: bad downcast<> or device<>. Tried to convert the device %s of type %s to a %s, which are incompatible.\n", dev->tag(), dev->name(), dst_type.name()); - abort(); } diff --git a/src/emu/emucore.h b/src/emu/emucore.h index 88fb025dc41..3d1dd5a953c 100644 --- a/src/emu/emucore.h +++ b/src/emu/emucore.h @@ -334,20 +334,21 @@ private: class device_t; -void bitch_bad_cast(const std::type_info &src_type, const std::type_info &dst_type); -void bitch_bad_device_cast(const device_t *dev, const std::type_info &dst_type); +void report_bad_cast(const std::type_info &src_type, const std::type_info &dst_type); +void report_bad_device_cast(const device_t *dev, const std::type_info &dst_type); // template function for casting from a base class to a derived class that is checked // in debug builds and fast in release builds template inline _Dest downcast(_Source *src) { -#ifndef NDEBUG - if(dynamic_cast<_Dest>(src) != src) { - if(dynamic_cast(src)) - bitch_bad_device_cast(dynamic_cast(src), typeid(_Dest)); +#ifdef MAME_DEBUG + if (dynamic_cast<_Dest>(src) != src) + { + if (dynamic_cast(src) != NULL) + report_bad_device_cast(dynamic_cast(src), typeid(_Dest)); else - bitch_bad_cast(typeid(src), typeid(_Dest)); + report_bad_cast(typeid(src), typeid(_Dest)); } #endif return static_cast<_Dest>(src); @@ -356,12 +357,13 @@ inline _Dest downcast(_Source *src) template inline _Dest downcast(_Source &src) { -#ifndef NDEBUG - if(&dynamic_cast<_Dest>(src) != &src) { - if(dynamic_cast(&src)) - bitch_bad_device_cast(dynamic_cast(&src), typeid(_Dest)); +#ifdef MAME_DEBUG + if (&dynamic_cast<_Dest>(src) != &src) + { + if (dynamic_cast(&src) != NULL) + report_bad_device_cast(dynamic_cast(&src), typeid(_Dest)); else - bitch_bad_cast(typeid(src), typeid(_Dest)); + report_bad_cast(typeid(src), typeid(_Dest)); } #endif return static_cast<_Dest>(src);