Jasvirbahl / b-tk

Automatically exported from code.google.com/p/b-tk
0 stars 0 forks source link

Matlab support under Unix OS 64 bit crashed #7

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Build BTK with Matlab support under Linux 64-bit or MacOS X 64-bit
2. Open acquisitions into Matlab
3. Matlab crashes

This problem is related to the memory management used between BTK and Matlab to 
store handles under 64-bit OS.

The problem is that a pointer to the object btk::Acquisition under Unix 64 bit 
is stored under 8 bits but the matrix used to store the handle is set as an 
uint32 type (4 bits).

Fixing this issue could have consequences on the compatibility of BTK-0.1.6 and 
BTK-0.1.7 (like storing handle in a matrix)

Original issue reported on code.google.com by arnaud.barre on 31 Jan 2011 at 11:11

GoogleCodeExporter commented 8 years ago

Original comment by arnaud.barre on 1 Feb 2011 at 6:15

GoogleCodeExporter commented 8 years ago
The proposed solution is to modify the creation of the handle. Instead of using 
an unsigned integer coded on 32 bits (uint32), the handle will be stored as a 
double. This solution seems to work under 32-bit and 64-bit system as a double 
is coded on 8 bits under Maltab. Moreover, this solution is already used by 
Mathworks to store handle.

The drawback of this method is the possibility to have incompatible code 
between BTK-0.1.6 and BTK-0.1.7 if you store handles in a array. 
For example:
% Matlab code
handles = uint32(zeros(4,1)); % Create a matrix with the type UINT32
handles(1) = btkReadAcquisition('myFile.c3d'); % Store the handle
markers = btkGetMarkers(handles(1)); % Don't work anymore for BTK-0.1.7 and 
later.

To be able to use the same code, it is proposed to use the function 
btkGetVersion to adapt the array initialization.
For example:
% Matlab code
if (strcmp(btkGetVersion,'0.1.6')==0)
  handles = uint32(zeros(4,1)); % Create a matrix with the type UINT32
else
  handles = zeros(4,1); % Create a matrix with the type DOUBLE
end
handles(1) = btkReadAcquisition('myFile.c3d');
markers = btkGetMarkers(handles(1)); % Works in every case

Original comment by arnaud.barre on 1 Feb 2011 at 6:38

GoogleCodeExporter commented 8 years ago

Original comment by arnaud.barre on 3 Feb 2011 at 9:29