Mailing List Archive

Problems with dynamic_cast
In Android build with latest ndk -

In standardsettings.cpp
auto dce = dynamic_cast<DialogCompletionEvent*>(event)
the dynamic cast returns null even when the correct type is passed. I
have changed that code to use a static cast in the Android case.

To see whether all dynamic_casts are failing I set a breakpoint at
another dynamic_cast while running in Android and it is working correctly

tv_play.cpp:3952
auto *qke = dynamic_cast<QKeyEvent*>(e);
After that line is run the value of qke is not null, it is the same as
the value of e.

This one is executed whenever you press a remote button while playing a
recording.

So it is not a general failure, there must be some specific condition
that affects standardsettings.cpp, or some corruption of data.

Peter

_______________________________________________
mythtv-dev mailing list
mythtv-dev@mythtv.org
http://lists.mythtv.org/mailman/listinfo/mythtv-dev
http://wiki.mythtv.org/Mailing_List_etiquette
MythTV Forums: https://forum.mythtv.org
Re: Problems with dynamic_cast [ In reply to ]
What about doing
auto *dce = dynamic_cast...

Sent from Nine
________________________________
From: Peter Bennett
Sent: Tuesday, 28 January 2020 21:24
To: Mark Spieth; David Engel; Development of MythTV
Subject: [mythtv] Problems with dynamic_cast

In Android build with latest ndk -

In standardsettings.cpp
auto dce = dynamic_cast<DialogCompletionEvent*>(event)
the dynamic cast returns null even when the correct type is passed. I
have changed that code to use a static cast in the Android case.

To see whether all dynamic_casts are failing I set a breakpoint at
another dynamic_cast while running in Android and it is working correctly

tv_play.cpp:3952
auto *qke = dynamic_cast<QKeyEvent*>(e);
After that line is run the value of qke is not null, it is the same as
the value of e.

This one is executed whenever you press a remote button while playing a
recording.

So it is not a general failure, there must be some specific condition
that affects standardsettings.cpp, or some corruption of data.

Peter

_______________________________________________
mythtv-dev mailing list
mythtv-dev@mythtv.org
http://lists.mythtv.org/mailman/listinfo/mythtv-dev
http://wiki.mythtv.org/Mailing_List_etiquette
MythTV Forums: https://forum.mythtv.org
Re: Problems with dynamic_cast [ In reply to ]
On 1/28/20 5:06 PM, jyavenard@gmail.com wrote:
> What about doing
> auto *dce = dynamic_cast...
>
> ------------------------------------------------------------------------
That syntax makes more sense to me and we did change it to *dce but it
still does not work. dce always gets set to null, even when the object
is of matching type.

Peter
Re: Problems with dynamic_cast [ In reply to ]
Is it failing when things are allocated in one shared library and this dynamic cast done in another library or executable? I seem to remember some issues with that on Android in the past. All works fine within the same shared library.



John



From: mythtv-dev <mythtv-dev-bounces@mythtv.org> On Behalf Of Peter Bennett
Sent: 28 January 2020 22:11
To: mythtv-dev@mythtv.org
Subject: Re: [mythtv] Problems with dynamic_cast





On 1/28/20 5:06 PM, jyavenard@gmail.com <mailto:jyavenard@gmail.com> wrote:

What about doing
auto *dce = dynamic_cast...



_____

That syntax makes more sense to me and we did change it to *dce but it still does not work. dce always gets set to null, even when the object is of matching type.

Peter
Re: Problems with dynamic_cast [ In reply to ]
On 29/01/2020 9:25 am, john.p.harvey@btinternet.com wrote:
>
> Is it failing when things are allocated in one shared library and this
> dynamic cast done in another library or executable? I seem to remember
> some issues with that on Android in the past. All works fine within
> the same shared library.
>
> John
>
The base class is in libQt5Core.so shared library, the derived class is
constructed in another libmythui.so.

Dynamic_cast is in the libmyth.so, passed as base class ptr defined in
libQt5Core.so via postEvent and is implicitly downcast.

Mark
Re: Problems with dynamic_cast [ In reply to ]
On Tue, 2020-01-28 at 22:25 +0000, john.p.harvey@btinternet.com wrote:
> Is it failing when things are allocated in one shared library and
> this dynamic cast done in another library or executable? I seem to
> remember some issues with that on Android in the past. All works fine
> within the same shared library.

Hmm. DialogCompletionEvent is defined in libmythui, and
standardsettings.cpp is in libmyth.

David


> John
>
> From: mythtv-dev <mythtv-dev-bounces@mythtv.org> On Behalf Of Peter
> Bennett
> Sent: 28 January 2020 22:11
> To: mythtv-dev@mythtv.org
> Subject: Re: [mythtv] Problems with dynamic_cast
>
>
>
> On 1/28/20 5:06 PM, jyavenard@gmail.com wrote:
> > What about doing
> > auto *dce = dynamic_cast...
> >
>
> That syntax makes more sense to me and we did change it to *dce but
> it still does not work. dce always gets set to null, even when the
> object is of matching type.
>
> Peter
> _______________________________________________
> mythtv-dev mailing list
> mythtv-dev@mythtv.org
> http://lists.mythtv.org/mailman/listinfo/mythtv-dev
> http://wiki.mythtv.org/Mailing_List_etiquette
> MythTV Forums: https://forum.mythtv.org

_______________________________________________
mythtv-dev mailing list
mythtv-dev@mythtv.org
http://lists.mythtv.org/mailman/listinfo/mythtv-dev
http://wiki.mythtv.org/Mailing_List_etiquette
MythTV Forums: https://forum.mythtv.org
Re: Problems with dynamic_cast [ In reply to ]
On 28/01/2020 22:25, john.p.harvey@btinternet.com wrote:

> Is it failing when things are allocated in one shared library and this
> dynamic cast done in another library or executable? I seem to remember
> some issues with that on Android in the past. All works fine within
> the same shared library.
>
> John
>
>

Yeah I've seem this same problem in MythTV on linux before as well some
time ago though.

https://lists.gt.net/mythtv/firehose/508449#508449


Paul H.
Re: Problems with dynamic_cast [ In reply to ]
I have another instrumented test if someone can test it. Otherwise it
will have to wait for approx 7 hours when I get home.

http://digivation.com.au/debian/mythfrontend-20200129-arm64-v31-Pre-1828-g4b2272287a-dirty.apk

use adb logcat | tee x.log

The test is

settings -> video -> playback -> change profile to something else

Then email me with the last bit of the log where it mentions dce especially.

Mark

_______________________________________________
mythtv-dev mailing list
mythtv-dev@mythtv.org
http://lists.mythtv.org/mailman/listinfo/mythtv-dev
http://wiki.mythtv.org/Mailing_List_etiquette
MythTV Forums: https://forum.mythtv.org
Re: Problems with dynamic_cast [ In reply to ]
On Wed, Jan 29, 2020 at 11:24:45AM +1100, Mark Spieth wrote:
> I have another instrumented test if someone can test it. Otherwise it will
> have to wait for approx 7 hours when I get home.
>
> http://digivation.com.au/debian/mythfrontend-20200129-arm64-v31-Pre-1828-g4b2272287a-dirty.apk
>
> use adb logcat | tee x.log
>
> The test is
>
> settings -> video -> playback -> change profile to something else
>
> Then email me with the last bit of the log where it mentions dce especially.

01-28 20:30:23.656 32532 32555 I mfe : mythdialogbox.cpp:452:SendEvent post dce:140920670464 dce_e:P21DialogCompletionEvent:140813528616 ev:140920670464 ev_e:P6QEvent:140813528641
01-28 20:30:23.656 32532 32555 I mfe : standardsettings.cpp:815:customEvent evtype:65518
01-28 20:30:23.656 32532 32555 I mfe : standardsettings.cpp:832:customEvent dce:0 e:P6QEvent:140818516747 qe:P6QEvent:140818516747 d2:P21DialogCompletionEvent:140818516722

I'll send you the whole log privately if you want it.

David
--
David Engel
david@istwok.net
_______________________________________________
mythtv-dev mailing list
mythtv-dev@mythtv.org
http://lists.mythtv.org/mailman/listinfo/mythtv-dev
http://wiki.mythtv.org/Mailing_List_etiquette
MythTV Forums: https://forum.mythtv.org
Re: Problems with dynamic_cast [ In reply to ]
On 29/01/2020 1:35 pm, David Engel wrote:
> On Wed, Jan 29, 2020 at 11:24:45AM +1100, Mark Spieth wrote:
>> I have another instrumented test if someone can test it. Otherwise it will
>> have to wait for approx 7 hours when I get home.
>>
>> http://digivation.com.au/debian/mythfrontend-20200129-arm64-v31-Pre-1828-g4b2272287a-dirty.apk
>>
>> use adb logcat | tee x.log
>>
>> The test is
>>
>> settings -> video -> playback -> change profile to something else
>>
>> Then email me with the last bit of the log where it mentions dce especially.
> 01-28 20:30:23.656 32532 32555 I mfe : mythdialogbox.cpp:452:SendEvent post dce:140920670464 dce_e:P21DialogCompletionEvent:140813528616 ev:140920670464 ev_e:P6QEvent:140813528641
> 01-28 20:30:23.656 32532 32555 I mfe : standardsettings.cpp:815:customEvent evtype:65518
> 01-28 20:30:23.656 32532 32555 I mfe : standardsettings.cpp:832:customEvent dce:0 e:P6QEvent:140818516747 qe:P6QEvent:140818516747 d2:P21DialogCompletionEvent:140818516722
>
> I'll send you the whole log privately if you want it.
>
Well thats interesting. sender newed DialogCompletionEvent type is
different from one in libmyth. no wonder it doesnt work.

now to try -rdynamic as a SO post suggests.

Mark

_______________________________________________
mythtv-dev mailing list
mythtv-dev@mythtv.org
http://lists.mythtv.org/mailman/listinfo/mythtv-dev
http://wiki.mythtv.org/Mailing_List_etiquette
MythTV Forums: https://forum.mythtv.org
Re: Problems with dynamic_cast [ In reply to ]
On 1/29/2020 3:02 PM, Mark Spieth wrote:
>
> On 29/01/2020 1:35 pm, David Engel wrote:
>> On Wed, Jan 29, 2020 at 11:24:45AM +1100, Mark Spieth wrote:
>>> I have another instrumented test if someone can test it. Otherwise
>>> it will
>>> have to wait for approx 7 hours when I get home.
>>>
>>> http://digivation.com.au/debian/mythfrontend-20200129-arm64-v31-Pre-1828-g4b2272287a-dirty.apk
>>>
>>>
>>> use adb logcat | tee x.log
>>>
>>> The test is
>>>
>>> settings -> video -> playback -> change profile to something else
>>>
>>> Then email me with the last bit of the log where it mentions dce
>>> especially.
>> 01-28 20:30:23.656 32532 32555 I mfe     :
>> mythdialogbox.cpp:452:SendEvent  post dce:140920670464
>> dce_e:P21DialogCompletionEvent:140813528616 ev:140920670464
>> ev_e:P6QEvent:140813528641
>> 01-28 20:30:23.656 32532 32555 I mfe     :
>> standardsettings.cpp:815:customEvent  evtype:65518
>> 01-28 20:30:23.656 32532 32555 I mfe     :
>> standardsettings.cpp:832:customEvent  dce:0 e:P6QEvent:140818516747
>> qe:P6QEvent:140818516747 d2:P21DialogCompletionEvent:140818516722
>>
>> I'll send you the whole log privately if you want it.
>>
> Well thats interesting. sender newed DialogCompletionEvent type is
> different from one in libmyth. no wonder it doesnt work.
>
> now to try -rdynamic as a SO post suggests.

Found it!

The key is

https://android.googlesource.com/platform/ndk/+/master/docs/user/common_problems.md#rtti_exceptions-not-working-across-library-boundaries

I added a virtual destructor to DialogCompletionEvent and that one
works. Now to do it for the rest that use dynamic_cast. Ive left
-rdynamic in place as others have said its necessary.

It works as it forces a vtable to exist only in the so that has the
virtual function defined. Every subclass needs at least one defined non
inline virtual function.

Will push stuff before bed. Watching to do.

Mark
_______________________________________________
mythtv-dev mailing list
mythtv-dev@mythtv.org
http://lists.mythtv.org/mailman/listinfo/mythtv-dev
http://wiki.mythtv.org/Mailing_List_etiquette
MythTV Forums: https://forum.mythtv.org
Re: Problems with dynamic_cast [ In reply to ]
On Thu, Jan 30, 2020 at 12:05:25AM +1100, Mark Spieth wrote:
> On 1/29/2020 3:02 PM, Mark Spieth wrote:
> >
> > On 29/01/2020 1:35 pm, David Engel wrote:
> > > On Wed, Jan 29, 2020 at 11:24:45AM +1100, Mark Spieth wrote:
> > > > I have another instrumented test if someone can test it.
> > > > Otherwise it will
> > > > have to wait for approx 7 hours when I get home.
> > > >
> > > > http://digivation.com.au/debian/mythfrontend-20200129-arm64-v31-Pre-1828-g4b2272287a-dirty.apk
> > > >
> > > >
> > > > use adb logcat | tee x.log
> > > >
> > > > The test is
> > > >
> > > > settings -> video -> playback -> change profile to something else
> > > >
> > > > Then email me with the last bit of the log where it mentions dce
> > > > especially.
> > > 01-28 20:30:23.656 32532 32555 I mfe???? :
> > > mythdialogbox.cpp:452:SendEvent? post dce:140920670464
> > > dce_e:P21DialogCompletionEvent:140813528616 ev:140920670464
> > > ev_e:P6QEvent:140813528641
> > > 01-28 20:30:23.656 32532 32555 I mfe???? :
> > > standardsettings.cpp:815:customEvent? evtype:65518
> > > 01-28 20:30:23.656 32532 32555 I mfe???? :
> > > standardsettings.cpp:832:customEvent? dce:0 e:P6QEvent:140818516747
> > > qe:P6QEvent:140818516747 d2:P21DialogCompletionEvent:140818516722
> > >
> > > I'll send you the whole log privately if you want it.
> > >
> > Well thats interesting. sender newed DialogCompletionEvent type is
> > different from one in libmyth. no wonder it doesnt work.
> >
> > now to try -rdynamic as a SO post suggests.
>
> Found it!
>
> The key is
>
> https://android.googlesource.com/platform/ndk/+/master/docs/user/common_problems.md#rtti_exceptions-not-working-across-library-boundaries
>
> I added a virtual destructor to DialogCompletionEvent and that one works.
> Now to do it for the rest that use dynamic_cast. Ive left -rdynamic in place
> as others have said its necessary.
>
> It works as it forces a vtable to exist only in the so that has the virtual
> function defined. Every subclass needs at least one defined non inline
> virtual function.

I poked around last night but didn't get anywhere. Glad you found it.
Good work. My big question is why doesn't the compiler complain in
such cases? Or does it and we just missed it?

David

> Will push stuff before bed. Watching to do.

--
David Engel
david@istwok.net
_______________________________________________
mythtv-dev mailing list
mythtv-dev@mythtv.org
http://lists.mythtv.org/mailman/listinfo/mythtv-dev
http://wiki.mythtv.org/Mailing_List_etiquette
MythTV Forums: https://forum.mythtv.org
Re: Problems with dynamic_cast [ In reply to ]
On 30/01/2020 2:18 am, David Engel wrote:
> On Thu, Jan 30, 2020 at 12:05:25AM +1100, Mark Spieth wrote:
>> On 1/29/2020 3:02 PM, Mark Spieth wrote:
>>> On 29/01/2020 1:35 pm, David Engel wrote:
>>>> On Wed, Jan 29, 2020 at 11:24:45AM +1100, Mark Spieth wrote:
>>>>> I have another instrumented test if someone can test it.
>>>>> Otherwise it will
>>>>> have to wait for approx 7 hours when I get home.
>>>>>
>>>>> http://digivation.com.au/debian/mythfrontend-20200129-arm64-v31-Pre-1828-g4b2272287a-dirty.apk
>>>>>
>>>>>
>>>>> use adb logcat | tee x.log
>>>>>
>>>>> The test is
>>>>>
>>>>> settings -> video -> playback -> change profile to something else
>>>>>
>>>>> Then email me with the last bit of the log where it mentions dce
>>>>> especially.
>>>> 01-28 20:30:23.656 32532 32555 I mfe     :
>>>> mythdialogbox.cpp:452:SendEvent  post dce:140920670464
>>>> dce_e:P21DialogCompletionEvent:140813528616 ev:140920670464
>>>> ev_e:P6QEvent:140813528641
>>>> 01-28 20:30:23.656 32532 32555 I mfe     :
>>>> standardsettings.cpp:815:customEvent  evtype:65518
>>>> 01-28 20:30:23.656 32532 32555 I mfe     :
>>>> standardsettings.cpp:832:customEvent  dce:0 e:P6QEvent:140818516747
>>>> qe:P6QEvent:140818516747 d2:P21DialogCompletionEvent:140818516722
>>>>
>>>> I'll send you the whole log privately if you want it.
>>>>
>>> Well thats interesting. sender newed DialogCompletionEvent type is
>>> different from one in libmyth. no wonder it doesnt work.
>>>
>>> now to try -rdynamic as a SO post suggests.
>> Found it!
>>
>> The key is
>>
>> https://android.googlesource.com/platform/ndk/+/master/docs/user/common_problems.md#rtti_exceptions-not-working-across-library-boundaries
>>
>> I added a virtual destructor to DialogCompletionEvent and that one works.
>> Now to do it for the rest that use dynamic_cast. Ive left -rdynamic in place
>> as others have said its necessary.
>>
>> It works as it forces a vtable to exist only in the so that has the virtual
>> function defined. Every subclass needs at least one defined non inline
>> virtual function.
> I poked around last night but didn't get anywhere. Glad you found it.
> Good work. My big question is why doesn't the compiler complain in
> such cases? Or does it and we just missed it?
>
> David

Others have asked the same question.

How can it complain when it doesn't know that there is a shared object
at compile time vs link time?

Where is the master/source of truth vtable/typeinfo when it can be
optimized out?

clang must do more optimisation than g++ and this is why we are seeing
it now.

Has anyone ever compiled the linux version with clang? I expect similar
issues.

We could try different linkers (BFD or gold vs llvm-ld) but if the
compiler does not put in appropriate symbols that may not be possible.
Because all virtual functions are in the header there is no single
source of truth at compile time (though there is at link time). A job
for smarter people than me.

I have pushed the final change to expose locked vtables in affected
classes. There should not be any more. Some already had object locked
virtual functions so they did not need to be updated.

Mark

_______________________________________________
mythtv-dev mailing list
mythtv-dev@mythtv.org
http://lists.mythtv.org/mailman/listinfo/mythtv-dev
http://wiki.mythtv.org/Mailing_List_etiquette
MythTV Forums: https://forum.mythtv.org