Using the code below and clicking the Home button which performs GUI_EndDialog(pMsg->hWin, 0);
we will get MAX_GRAPHS (3) of these
"GUI_alloc.c: block to be deleted already locked in _Free()" errors
and 1
"GUI_alloc.c: GUI_ALLOC_h2p: illegal argument (0 handle) in GUI_ALLOC_h2p()." error.
The question is, what is the best practice for cleaning up a graph window?
Cheers,
Joe
Referencing threads:
GUI_alloc erro
GRAPH free allocated memory problem.
Display All
we will get MAX_GRAPHS (3) of these
"GUI_alloc.c: block to be deleted already locked in _Free()" errors
and 1
"GUI_alloc.c: GUI_ALLOC_h2p: illegal argument (0 handle) in GUI_ALLOC_h2p()." error.
The question is, what is the best practice for cleaning up a graph window?
Cheers,
Joe
Referencing threads:
GUI_alloc erro
GRAPH free allocated memory problem.
C Source Code: GUI_alloc_erro_on_exit.c
- #include <stdlib.h>
- #include "DIALOG.h"
- #include "GRAPH.h"
- /*********************************************************************
- *
- * Defines
- *
- **********************************************************************
- */
- #define ID_BUTTON_2 (GUI_ID_USER + 0x05)
- #define ID_TEXT_0 (GUI_ID_USER + 0x23)
- #define ID_GRAPH_0 (GUI_ID_USER + 0x24)
- /*********************************************************************
- *
- * Static data
- *
- **********************************************************************
- */
- #define MAX_GRAPHS 3
- static GRAPH_DATA_Handle _ahData[MAX_GRAPHS]; // Array of handles for the GRAPH_DATA objects
- // Array of colors for the GRAPH_DATA objects
- static GUI_COLOR _aColor[] = {
- GUI_LIGHTGRAY, GUI_LIGHTGRAY, GUI_LIGHTGRAY, GUI_ORANGE,
- GUI_GREEN, GUI_GREEN, GUI_RED, GUI_RED,
- GUI_LIGHTBLUE, GUI_LIGHTBLUE
- };
- //
- // Dialog ressource
- //
- static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
- { FRAMEWIN_CreateIndirect, "ChartWindow", 0, 0, 0, 780, 440, 0 },
- { GRAPH_CreateIndirect, 0, GUI_ID_GRAPH0, 20, 80, 740, 340 },
- { BUTTON_CreateIndirect, "Home", ID_BUTTON_2, 710, 10, 60, 60, 0, 0x0, 0 },
- };
- /*********************************************************************
- *
- * _AddValues
- *
- * Function description
- * This routine calculates new random values in dependence of the previous added values
- * and adds them to the GRAPH_DATA objects
- */
- static void _AddValues(void) {
- for (int i = 0; i < MAX_GRAPHS; i++)
- GRAPH_DATA_YT_AddValue(_ahData[i++], i * 30 + rand() % 30);
- }
- /*********************************************************************
- *
- * _cbCallback
- *
- * Function description
- * Callback function of the dialog
- */
- WM_SCROLL_STATE scrollState;
- static void _cbCallback(WM_MESSAGE * pMsg) {
- unsigned i;
- int NCode;
- int Id;
- WM_HWIN hItem;
- switch (pMsg->MsgId) {
- case WM_INIT_DIALOG:
- //
- // Add graphs
- //
- hItem = WM_GetDialogItem(pMsg->hWin, GUI_ID_GRAPH0);
- for (i = 0; i < MAX_GRAPHS; i++) {
- _ahData[i] = GRAPH_DATA_YT_Create(_aColor[i], 2000, 0, 0);
- GRAPH_AttachData(hItem, _ahData[i]);
- }
- // Initialization of 'Home'
- hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2);
- BUTTON_SetText(hItem, "home");
- break;
- case WM_NOTIFY_PARENT:
- Id = WM_GetId(pMsg->hWinSrc);
- NCode = pMsg->Data.v;
- switch (NCode) {
- case WM_NOTIFICATION_RELEASED:
- switch (Id) {
- case ID_BUTTON_2: // Home
- GUI_EndDialog(pMsg->hWin, 0);
- break;
- }
- break;
- }
- break;
- default:
- WM_DefaultProc(pMsg);
- }
- }
- void MainTask(void) {
- GUI_Init();
- WM_SetDesktopColor(GUI_BLACK);
- WM_SetCreateFlags(WM_CF_MEMDEV);
- GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbCallback, 0, 0, 0);
- for (int i = 0; i < 100; i++)
- _AddValues();
- while (1) {
- GUI_Delay(20);
- _AddValues();
- }
- }