adamrehn / ue4-grpc-demo

Dockerised Unreal Engine 4 microservice demo using gRPC
MIT License
68 stars 24 forks source link

[request/enhancement/discussion] Shift gRPC service implementation to a plugin #3

Closed RachithP closed 3 years ago

RachithP commented 3 years ago

Hi @adamrehn,

Thanks a lot for this demo!

I was trying something similar but with the service implementation in Plugin code, for portability. The problem I'm facing is not an issue of this repo, but I hope you will be able to help me and it might be useful for others as well.

I created a project without the docker part of your project, and was able to launch gRPC server on it. Now, I'm trying to port the GrpcServiceImp.h & it's .cpp part into a Plugin along with the threadingHelper code. The server is still created during BeginPlay() of an Actor/Pawn whom I'd like to control. However, engine is crashing when I try to send commands from a python client. The trace was something like this

<CALLSTACK START>
grpc_impl::internal::RpcMethodHandler<PawnMovementDemo::Service, Direction, Empty>::D​eserialize(grpc_call*, grpc_byte_buffer*, grpc::Status*, void**) Address = 0x174ee7926 [~/.local/include/grpcpp/impl/codegen/method_handler_impl.h, line 99] [in UE4Editor-MyPlugin-0021.dylib]
grpc_impl::Server::SyncRequest::CallData::Run(std::__1::shared_ptr<grpc_impl::Server::GlobalCallbacks> const&, bool) Address = 0x1753e9966 (filename not found) [in UE4Editor-ConanUE4-7613.dylib]
grpc_impl::Server::SyncRequestThreadManager::D​oWork(void*, bool, bool) Address = 0x1753e880b (filename not found) [in UE4Editor-ConanUE4-7613.dylib]
grpc::ThreadManager::MainWorkLoop() Address = 0x175424101 (filename not found) [in UE4Editor-ConanUE4-7613.dylib]
grpc::ThreadManager::WorkerThread::Run() Address = 0x175423dec (filename not found) [in UE4Editor-ConanUE4-7613.dylib]
grpc::ThreadManager::WorkerThread::WorkerThread(grpc::ThreadManager*)::$_0::o​perator()(void*) const Address = 0x17542507c (filename not found) [in UE4Editor-ConanUE4-7613.dylib]
grpc::ThreadManager::WorkerThread::WorkerThread(grpc::ThreadManager*)::$_0::__invoke(void*) Address = 0x175425055 (filename not found) [in UE4Editor-ConanUE4-7613.dylib]
grpc_core::(​anonymous namespace)::ThreadInternalsPosix::ThreadInternalsPosix(char const*, void (*)(void*), void*, bool*, grpc_core::Thread::Options const&)::'lambda'(void*)::o​perator()(void*) const Address = 0x1759537ef (filename not found) [in UE4Editor-ConanUE4-7613.dylib]
grpc_core::(​anonymous namespace)::ThreadInternalsPosix::ThreadInternalsPosix(char const*, void (*)(void*), void*, bool*, grpc_core::Thread::Options const&)::'lambda'(void*)::__invoke(void*) Address = 0x1759536e5 (filename not found) [in UE4Editor-ConanUE4-7613.dylib]
_pthread_start Address = 0x7fff73926109 (filename not found) [in libsystem_pthread.dylib]
thread_start Address = 0x7fff73921b8b (filename not found) [in libsystem_pthread.dylib]
<CALLSTACK END> 

Initially I had the gRPC dependencies in my project's .build.cs. Now, I've included the same dependencies in the Plugin's .build.cs and removed it from the project's .build.cs. This is static linkage of gRPC libraries.

The .uplugin part contains

"FileVersion": 3,
"Version": 1,
"VersionName": "1.0",
"FriendlyName": "",
"Description": "",
"Category": "Other",
"CreatedBy": "",
"CreatedByURL": "",
"DocsURL": "",
"MarketplaceURL": "",
"SupportURL": "",
"CanContainContent": true,
"IsBetaVersion": false,
"IsExperimentalVersion": false,
"Installed": false,
"Modules": [
{
"Name": "MyPlugin",
"Type": "Runtime",
"LoadingPhase": "Default"
}
]

and I've added the dependency of the Plugin module in the project's .build.cs.

I tried different LoadingPhase for the Plugin module - PreDefault, Default, PostDefault and none of them worked.

The functionality is not failing when I start the game, but when I send my first message from the client. For me, it looks like some thread issue - one thread is not able to communicate to another? I'm launching the service implementations on GameThreads as done in your code. Is this a problem when a plugin is involved? I'm unable to understand what is causing this issue. Any help that could direct me towards potential problems would be really helpful!

Thanks in advance!

Cheers!

adamrehn commented 3 years ago

Apologies for the delay in responding to this issue, I've been drowning in work over the past few months and progress on addressing my GitHub backlog has been frustratingly slow.

Hmmm, that's strange that it works from inside a project but fails from inside a plugin. I'll refactor the demo in this repo to use a plugin and see if I can reproduce the crash.

RachithP commented 3 years ago

@adamrehn , Thanks for getting back!

No worries on the delay!

I managed to get it working via FRunnable thread instead of FAsyncGraphTaskBase. I did not debug why I was getting a runtime error. Since it looked like it had to do something with threads, I tried FRunnable instead.

But, I look forward to see if you could get it running! Thanks much.

saddlekiller commented 2 years ago

@adamrehn , Thanks for getting back!

No worries on the delay!

I managed to get it working via FRunnable thread instead of FAsyncGraphTaskBase. I did not debug why I was getting a runtime error. Since it looked like it had to do something with threads, I tried FRunnable instead.

But, I look forward to see if you could get it running! Thanks much.

Hi RachithP, I got the similar situation. The server crashed when I tried to send requests from python client. Could you share a simple demo about how to fix it using FRunnable?