Hi, did you find out the reason of the problem?
четверг, 29 марта 2018 г., 15:21:32 UTC+3 пользователь Vylsain написал:
>
> Ok, thanks for your answer. I will look for the problem somewhere else
> then. ;)
>
> On Tuesday, March 27, 2018 at 2:24:38 PM UTC+2, Vylsain wrote:
>>
>> Hi,
>>
>> I'm trying to implement polymorphism with protobuf. I want to have
>> several levels, each new level extending the previous one.
>> I have a crash when calling MutableExtension.
>>
>> My .proto file looks like :
>>
>>
>> *package aapb;*
>>
>> *message A*
>> *{*
>> * optional int32 fooA = 1;*
>>
>> * extensions 1000 to max;*
>> *}*
>>
>> *message B*
>> *{*
>> * extend A*
>> * {*
>>
>> *optional B b = 1000;*
>>
>> * }*
>>
>> * optional int32 fooB = 1;*
>>
>> * extensions 1000 to max;*
>> *}*
>>
>> *message C*
>> *{*
>> * extend B*
>>
>> * {*
>>
>> *optional C c = 1000;*
>>
>> * }*
>>
>> * optional int32 fooC = 1;*
>>
>> * extensions 1000 to max;*
>> *}*
>>
>>
>>
>> On the C++ side, I have the corresponding classes :
>>
>> *class A*
>> *{*
>> * virtual void WriteExtensions(aapb::A *pA){}*
>> *}*
>>
>> *class B : public A*
>> *{*
>> * virtual void WriteExtensions(aapb::A *pA)*
>> * {*
>> * aapb::B* pB = pA->MutableExtension(aapb::B::b);*
>> * pB->fooB = 1;*
>> * WriteExtensions(pB);*
>> * }*
>>
>> * virtual void WriteExtensions(aapb::B *pB){}*
>> *}*
>>
>> *class C : public B*
>> *{*
>> * virtual void WriteExtensions(aapb::B *pB)*
>> * {*
>> * aapb::C* pC = pB->MutableExtension(aapb::C::c);
>> //crash happens here*
>> * pC->fooC = 2;*
>> * }*
>> *}*
>>
>> Then, in my program I just create shared_ptr<C> and aapb::A objects and
>> call C's WriteExtensions method with aapb::A reference as an argument.
>> It works as expected in Debug and I retrieve the correct data when
>> reading the file.
>> But in Release, I have a segfault when writing the file, when it reaches
>> the MutableExtension call of the C class.
>> To be more precise, the segfault happens on the call of
>> *google::protobuf::internal::ExtensionSet::MutableMessage(int,
>> unsigned char, google::protobuf::MessageLite const&,
>> google::protobuf::FieldDescriptor const*) ()*
>>
>> I'm struggling to see where the problem is coming from and wanted to make
>> sure the protobuf part is correct before I look for other causes.
>> So you guys see anything wrong in the way I use this ?
>>
>> Thanks
>>
>>
>>
--
You received this message because you are subscribed to the Google Groups
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.