(03-31-2015 12:50 AM)Esenthel Wrote: The file is not created because most likely you need admin permission to write in root C folder.
That is not so simple as you think
File "enter.txt" is created, but "exit.txt" doesn't?
Ok to remove all misunderstandings let's use the following code:
Code:
/******************************************************************************/
void writeToLog(Str s)
{
C Str fname = "C:\\appLog.txt";
FileText f; f.append(fname); f.putLine(s);
}
/******************************************************************************/
class baba
{
baba(){ writeToLog("Constructor Called"); }
~baba(){ writeToLog("Destructor Called" ); }
}
baba bab;
Flt deltaTime, last_time;
/******************************************************************************/
void InitPre() // init before engine inits
{
EE_INIT();
App.flag = APP_WORK_IN_BACKGROUND|APP_NO_PAUSE_ON_WINDOW_MOVE_SIZE|APP_ALLOW_NO_GPU|APP_MINIMIZABLE|APP_EXIT_IMMEDIATELY;
writeToLog("IntPre Called");
LogConsole();
while(Update()){};
}
/******************************************************************************/
bool Init() // initialize after engine is ready
{
writeToLog("Init Called");
return true;
}
/******************************************************************************/
void Shut() // shut down at exit
{
writeToLog("Shut Called");
}
/******************************************************************************/
bool Update() // main updating
{
deltaTime = Time.curTime() - last_time;
if(Time.curTime() > 10)
return false;
return true;// continue
}
/******************************************************************************/
void Draw(){}
/******************************************************************************/
Now i answer your questions:
(03-31-2015 12:50 AM)Esenthel Wrote: Shut does get called with APP_EXIT_IMMEDIATELY enabled.
Yes, but
only when IntPre exits itself, without X button.
(03-31-2015 12:50 AM)Esenthel Wrote: Please do not call any of the Init Shut Update Draw manually, as these are callbacks called by the engine.
Ok, the new example doesn't do that.
(03-31-2015 12:50 AM)Esenthel Wrote: Handle your game server loop in 'Update'
How can i do that if application exits after IntPre function?
Let's do 3 tests together.
You can change
C Str fname = "C:\\appLog.txt"; to any file name you like.
Test 1. Run the code above and wait 10 seconds. Application will close itself.
What you expect in log:
Constructor Called
IntPre Called
Init Called
Shut Called
Destructor Called
What you get:
Constructor Called
IntPre Called
Shut Called
Destructor Called
What's wrong:
Init is NOT called
Test 2. Run the code above and close it with X button.
What you expect in log:
Constructor Called
IntPre Called
Shut Called
Destructor Called
What you get:
Constructor Called
IntPre Called
What's wrong:
No way, no Shut and no Destructor! A memory leak? I think the problem is that the engine calls Shut etc when the window recieves a message like WM_CLOSE or WM_QUIT or whatever. But with APP_EXIT_IMMEDIATELY there is NO window
Test 3. Remove while(Update()){}; from IntPre from the code above and run application.
What you expect in log:
Constructor Called
IntPre Called
Shut Called
Destructor Called
What you get:
Constructor Called
IntPre Called
Shut Called
Destructor Called
What's wrong:
In this case application is closed right after it is opened and Update is not handled by the engine so i can't do the following:
(03-31-2015 12:50 AM)Esenthel Wrote: Handle your game server loop in 'Update'
So what shall i do to get all destructors calls and Shut when i use X button to close the application?