[Android NDK]App crashed when invoke ParseFromArray() of protobuf

this’s my proto file:

message role_data {
	required string  id					= 1;	
	required int32  atk					= 2;	
	required int32  hp_max				= 3;	
	required int32  mp_max				= 4;	
}

this’s my testing code:

HProtocol::role_data role;

UE_LOG(LogTemp, Display, TEXT("[PVPModule::OnCustomMatchReturn] 111111111"));

role.set_id("wag");
UE_LOG(LogTemp, Display, TEXT("[PVPModule::OnCustomMatchReturn] 2222222222"));

role.set_atk(999);
UE_LOG(LogTemp, Display, TEXT("[PVPModule::OnCustomMatchReturn] 333333333"));

role.set_hp_max(888);
UE_LOG(LogTemp, Display, TEXT("[PVPModule::OnCustomMatchReturn] 44444444"));

role.set_mp_max(777);
UE_LOG(LogTemp, Display, TEXT("[PVPModule::OnCustomMatchReturn] 5555"));

int BSize = role.ByteSize();
char* buf = new char[BSize];
UE_LOG(LogTemp, Display, TEXT("[PVPModule::OnCustomMatchReturn] 6666"));

role.SerializeToArray(buf, BSize);
UE_LOG(LogTemp, Display, TEXT("[PVPModule::OnCustomMatchReturn] 777"));

HProtocol::role_data role2;
UE_LOG(LogTemp, Display, TEXT("[PVPModule::OnCustomMatchReturn] 888"));

bool rs = role2.ParseFromArray(buf, BSize);
UE_LOG(LogTemp, Display, TEXT("[PVPModule::OnCustomMatchReturn] 999 SUCCESS:%d"), rs);

this’s the debug info in console of monitor:

this’s crash dump that cause by ParseFromArray() of protobuf API

********** Crash dump: **********
Build fingerprint: 'Xiaomi/helium/helium:6.0.1/MMB29M/6.9.29:user/release-keys'
pid: 16141, tid: 16172, name: Thread-5372  >>> com.test.HuaiKX <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0
Stack frame 10-17 03:07:04.637 31796 31796 F DEBUG   :     #00 00000000  <unknown>: Unable to open symbol file D:\workspace\unreal_project\huaikongxin2\program\client\HuaiKXCli\Intermediate\Android\APK\obj\local\armeabi-v7a/<unknown>. Error (22): Invalid argument
Stack frame 10-17 03:07:04.637 31796 31796 F DEBUG   :     #01 01984117  /data/app/com.test.HuaiKX-1/lib/arm/libUE4.so (_ZN6google8protobuf11MessageLite14ParseFromArrayEPKvi+10): Routine InlineParseFromArray at D:\workspace\unreal_project\huaikongxin2\program\common\custom_msg\android_ndk_build/jni/google/protobuf/message_lite.cc:142
Stack frame 10-17 03:07:04.637 31796 31796 F DEBUG   :     #02 018c824c  /data/app/com.test.HuaiKX-1/lib/arm/libUE4.so (_ZN9PVPModule19OnCustomMatchReturnEPKci+1080): Routine PVPModule::OnCustomMatchReturn(char const*, int) at D:\workspace\unreal_project\huaikongxin2\program\client\HuaiKXCli\Source\HuaiKX\Logic\Private\PVPModule/PVPModule.cpp:101
Stack frame 10-17 03:07:04.638 31796 31796 F DEBUG   :     #03 018dd32c  /data/app/com.test.HuaiKX-1/lib/arm/libUE4.so (_ZN9HServices15HCallbackMaster19InvokeCustomCallFunEiPKci+440): Routine HServices::HCallbackMaster::InvokeCustomCallFun(int, char const*, int) at D:\workspace\unreal_project\huaikongxin2\program\client\HuaiKXCli\Source\HuaiKX\Services\Master/HCallbackMaster.cpp:592
Stack frame 10-17 03:07:04.638 31796 31796 F DEBUG   :     #04 018e3074  /data/app/com.test.HuaiKX-1/lib/arm/libUE4.so (_ZN9HServices13HObjectMaster15OnCustomMessageEPKci+92): Routine HServices::HObjectMaster::OnCustomMessage(char const*, int) at D:\workspace\unreal_project\huaikongxin2\program\client\HuaiKXCli\Source\HuaiKX\Services\Master/HObjectMaster.cpp:93
Stack frame 10-17 03:07:04.638 31796 31796 F DEBUG   :     #05 018c2bd0  /data/app/com.test.HuaiKX-1/lib/arm/libUE4.so (_ZN10AHGameMode4TickEf+152): Routine AHGameMode::Tick(float) at D:\workspace\unreal_project\huaikongxin2\program\client\HuaiKXCli\Source\HuaiKX\Graphics\World/HGameMode.cpp:135
Stack frame 10-17 03:07:04.638 31796 31796 F DEBUG   :     #06 01fdcdd8  /data/app/com.test.HuaiKX-1/lib/arm/libUE4.so (_ZN18FActorTickFunction11ExecuteTickEf10ELevelTickN13ENamedThreads4TypeERK12TRefCountPtrI11FGraphEventE+1044): Routine FActorTickFunction::ExecuteTick(float, ELevelTick, ENamedThreads::Type, TRefCountPtr<FGraphEvent> const&) at ??:?
Stack frame 10-17 03:07:04.638 31796 31796 F DEBUG   :     #07 02ddec44  /data/app/com.test.HuaiKX-1/lib/arm/libUE4.so (_ZN17FTickFunctionTask6DoTaskEN13ENamedThreads4TypeERK12TRefCountPtrI11FGraphEventE+312): Routine FTickFunctionTask::DoTask(ENamedThreads::Type, TRefCountPtr<FGraphEvent> const&) at ??:?
Stack frame 10-17 03:07:04.638 31796 31796 F DEBUG   :     #08 02dde7e4  /data/app/com.test.HuaiKX-1/lib/arm/libUE4.so (_ZN10TGraphTaskI17FTickFunctionTaskE11ExecuteTaskER6TArrayIP14FBaseGraphTask17FDefaultAllocatorEN13ENamedThreads4TypeE+540): Routine TGraphTask<FTickFunctionTask>::ExecuteTask(TArray<FBaseGraphTask*, FDefaultAllocator>&, ENamedThreads::Type) at ??:?
Stack frame 10-17 03:07:04.639 31796 31796 F DEBUG   :     #09 01a0bd08  /data/app/com.test.HuaiKX-1/lib/arm/libUE4.so (_ZN16FNamedTaskThread23ProcessTasksNamedThreadEib+8212): Routine $a.2140 at zero_copy_stream.cc:?
Stack frame 10-17 03:07:04.639 31796 31796 F DEBUG   :     #10 01a09530  /data/app/com.test.HuaiKX-1/lib/arm/libUE4.so (_ZN16FNamedTaskThread21ProcessTasksUntilQuitEi+184): Routine FNamedTaskThread::ProcessTasksUntilQuit(int) at ??:?
Stack frame 10-17 03:07:04.639 31796 31796 F DEBUG   :     #11 02dd9ab8  /data/app/com.test.HuaiKX-1/lib/arm/libUE4.so (_ZN18FTickTaskSequencer16ReleaseTickGroupE13ETickingGroupb+2376): Routine FTickTaskSequencer::ReleaseTickGroup(ETickingGroup, bool) at ??:?
Stack frame 10-17 03:07:04.639 31796 31796 F DEBUG   :     #12 02dd3934  /data/app/com.test.HuaiKX-1/lib/arm/libUE4.so (_ZN16FTickTaskManager12RunTickGroupE13ETickingGroupb+228): Routine FTickTaskManager::RunTickGroup(ETickingGroup, bool) at ??:?
Stack frame 10-17 03:07:04.639 31796 31796 F DEBUG   :     #13 026d6b20  /data/app/com.test.HuaiKX-1/lib/arm/libUE4.so (_ZN6UWorld4TickE10ELevelTickf+6360): Routine $a.465 at zero_copy_stream.cc:?
Stack frame 10-17 03:07:04.639 31796 31796 F DEBUG   :     #14 0250cc0c  /data/app/com.test.HuaiKX-1/lib/arm/libUE4.so (_ZN11UGameEngine4TickEfb+6468): Routine $a.822 at zero_copy_stream.cc:?
Stack frame 10-17 03:07:04.639 31796 31796 F DEBUG   :     #15 0199a084  /data/app/com.test.HuaiKX-1/lib/arm/libUE4.so (_ZN11FEngineLoop4TickEv+14500): Routine $a.349 at zero_copy_stream.cc:?
Stack frame 10-17 03:07:04.640 31796 31796 F DEBUG   :     #16 019932b0  /data/app/com.test.HuaiKX-1/lib/arm/libUE4.so (_Z11AndroidMainP11android_app+4644): Routine $a.275 at zero_copy_stream.cc:?
Stack frame 10-17 03:07:04.640 31796 31796 F DEBUG   :     #17 0199e6c4  /data/app/com.test.HuaiKX-1/lib/arm/libUE4.so (android_main+220): Routine android_main at ??:?
Stack frame 10-17 03:07:04.640 31796 31796 F DEBUG   :     #18 019be838  /data/app/com.test.HuaiKX-1/lib/arm/libUE4.so: Routine android_app_entry at zero_copy_stream.cc:?
Stack frame 10-17 03:07:04.640 31796 31796 F DEBUG   :     #19 00041843  /system/lib/libc.so (_ZL15__pthread_startPv+30)
Stack frame 10-17 03:07:04.640 31796 31796 F DEBUG   :     #20 000192a5  /system/lib/libc.so (__start_thread+6)

I don’t how to solve this issue, does anybody have the same problem before?

I took me ages to figure it out, I code a function to implement MessageLite::ParseFromArray(), and it works right.
I don’t know why, It seems a bug of UE4 building, as I know, MessageLite::ParseFromArray() works well in cocos2dx project.

#ifndef	__ProtobufHelper_H__
#define	__ProtobufHelper_H__

#include <google/protobuf/message_lite.h>
#include <google/protobuf/io/coded_stream.h>

class ProtobufHelper
{
public:

	static bool Parse(::google::protobuf::MessageLite& Message, const char* Data, int Size)
	{
		::google::protobuf::io::CodedInputStream input(reinterpret_cast<const uint8*>(Data), Size);

		return Message.MergePartialFromCodedStream(&input) && input.ConsumedEntireMessage();
	}
};

#endif

invoke:

HProtocol::role_data role2; 
bool rs = ProtobufHelper::Parse(role2, buf, BSize);

Hello,

Can you explain where you’re using / calling this code? If you’re able to reproduce this crash, please provide the steps to help investigate the crash locally. Also include the full callstack and log files from the crash for additional information.

Apologies for the delay. Now I have uploaded the project which can reproduce this issue, steps have been put in it.
https://app.box.com/s/gs56zgdolwe0wfe5rhr6rc1si160jvvt

Can you explain where the crash occurs? I followed the instructions from your text document and then compiled the project for Android. The package process completed successfully and I was able to launch the project on the testing device. If you’re still getting a crash with the project you sent, can you provide the Android version the phone is on as well as the the phone model so that I can make sure I am testing on similar hardware.

Android version is 6.0.1. my phone is Mi Max (xiaomi), and build mode of UE4 is DebugGame

i meet the same crash in android runtime. link text

don’t know how to fix this.

I met the same thing. crash in android runtime.

How can i fix it? please help.