I'm trying to use the helloworld example to create a GRPC client library 
for Unity3D using the following steps:

1. Took the existing GreeterClient class and modified it such that all the 
parameters and return types are C compatible:
    a. The constructor now takes a const char * and int to create the 
Channel.
    b. The SayHello function takes a const char * and returns one too.
2. I created a singleton ClientManager class with the following functions:
    a. int newClient(const char *, int port): this creates a new 
GreeterClient, saves it into a map and returns an int that was used as the 
key for the map.
    b. const char* sayHello(int client_id, const char *user): Finds the 
client using the client ID then calls SayHello(user).
    c. void deleteClient(int client_id): deletes the client.
3. I added an export "C" block with 3 functions to get the singleton 
manager instance and call its 3 functions.

To compile I'm using (note that this will create the Linux .so and OSX 
.bundle, I haven't gotten around to doing .dll):
$ g++ -std=c++11 -I/usr/local/include -pthread  -c -o greeter_lib.o 
greeter_lib.cc

$ g++ helloworld.pb.o helloworld.grpc.pb.o greeter_lib.o -L/usr/local/lib 
`pkg-config --libs grpc++ grpc` -lprotobuf -lpthread -ldl -shared -o 
greeter.so

$ g++ helloworld.pb.o helloworld.grpc.pb.o greeter_lib.o -L/usr/local/lib 
`pkg-config --libs grpc++ grpc` -lprotobuf -lpthread -ldl -bundle -o 
greeter.bundle


When I run this, calling newClient works great! When I call sayHello I get 
a null pointer exception:

Registered platform support modules in: 0.037474s.

Native extension for OSXStandalone target not found

Load scene 'Temp/__Backupscenes/0.backup' time: 0.633909 ms 

D0722 14:37:02.336402000 140735245529088 ev_posix.c:106] Using polling 
engine: poll

Receiving unhandled NULL exception

Launching bug reporter

Obtained 33 stack frames.

#0  0x000001253a96ce in 
helloworld::Greeter::Stub::SayHello(grpc::ClientContext*, 
helloworld::HelloRequest const&, helloworld::HelloReply*)

#1  0x000001253b6c04 in GreeterClient::sayHello(char const*)

#2  0x000001253b640b in GreeterClient_sayHello

#3  0x000001251d311a in  (wrapper managed-to-native) 
HelloWorldRpc:GreeterClient_sayHello (int,string) + 0x11a (0x1251d3000 
0x1251d31fa) [0x116542660 - Unity Child Domain]

#4  0x000001251d2d4e in  HelloWorldRpc:Start () + 0x9e (0x1251d2cb0 
0x1251d2e44) [0x116542660 - Unity Child Domain]

#5  0x000001219bf38a in  (wrapper runtime-invoke) 
object:runtime_invoke_void__this__ (object,intptr,intptr,intptr) + 0xfa 
(0x1219bf290 0x1219bf4bd) [0x116542660 - Unity Child Domain]

#6  0x00000109bb90a0 in mono_get_runtime_build_info

#7  0x00000109ce73ca in mono_runtime_invoke

#8  0x0000010115e502 in ScriptingInvocation::Invoke(MonoException**, bool)

#9  0x00000101138374 in 
MonoBehaviour::InvokeMethodOrCoroutineChecked(ScriptingMethodMono, 
MonoObject*, MonoException**)

#10 0x00000101138638 in 
MonoBehaviour::InvokeMethodOrCoroutineChecked(ScriptingMethodMono, 
MonoObject*)

#11 0x00000100d2adea in DelayedCallManager::Update(int)

#12 0x00000101011e3f in PlayerLoop(bool, bool, IHookEvent*)

#13 0x000001019f92fd in Application::UpdateScene(bool)

#14 0x000001019f9873 in Application::EnterPlayMode(bool)

#15 0x000001019f6648 in Application::SetIsPlaying(bool)

#16 0x000001019f5f2a in Application::TickTimer()

#17 0x007fff940d3dec in __NSFireTimer

#18 0x007fff895cfb94 in 
__CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__

#19 0x007fff895cf823 in __CFRunLoopDoTimer

#20 0x007fff895cf37a in __CFRunLoopDoTimers

#21 0x007fff895c6871 in __CFRunLoopRun

#22 0x007fff895c5ed8 in CFRunLoopRunSpecific

#23 0x007fff9b1cf935 in RunCurrentEventLoopInMode

#24 0x007fff9b1cf76f in ReceiveNextEventCommon

#25 0x007fff9b1cf5af in _BlockUntilNextEventMatchingListInModeWithFilter

#26 0x007fff9b534df6 in _DPSNextEvent

#27 0x007fff9b534226 in -[NSApplication 
_nextEventMatchingEventMask:untilDate:inMode:dequeue:]

#28 0x007fff9b528d80 in -[NSApplication run]

#29 0x007fff9b4f2368 in NSApplicationMain

#30 0x00000101c5a838 in EditorMain(int, char const**)

#31 0x00000101c5aee9 in main

#32 0x000001000020c4 in start

Launching external process: 
/Applications/Unity/Unity.app/Contents/BugReporter/Unity Bug 
Reporter.app/Contents/MacOS/unity.bugreporter.exe

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" 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].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/b385eb5e-e886-4dcc-acce-e259f4a62ed3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to