When we are copying recorded data into a buffer we use a pointer to track the

buffer position.  This pointer wasn't used in DR_Changes_Step and was corrupting
the pointer initialization later in the write function.
This commit is contained in:
Alex Lin 2018-05-16 09:08:39 -05:00
parent be6f9dc855
commit 1e783fb49c

View File

@ -363,6 +363,7 @@ int Trick::DataRecordGroup::init() {
// Allocate recording space for time. // Allocate recording space for time.
rec_buffer[0]->buffer = (char *)calloc(max_num , rec_buffer[0]->ref->attr->size) ; rec_buffer[0]->buffer = (char *)calloc(max_num , rec_buffer[0]->ref->attr->size) ;
rec_buffer[0]->last_value = (char *)calloc(1 , rec_buffer[0]->ref->attr->size) ;
/* Loop through all variables looking up names. Allocate recording space /* Loop through all variables looking up names. Allocate recording space
according to size of the variable */ according to size of the variable */
@ -593,7 +594,30 @@ int Trick::DataRecordGroup::data_record(double in_time) {
*((double *)(rec_buffer[0]->last_value)) = in_time ; *((double *)(rec_buffer[0]->last_value)) = in_time ;
for (jj = 0; jj < rec_buffer.size() ; jj++) { for (jj = 0; jj < rec_buffer.size() ; jj++) {
drb = rec_buffer[jj] ; drb = rec_buffer[jj] ;
memcpy( drb->buffer + (buffer_offset * drb->ref->attr->size) , drb->last_value , drb->ref->attr->size ) ; REF2 * ref = drb->ref ;
int param_size = ref->attr->size ;
if ( buffer_offset == 0 ) {
drb->curr_buffer = drb->buffer ;
} else {
drb->curr_buffer += param_size ;
}
switch ( param_size ) {
case 8:
*(int64_t *)drb->curr_buffer = *(int64_t *)drb->last_value ;
break ;
case 4:
*(int32_t *)drb->curr_buffer = *(int32_t *)drb->last_value ;
break ;
case 2:
*(int16_t *)drb->curr_buffer = *(int16_t *)drb->last_value ;
break ;
case 1:
*(int8_t *)drb->curr_buffer = *(int8_t *)drb->last_value ;
break ;
default:
memcpy( drb->curr_buffer , drb->last_value , param_size ) ;
break ;
}
} }
buffer_num++ ; buffer_num++ ;
} }