Archived

This topic is now archived and is closed to further replies.

Nacho

Problems with GUI implementation

Recommended Posts

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!!

Share this post


Link to post
Share on other sites
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 ]

Share this post


Link to post
Share on other sites
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;

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites