Problems with GUI implementation

Started by
3 comments, last by Nacho 21 years, 8 months ago
Hi! I´m coding a GUI with DirectX and I´m having a little trouble with the list of windows. Ok, here´s the situation: I´ve got an ABC called CWindow. Up to this moment there are two classes that derive from it and override its only pure virtual method Render, these are CButton and CGraph. Since I´m not the person who is actually designing the GUI, my teammate who is in charge of that gives me a bunch of bitmaps and a text file that has all the information to build the GUI (total number of controls, size and position for every window, name of the associated bitmap, etc.) Since I don´t know at compile-time neither how many windows will I have to allocate room for nor which class are them (Button ,Graph, etc.) I use the following approach: I declare a pointer to a pointer to a CWindow inside WinMain and I pass it to the LoadGUI function like this: CWindow **lpWindow = NULL; int iTotalControls; // It is validated inside LoadGUI(). LoadGUI(hWnd,lpDD,lpWindow,iTotalControls); // lpDD is a valid DDraw4 object. The most important snippets inside LoadGUI() are: if(NULL==(lpFile = fopen("GUI2.txt","r"))) return INIT_FAILED; fscanf(lpFile,"Total Controls: %d\n\n",&iTotalControls); lpWindow = new CWindow*[iTotalControls]; for(iLoop=0;iLoop; delete [] lpWindow; lpWindow = NULL; The program crashes in this part of the code. I´m completely sure about that because I commented out this snippet and the program worked and exited fine. What do you think I should do? Thanks in advance!!
Advertisement
Looks like you''re using the wrong delete operator. Delete all the windows using "delete" and only then use "delete []" on the array of pointers.

You should really use std::vector though, as it helps get rid of the pointer-to-pointer ugliness and confusion.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files | My stuff ]
Looking at your answer I realized that my message got messed when I posted it. Here´s the shutdown snippet again:

for(i=0;
ii++)
delete [] lpWindow;

delete [] lpWindow;
lpWindow = NULL;
The condition for that for loop is 'i < iTotalControls'.

[edited by - Ignacio Liverotti on August 12, 2002 2:28:48 PM]
I´ve found the mistake! There is an array of offscreen surfaces inside CWindow and I forgot to release them before deleting the CWindow pointers. Thanks for your help Kylotan!

This topic is closed to new replies.

Advertisement