Antoine.YVAN Posted September 20, 2021 Share Posted September 20, 2021 Hi to all ! I am encountering a problem when trying to use user defined packets. Here it is => My setup : - Windows 10 - Unigine 2.14 - Visual Studio 2019 What I want to do : - Send a user defined packet from my Host to Unigine's IG - Receive the packet and read the data What happens : - My Host sends the User defined packet (loop every 10s for debugging purpose) - When the IG receives the packet, it crashes after running the method packet->getData(); I can't find anything relevant with my debugger. Here is the code (found on the docs) : // ... (default WorldLogic init) Unigine::Plugins::IG::CIGI::Connector* cigi = IG::CIGI::Connector::get(); IG::CIGI::CigiRecvCallback* callbackView = (IG::CIGI::CigiRecvCallback*)MakeCallback(this, &AppWorldLogic::on_recv_update_view); cigi->addReceivePacketCallback(203, callbackView); return 1; } void AppWorldLogic::on_recv_update_view(IG::CIGI::CigiHostUserDefined* packet) { Log::warning("recv_update_view\n"); unsigned char* data = packet->getData(); return; } I don't know if I am doing something wrong here. Some help would be really appreciated ! :) Best Regards, Antoine Link to comment
cash-metall Posted September 21, 2021 Share Posted September 21, 2021 Hello! this is mistake in the documentation: this code snippet from the previous version. in 2.14, callbacks take a pointer to the CigiHostPacket class, which you need to cast to userdefined int AppWorldLogic::init() { // CigiRecvCallback its Callback for void(CigiHostPacket *) signature cigi->addReceivePacketCallback(202, MakeCallback(this, &AppWorldLogic::on_recv_user_packet)); return 1; } void AppWorldLogic::on_recv_user_packet(IG::CIGI::CigiHostPacket * base_packet) { CigiHostUserDefined * packet = dynamic_cast<CigiHostUserDefined *>(base_packet); unsigned char * request_data = packet->getData(); // read } Link to comment
Antoine.YVAN Posted September 21, 2021 Author Share Posted September 21, 2021 Hello, Indeed this works as expected! Thanks. Link to comment
Recommended Posts