Использую glut.
Функция glutMainLoop; не возвращает управление в вызывающую функцию, то есть после неё что-либо писать бессмысленно. А при выходе из программы надо сделать определённые действия (память освободить).
В интернете пока нашёл только это: http://opengl.org.ru/docs/faq/glut.htm
3.070 I have a GLUT program that allocates memory at startup. How do I deallocate this memory when the program exits?
If the user exits your program through some input that you can catch, such as a key press or menu selection, the answer is trivial. Simply free the resources in the appropriate input event handler.
Normally, this question comes up because the user has killed the program through window frame controls, such as the Microsoft Windows Close Window icon in the upper right corner of the title bar. In this case, your program won't get an event indicating the program is exiting.
For simple resources such as memory deallocation, this should not be a problem. The OS will free any memory that was in use by the process.
Of greater concern is prompting the user to save work or flushing data held in software buffers to files.
Unfortunately, GLUT doesn't provide a mechanism to handle such events, because the OS or window manager is killing the process in a forceful way.
One option is to hack the GLUT source, and disable the Close Window icon in the window frame title bar. This is distasteful, for it means you must now include the entire GLUT window creation code in your application.
In short, there is no good answer to this problem. Users, in general, should not expect good results when they exit an application in this way.
Лезть ковыряться в исходниках этого Глюта, а потом таскать его с собой не очень хочется.
Что делать, подскажите. Есть же, наверно, другие пути?
zorin29
Перехвати WM_CLOSE - это сообщение получает окно при закрытии. Не знаю, как это делается на Си, могу написать только на Дельфи.
Dmitriy82
atexit(<какая-нибудь функция>). У меня в машграфе так было написано, правда не проверял,
выполняется ли.
mmvtiko
Использую glut.Функция glutMainLoop; не возвращает управление в вызывающую функцию, то есть после неё что-либо писать бессмысленно. А при выходе из программы надо сделать определённые действия (память освободить).
В интернете пока нашёл только это:
http://opengl.org.ru/docs/faq/glut.htm
Лезть ковыряться в исходниках этого Глюта, а потом таскать его с собой не очень хочется.
Что делать, подскажите. Есть же, наверно, другие пути?