Segmentation violation in converting TMessage to a class

Hi,

I’m working on development a framework using ROOT I/O.
And I have some difficulties to convert from TMessage to user-defined class.

Here’s my test code to convert from TMessage to user-defined class

[code]MyClass* outevt = new MyClass();
outevt->Print();
msg->Print();

outevt = (MyEvent*)msg->ReadObjectAny(MyEvent::Class());
outevt->Print();[/code]

And here’s the result including error

[code]OBJ: MyEvent MyEvent Simple event class
OBJ: TMessage TMessage Message buffer class

*** Break *** segmentation violation
Using host libthread_db library “/lib/tls/libthread_db.so.1”.
Attaching to program: /proc/5225/exe, process 5225
[Thread debugging using libthread_db enabled]
[New Thread -1218586048 (LWP 5225)]
0x04f8051e in __waitpid_nocancel () from /lib/tls/libc.so.6
Thread 1 (Thread -1218586048 (LWP 5225)):
#0 0x04f8051e in __waitpid_nocancel () from /lib/tls/libc.so.6
#1 0x04f151d4 in do_system () from /lib/tls/libc.so.6
#2 0x00232d7f in system () from /lib/tls/libpthread.so.0
#3 0x004c36f9 in TUnixSystem::Exec () from /root/lib/libCore.so
#4 0x004c3b29 in TUnixSystem::StackTrace ()
from /root/lib/libCore.so
#5 0x004c1c1f in TUnixSystem::DispatchSignals ()
from /root/lib/libCore.so
#6 0x004bfd17 in SigHandler () from /root/lib/libCore.so
#7 0x004c635b in sighandler () from /root/lib/libCore.so
#8
#9 0x0804e47e in main (argc=2, argv=0xbfffc174) at main.cc:94[/code]

Is there any wrong syntax to use TMessage::ReadObjectAny() function?
After using it, I can’t access any member function of MyClass.
(When I try to use, it makes segmentation violation)

I need your help please.

Best Regards,

How was the TMessage filled?
Did you get check that outevt is non zero?

Philippe

Hi Philippe,

Thanks for replying me again.

I filled TMessage as below

And I also checked the lengths of TMessage are non-zero by using TMessage::Length() function.
(And I also used TMessage::SetReadMode())

I think

doesn’t work correctly but I have no idea how I can fix that.

Best Regards,

Humm … Is the TMessage create and filled in the same session as the read?
In which case you are most likely missing:msg.Reset(); // Start at the beginning msg.SetReadMode();

Cheers,
Philippe

I didn’t write them in my question post but I used TMessage::Reset() and TMessage::SetReadMode() both actually.

Does anyone have a example using TMessage with user-defined class?

Best Regards,

[quote]Does anyone have a example using TMessage with user-defined class? [/quote]See several example of TMessage usage in $ROOTSYS/tutorials/net

Also I assume you did generate the dictionary for your Event class.

If you send a complete example reproducing your problem I will take a look.

Cheers,
Philippe.