LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with printing from EasyTab Control

 Test in attachment prepares data, puts it in EasyTab Control and prints graphics.
if put FillGraphs Button twice  - Ok
if FillGraphs Button, Print Button and FillGraphs Button:
 FATAL RUN-TIME ERROR:   "Print_test.c", line 74, col 17, thread id 0x000009FC:   Dynamic memory is corrupt.

Help me! Where is my mistake?

0 Kudos
Message 1 of 6
(3,426 Views)

You are allocating memory into local variables DataX and DataY, but you are not freeing it afterwards. This may be upsetting CVI's internal house-keeping/tracking of allocated memory, so that when the routine is repeated it is pot luck as to whether or not the program happens to use the same memory locations as before. CVI may expect the original pointers to still be valid (ie still in the same place), as you have not explicitly freed them. By calling a different routine in the meantime this will almost certainly alter the memory area on the stack that was used to store DataX and DataY, thus corrupting CVI's internal chain. Just free the memory at the end of the FillGraphs routine and all should be well.

JR

0 Kudos
Message 2 of 6
(3,418 Views)
I add "free(DataX); free(DataY)" at the end of FillGraphs with the same effect. But i don't want to freed memory, because i want to use these data later.
0 Kudos
Message 3 of 6
(3,416 Views)

Looks like the problem must be elsewhere, then. If you want to use the DataX and DataY variables "later" (not sure what you mean by this) then you should use static variables for them, not automatic. That way their values are guaranteed to persist outside of the function - currently the variables are discarded by CVI as soon as FillGraphs terminates; not a good idea if you need to retain their values.

JR

0 Kudos
Message 4 of 6
(3,411 Views)
Sorry for my English, no practice.
Put all data in global structure and erase all malloc. Same error. 
0 Kudos
Message 5 of 6
(3,403 Views)
I think, that my error in using DuplicateGraphControl with data, because when i Discard Control in the new panel some internal pointers changed in the old panel.
I change Duplicate for NewControl and redraw graphics in this new Control - no errors.
Thank you.
0 Kudos
Message 6 of 6
(3,363 Views)