-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GRPC client 적용 Unreal project 추가 #26
Comments
이 reference 는 좋지 않을 것 같습니다.
|
언리얼 프로젝트에 protobuf, grpc 라이브러리 추가를 위한 모듈 파일 수정 Reference 0cc1e50 |
현재 에디터 실행 시 libprotobuf-lite.dll, libprotobuf.dll 을 찾을 수 없다는 이유로 K2UE4 모듈 로드 실패 발생 protobuf, grpc 는 dll 도 같이 로드되어야함 |
protobuf/bin 에 있는 *.dll 들을 K2UE4/Binaries/Win64 에 복사하여 문제 해결 |
Unreal 에서 구현된 gRPC reference 가 상당히 부족함. 크게 두가지 정도로 reference 가 모여지는데
|
현재 Game Module에 gRPC 설정 작업이 묶여있는데, 따로 gRPC Third-Party Plugin을 만들어서 분리하여 다른 프로젝트로 통합시키거나 관리 할 때 유용할 것 같습니다. |
현재 Packaging 하여 게임 실행 시 protobuf 관련 dll 을 로드 할 수 없다고 오류 발생 예시로 추가한 기본 Third Party Plugin example 는 dll 이 잘 로드 됨.... |
dll 의 위치가 실행파일 경로에는 무조건 있어야함. RuntimeDependencies 에서 $(TargetOutputDir)를 이용하면, 빌드 시 dll 의 위치가 .exe 위치에 있게됨. 패키징 시는 잘 작동하지만, VS에서 빌드할 때는 저렇게 설정해도 dll 이 ,exe 위치로 이동을 안해주는듯 |
|
일단은 따로 copy 해주는 방식으로 진행. |
sample.proto generate 해서 나온 소스 추가해서 GameInstance 에서 로그인을 해보자 |
generate 해서 나온 소스 추가 작업을 K2Unity 의 generate.bat 처럼, batch 파일을 이용해 실행 제공. UE4의 Hot reload 기능이 아직 부실하여, Source/proto 폴더 내 파일이 변경된다면 다시 빌드해함 |
UE4에서 generate 해서 추가서 *.pb.cc 파일들 위해 파일들을 컴파일 하기 위해, *.pb.cc 들의 소스코드 수정 #pragma warning (push)
// forcing value to bool true or false
#pragma warning (disable : 4800)
// decimal digit terminates octal escape sequence
#pragma warning (disable : 4125)
// behavior change __is_pod has different value in previous version
#pragma warning (disable : 4647)
// 'symbol' is not defined as a preprocessor macro,
// replacing with '0' for 'directives'
#pragma warning (disable : 4668)
// constructor is not implicitly called
#pragma warning (disable : 4582)
// destructor is not implicitly called
#pragma warning (disable : 4583)
// reinterpret_cast
#pragma warning (disable : 4946)
// Reader beware: this should only be done if the
// compile platform AND the build target are Windows.
static void MemoryBarrier() {}
#include "Windows/AllowWindowsPlatformTypes.h"
#pragma intrinsic(_InterlockedCompareExchange64)
#define InterlockedCompareExchangeAcquire64 _InterlockedCompareExchange64
#define InterlockedCompareExchangeRelease64 _InterlockedCompareExchange64
#define InterlockedCompareExchangeNoFence64 _InterlockedCompareExchange64
#define InterlockedCompareExchange64 _InterlockedCompareExchange64
...
#pragma warning( pop )
// Reader beware: this should only be done if the
// compile platform AND the build target are Windows.
#include "Windows/HideWindowsPlatformTypes.h" OpenSSl, zlib 라이브러리도 종속성에 추가 AddEngineThirdPartyPrivateStaticDependencies(Target, "OpenSSL");
AddEngineThirdPartyPrivateStaticDependencies(Target, "zlib"); Reference |
수정되는 코드 부분을 template 로 만들고, |
|
commit log 에 resolve 없이 issue 번호만(#IssueNumber) 달아주시면 해당 시점에 함께 로깅(참조)됩니다. 다만 이 경우에 rebase 등을 위해 force push 하는 경우 commit revision 들이 변경될 수 있어, 참조가 깨질 수 있습니다.(따라서 rebase 가 필요하다면, 가능한한 push 전에 해주어야합니다.)
|
8191577 Process.Start 는 현재 프로세스와 독립적으로 실행되므로 프로세스가 종료될 때까지 기다리지 않음. Process ProtocProcess = Process.Start(...);
ProtocProcess.WaitForExit();
|
프로세스 종료 시 exit code 를 확인하여, 실패 시 Merge template code 단계를 skip 하면 좋을 것 같다 |
abseil, upb, SSL, ... 라이브러리 링크 에러 발생
해당 라이브러리들 추가 필요 |
오류가 발생하는 경우, 오류내용(debug output)도 함께 기록해주시면 좋겠습니다. |
OpenSSL 라이브러리는 전에 추가를 했음에도 위와 같은 링크 에러 발생 AddEngineThirdPartyPrivateStaticDependencies(Target, "OpenSSL"); |
ed73da0 vcpkg로 gRPC 를 설치하면서 종속적으로 함께 설치된 OpenSSL 라이브러리를 추가하니 빌드 성공 |
c++ client 의 코드를 참조하여 UE4 용 client 제작 |
auto status = initStub.State(&context, empty, &rsp); ID PW 입력 후 Login 호출 시 크래쉬 발생
|
오류 기록시에는 굳이 전체 log 를 기록할 필요 없고, 문제해결에 주요한(전체가 필요한 경우라면 전체가 될 수도..)부분만 기록해주시면 됩니다. 이 경우에는
와 첨부해주신 소스 부분이 되겠네요. 이 문제는 참고 : C++ project(visual studio) 에서 gRPC 사용 구성 방법 의 항목 7 |
UE4에서 std::string 을 사용 시 delete 부분에서 항상 문제 발생
std::string CHANNEL_URL("localhost:9060");
auto creds = grpc::InsecureChannelCredentials();
auto initChannel = grpc::CreateChannel(CHANNEL_URL, creds); 여기서 std::string 을 const char* 로 type을 변경하여 몇번은 정상 작동되었지만, 그 다음 실행부터는 계속 같은 문제 발생 UE4에서 std::string 을 사용해도 문제가 없는지 확인해야할 듯, 혹은 다른 문제 |
dll에 std:;string 을 넘길 때 인스턴스가 다르거나, dll 과의 runtime library가 다른 것 같음.. 혹은 컴파일 시에 서로 프로젝트 세팅이 다르거나.. 일단 그러면 직접 gRPC 를 빌드해서 static library로 처리해보자. |
vcpkg 에서 package 의 빌드 방식을 변경하는 참고할만한 references
|
일단 dll 로는 해결 방안이 도저히 생각이 안남... vcpkg/ports 경로에서 grpc moudle 의 profile.cmake 를 열어서,
를
으로 수정하여 gRPC 라이브러리의 CRT를 MD 로 강제 변경. vcpkg 에서 gRPC, winsock2 package 들을 static 옵션을 붙여서 static library로 installl. error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in SharedPCH.Engine.ShadowErrors.h.obj |
참고 : https://www.lonely.coffee/blog/2020/4/20/ue4-protobuf-and-yarn-spinner
와 같이 되어있네요. 따라서, vcpkg 가 종속성 빌드를 알맞게 해준다면
만으로 잘 동작해야하지 않을까요? |
아 뒤에 런타임 옵션을 지정을 안했네요. 감사합니다. -static-md 로 설치하고 ThirdParty 폴더에 라이브러리들 복사하여 빌드 시 OpenSSL 에서 libcrypto.lib 관련 링크 에러가 발생
crypt32.lib 를 link 하여 해결 da592e9 로그인 기능도 문제없이 잘 실행됨. |
client 동작이 잘 이루어지면, README 에 새 UE4 project 에 적용하는 방법을 정리해주세요. (Unity client 구성 방법 참고) |
UE4 Editor 에서 첫 Login 성공 후 Stop 하고 Play 를 눌러서 다시 Login 시도 시 grpc::ClientContext 생성자에서 Exception 발생 지금은 GameInstance에서 Login이 호출 되어 성공 시 grpc::ClientContext::SetGlobalCallbacks 으로 g_client_callbacks 을 세팅해주는데, g_client_callbacks->DefaultConstructor(this); // Exception thrown: read access violation ClientContext 생성 전에 g_client_callbacks 을 다시 설정해주야할 듯 |
Login 시도 시에 grpc::ClientContext::SetGlobalCallbacks 를 호출하여, 처음부터 설정되도록 했는데... // client_context.cc
void ClientContext::SetGlobalCallbacks(GlobalCallbacks* client_callbacks) {
GPR_ASSERT(g_client_callbacks == g_default_client_callbacks); g_client_callbacks , g_default_client_callbacks 는 global static 변수 이고 Reset 함수가 따로 존재 하지 않은 것 같아 KritikaGameInstance 에서 초기화는 불가능해 보임. |
6b07661 stub 을 만들 때 넘겨주는 channel 은 thread safe. push thread 로 channel 을 그냥 넘겨줘도 문제 없을 듯. 그런데 push 이벤트로 jwt 토큰이 왔을 때 gRPCGlobalAuth.setJwt(Buffer.extra()); 가 thread safe 하지는 않을 것 같아보임... |
현재 첫 로그인 후 Stop 하고 Play 눌러 같은 계정으로 다시 로그인 시 크래쉬 발생 (다른 계정으로 로그인 시 발생 안함)
FPushResponseThread::Run() 안 while 문을 주석 처리 하니 크래쉬 현상 없어짐. while (Stream->Read(&Buffer)) // Read 함수는 blocking 함수
{
// empty...
} while (Stream->Read(&Buffer)) 이 부분에서 문제가 발생하는 듯.. |
이전 계정에서 사용하던 thread 는 올바르게 종료가 된 이후인가요? |
Thread 는 강제로 kill을 해도 Runnable 과 같이 정상 종료가 안되는 것 같네요 |
현재 문제가 Shutdown 시 Thread Kill 을 요청해도, 끝날 때 까지 기다리지 않고 그냥 Thread Handle 만 닫고 있으므로 내부에서는 아직 계속 돌아가고 있음. uint32 FRunnableThreadWin::Run()
{
// Assume we'll fail init
uint32 ExitCode = 1;
check(Runnable);
// Initialize the runnable object
if (Runnable->Init() == true)
{
// Initialization has completed, release the sync event
ThreadInitSyncEvent->Trigger();
// Setup TLS for this thread, used by FTlsAutoCleanup objects.
SetTls();
// Now run the task that needs to be done
ExitCode = Runnable->Run();
// Allow any allocated resources to be cleaned up
Runnable->Exit(); <- Invalid!
// ... 결국 끝날 때 까지 기다리지 않고... 삭제 처리하는게 문제인 것 같다 |
비동기 API 를 이용하여 PushThread 에서 처리해야 될 것 같다. CompletionQueue::Next 는 blocking 이라서 Async 버전인 CompletionQueue::AsyncNext를 사용해보자 |
현재 2번째 로그인 시 바로 "END OF PUSH service" 나는 이유는. Play -> 1 PushThread Begin -> Stop -> Play -> 2 PushThread Begin -> 1,2 PushThread Read Fail -> 1,2 PushThread Finish 2번째 로그인 시 서버 fail 메세지
|
How did you fix this issue? I am seeing something similar when trying to integrate grpc in UE |
@alkee-allm I have tried to read korean with google translate as much as possible, but how u managed to exclude Unreal Engine's open ssl ? |
C++ K2Client sample 참고해, unreal project(UE4)에서 gRPC client 적용이 필요.
.gitignore
알맞게 추가 또는 수정The text was updated successfully, but these errors were encountered: