Changeset 331 in flair-src


Ignore:
Timestamp:
Oct 1, 2019, 4:45:02 PM (2 years ago)
Author:
Sanahuja Guillaume
Message:

resolve aligment trap bug

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/FlairSensorActuator/src/VrpnClient_impl.cpp

    r330 r331  
    131131      liteObject_t tmp;
    132132      tmp.vrpnobject = obj;
    133       tmp.id = liteObjects.size();
     133      uint16_t id=liteObjects.size();
    134134      mutex->GetMutex();
    135135      liteObjects.push_back(tmp);
     
    137137      //Printf("%i %s\n",tmp.id,obj->self->ObjectName().c_str());
    138138     
    139       char char_array[obj->self->ObjectName().length() + 2];//id coded on 16bits
    140       strcpy(char_array, obj->self->ObjectName().c_str());
    141       uint16_t* idPtr=(uint16_t*)&char_array[obj->self->ObjectName().length()];
    142       *idPtr=tmp.id;
    143       dataSocket->HostToNetwork((char*)idPtr,sizeof(uint16_t));
    144       dataSocket->SendMessage(char_array,obj->self->ObjectName().length() + 2);
     139      char char_array[obj->self->ObjectName().length() + sizeof(id)];
     140      strcpy(char_array, obj->self->ObjectName().c_str());
     141      dataSocket->HostToNetwork((char*)(&id),sizeof(id));
     142      memcpy(&char_array[obj->self->ObjectName().length()],&id,sizeof(id));
     143      dataSocket->SendMessage(char_array,obj->self->ObjectName().length() + sizeof(id));
    145144    }else {
    146145      self->Warn("too much trackables for vrpnlite connection, not adding %s\n",obj->self->ObjectName().c_str());
  • trunk/tools/VrpnLite/src/VrpnLite.cpp

    r330 r331  
    5353    if(rcv>0) {
    5454      string object=msg;
    55       uint16_t* idPtr=(uint16_t*)&msg[rcv-2];
    56       dataSocket->HostToNetwork((char*)idPtr,sizeof(uint16_t));
     55      uint16_t id;
     56      memcpy(&id,&msg[rcv-2],sizeof(id));
     57      dataSocket->HostToNetwork((char*)&id,sizeof(id));
    5758      //assume we receive it in the good order
    58       if(*idPtr==vrpnobjects.size()) {
    59         Printf("adding object %s with id %i\n",object.c_str(),*idPtr);
     59      if(id==vrpnobjects.size()) {
     60        Printf("adding object %s with id %i\n",object.c_str(),id);
    6061        VrpnObject* vrpnobject = new VrpnObject(object,vrpnclient->GetTabWidget());
    6162        vrpnobjects.push_back(vrpnobject);
    6263      }else {
    63         Err("adding object %s failed, expected id %i, got %i\n",object.c_str(),vrpnobjects.size(),*idPtr);
     64        Err("adding object %s failed, expected id %i, got %i\n",object.c_str(),vrpnobjects.size(),id);
    6465      }
    6566    }
Note: See TracChangeset for help on using the changeset viewer.