Open Bqleine opened 2 years ago
How's AddressOrGUID
defined? I think if it's not a POD
type this might unfortunately be expected (because Rust doesn't have the C++ concept of non-trivial types).
Like this:
struct RAK_DLL_EXPORT AddressOrGUID
{
RakNetGUID rakNetGuid;
SystemAddress systemAddress;
SystemIndex GetSystemIndex(void) const {if (rakNetGuid!=UNASSIGNED_RAKNET_GUID) return rakNetGuid.systemIndex; else return systemAddress.systemIndex;}
bool IsUndefined(void) const {return rakNetGuid==UNASSIGNED_RAKNET_GUID && systemAddress==UNASSIGNED_SYSTEM_ADDRESS;}
void SetUndefined(void) {rakNetGuid=UNASSIGNED_RAKNET_GUID; systemAddress=UNASSIGNED_SYSTEM_ADDRESS;}
static unsigned long ToInteger( const AddressOrGUID &aog );
const char *ToString(bool writePort=true) const;
void ToString(bool writePort, char *dest) const;
AddressOrGUID() {}
AddressOrGUID( const AddressOrGUID& input )
{
rakNetGuid=input.rakNetGuid;
systemAddress=input.systemAddress;
}
AddressOrGUID( const SystemAddress& input )
{
rakNetGuid=UNASSIGNED_RAKNET_GUID;
systemAddress=input;
}
AddressOrGUID( Packet *packet );
AddressOrGUID( const RakNetGUID& input )
{
rakNetGuid=input;
systemAddress=UNASSIGNED_SYSTEM_ADDRESS;
}
AddressOrGUID& operator = ( const AddressOrGUID& input )
{
rakNetGuid=input.rakNetGuid;
systemAddress=input.systemAddress;
return *this;
}
AddressOrGUID& operator = ( const SystemAddress& input )
{
rakNetGuid=UNASSIGNED_RAKNET_GUID;
systemAddress=input;
return *this;
}
AddressOrGUID& operator = ( const RakNetGUID& input )
{
rakNetGuid=input;
systemAddress=UNASSIGNED_SYSTEM_ADDRESS;
return *this;
}
inline bool operator==( const AddressOrGUID& right ) const {return (rakNetGuid!=UNASSIGNED_RAKNET_GUID && rakNetGuid==right.rakNetGuid) || (systemAddress!=UNASSIGNED_SYSTEM_ADDRESS && systemAddress==right.systemAddress);}
};
rakNetGuid
and systemAddress
are supposed to be set to UNASSIGNED_RAKNET_GUID
and UNASSIGNED_SYSTEM_ADDRESS
respectively when the other is used.
Here's the RaknetGUID definition:
struct RAK_DLL_EXPORT RakNetGUID
{
RakNetGUID();
explicit RakNetGUID(uint64_t _g) {g=_g; systemIndex=(SystemIndex)-1;}
// uint32_t g[6];
uint64_t g;
...
And the AddressOrGuid definition:
struct RAK_DLL_EXPORT SystemAddress
{
/// Constructors
SystemAddress();
SystemAddress(const char *str);
SystemAddress(const char *str, unsigned short port);
/// SystemAddress, with RAKNET_SUPPORT_IPV6 defined, holds both an sockaddr_in6 and a sockaddr_in
union// In6OrIn4
{
#if RAKNET_SUPPORT_IPV6==1
struct sockaddr_storage sa_stor;
sockaddr_in6 addr6;
#endif
sockaddr_in addr4;
} address;
/// This is not used internally, but holds a copy of the port held in the address union, so for debugging it's easier to check what port is being held
unsigned short debugPort;
...
And I might as well link the rest of the library if you want to look by yourself: https://github.com/facebookarchive/RakNet/blob/master/Source/RakNetTypes.h
Hello, Any update on this one ? Do you still have the solution, could you find a fix or a workaround ? Asking because I observe a very similar issue on my project: it ends up with signal: 11, SIGSEGV: invalid memory reference, where you have invalid address. And in more details, I observe the same as you on GDB, I have a 'self' which is valid and points to an address in Rust world, and when I arrive in the C++ world, the 'this' becomes 0x00 (null ptr -> crash)
Any hint would be appreciated. Thx
Hello! I switched to another solution so I did not have to fix that problem, I suppose though you could make a C wrapper around that C++ code and then use it in rust, or maybe modify the type to make it not POD.
As emilio said this is related to having a POD type so if that's not the case for you you should try another issue i guess. Good luck!
Input C/C++ Header
Bindgen Invocation
Actual Results
Test crashes with
Debugger stack at time of crash:
By looking at the debugger results, it seems the
Send
function is called with aNULL
systemIdentifier
even though it is instantiated and called in rust with this:The debugger also shows that all the other arguments are non-null and valid in the
Send
function.I have tried other ways to instantiate the system_identifier but everything ends up with the same result, and I was able to verify that the system_identifier variable is valid on the rust side using the debugger.
Here are the generated bindings for some of the functions used:
Expected Results
The send function is called with valid arguments and doesn't crash