Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boolean not being set correctly #29

Open
zacharyabresch opened this issue Feb 21, 2017 · 5 comments
Open

Boolean not being set correctly #29

zacharyabresch opened this issue Feb 21, 2017 · 5 comments

Comments

@zacharyabresch
Copy link

Hi. I'm using ffi and ref-struct in a project and ran into a strange issue today. I have a struct with several boolean members. All of these boolean members are being set correctly except for one and I can't for the life of me figure out what's going on. Here's some code:

Struct definition

const RPC_CALL_STATE = StructType({
  eCallState: ref.types.int,
  bInboundCall: ref.types.bool,
  bVideoCall: ref.types.bool,
  bRecording: ref.types.bool,
  bEncrypted: ref.types.bool,
  bHDAudio: ref.types.bool,
  bVirtualMeetingCall: ref.types.bool,
  eCurrentCodec: ref.types.int,
  eAlertInfoType: ref.types.int,
  dAccumulatedMOSLQ: ref.types.double,
  nVideoState: ref.types.int,
  nErrorCode: ref.types.int,
  nCallStartTime: ref.types.uint,
  cPhoneNumber: FixedBuffer(RPC_STRING_LENGTH),
  cName: FixedBuffer(RPC_STRING_LENGTH),
  cCallId: FixedBuffer(RPC_STRING_LENGTH_CALLID),
  cPreviousCallId: FixedBuffer(RPC_STRING_LENGTH_CALLID),
});

The member in question is bEncrypted. I have verified that the C code is sending the correct value but, no matter what it sends, bEncrypted is always false. Yet, bInboundCall, bHDAudio, and bVirtualMeetingCall all work as expected. I tried changing the type to ref.types.int and I do see 0 or 1 but then bHDAudio is showing false when it should be true.

Consuming code

const pDataRef = ref.reinterpret(pData, RPC_DATA_CALL_PROGRESS.size);
pDataRef.type = RPC_DATA_CALL_PROGRESS;
this.callProgressObj = pDataRef.deref();
this.callProgressArray = this.callProgressObj.xCallState;

The callProgressArray is an array of RPC_CALL_STATE structs. This is a huge blocker for my team and project so any help you can provide would be greatly appreciated. Let me know if you have questions or need more detail. Thanks!

@zacharyabresch
Copy link
Author

BTW, I was running this code on a Mac (10.11.6) using Node 6.5.0. I've also tried it on a Windows 7 machine and the code is behaving even more strangely there. Struct members not being set correctly. Second calls to my ffi.Callback are not setting half the values correctly. Seriously need some help debugging this and figuring out what's going on. The same code on two different operating systems behaves quite differently. I'm not sure if it's something in ffi, ref, ref-struct, or ref-array and I have no idea how to determine what's going wrong.

@TooTallNate
Copy link
Owner

Sounds like an alignment issue to me. What does RPC_CALL_STATE.alignment and RPC_CALL_STATE.size print out for you?

@zacharyabresch
Copy link
Author

I'm getting the following:

Size: 744
Alignment: 8 +0ms

@zacharyabresch
Copy link
Author

shoot ... that was for the RPC_CALL_PROGRESS struct. I'll get the other one in a bit.

@zacharyabresch
Copy link
Author

Here's a more complete code sample:

const CALL_STATE_ARRAY_LEN = 2;

const RPC_CALL_STATE = StructType({
  eCallState: ref.types.int,
  bInboundCall: ref.types.bool,
  bVideoCall: ref.types.bool,
  bRecording: ref.types.bool,
  bEncrypted: ref.types.bool,
  bHDAudio: ref.types.bool,
  bVirtualMeetingCall: ref.types.bool,
  eCurrentCodec: ref.types.int,
  eAlertInfoType: ref.types.int,
  dAccumulatedMOSLQ: ref.types.double,
  nVideoState: ref.types.int,
  nErrorCode: ref.types.int,
  nCallStartTime: ref.types.uint,
  cPhoneNumber: FixedBuffer(RPC_STRING_LENGTH),
  cName: FixedBuffer(RPC_STRING_LENGTH),
  cCallId: FixedBuffer(RPC_STRING_LENGTH_CALLID),
  cPreviousCallId: FixedBuffer(RPC_STRING_LENGTH_CALLID),
});

const RPC_DATA_CALL_PROGRESS = StructType({
  xCallState: RefArray(RPC_CALL_STATE, CALL_STATE_ARRAY_LEN),
  dwStateOptions: ref.types.int,
});

How would you suggest I get the size and alignment here? xCallState is a RefArray of RPC_CALL_STATE objects and the entire RPC_DATA_CALL_PROGRESS struct is being reinterpreted and dereferenced at once.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants