c++ - Calling a function using the context pointer using JNI on android causes a segfault -


i found bit of code in 1 of example tango projects using jni , have no idea context nor how use it. example code works, code not.

void onxyzijavailablerouter(void *context, const tangoxyzij *xyz_ij) {     synchronizationapplication *app =         static_cast<synchronizationapplication *>(context);     app->onxyzijavailable(xyz_ij); } 

i tried mimicking below:

void onframeavailablerouter(void *context, const tangocameraid id,                             const tangoimagebuffer *buffer) {     synchronizationapplication *app =         static_cast<synchronizationapplication *>(context);     loge("before onframe call.");     app->onframeavailable(id, buffer);     loge("after onframe call."); } 

when try run it, however, output:

before onframe call. fatal signal 11 (sigsegv) @ 0x00000308 (code=1), thread 15673 (binder_2) 

now managed find pointer causes seg fault, have no idea why not work.

naturally, might have done wrong, have no idea since made exact copy of code in example.

int synchronizationapplication::tangoconnectcallbacks() {     tangoerrortype depth_ret =             tangoservice_connectonxyzijavailable(onxyzijavailablerouter);      depth_ret = tangoservice_connectonframeavailable(tangocameraid::tango_camera_color, null,                                          onframeavailablerouter);      return depth_ret; } 

the functions call routers.

void onxyzijavailable(const tangoxyzij *xyz_ij); void onframeavailable(const tangocameraid id, const tangoimagebuffer *buffer); 

what context? have read explanations, still not understand why can call function using context in example above, nor why need router function @ all. have read this answer , the android page on concept, see no link between context , class.

in onxyzijavailablerouter (the depth callback), context instance passed in tangoservice_connect function. believe in application class, there should line this: tangoservice_connect(this, tango_config_); this become context when callback called. context applies pose , event callbacks.

in case of onframeavailablerouter, context instance passed in in tangoservice_connectonframeavailable. in case, code setting null context, in callback, it's trying call function on null. that's crash point.

i believe if change tangoservice_connectonframeavailable(tangocameraid::tango_camera_color, this, onframeavailablerouter); should work fine.

the router function callbacks, haven't find way of giving function pointer of instance api. let me know if find way that, know well..


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -