If the game can be run through Steam, the app is restarted through Steam directly. Make sure OnUserDestroy() gets called if the game is killed when OnUserCreate() returns false to free all resources. Release Build 8224.

This commit is contained in:
sigonasr2 2024-03-22 00:59:55 -05:00
parent ae6bab6176
commit 66f91578cf
4 changed files with 10 additions and 4 deletions

View File

@ -322,17 +322,19 @@ bool AiL::OnUserCreate(){
ValidateGameStatus(); //Checks to make sure everything has been initialized properly. ValidateGameStatus(); //Checks to make sure everything has been initialized properly.
#ifndef __EMSCRIPTEN__ #ifndef __EMSCRIPTEN__
SetupDiscord(); SetupDiscord();
if(SteamAPI_RestartAppIfNecessary(2895980U))return false; //Immediately quit if steam is detected and can be started through it.
if(SteamAPI_Init()){ if(SteamAPI_Init()){
std::cout<<"Steam API Initialized successfully!"<<std::endl; std::cout<<"Steam API Initialized successfully!"<<std::endl;
}else{ }else{
std::cout<<"Steam API failed to initialize!"<<std::endl; std::cout<<"Steam API failed to initialize!"<<std::endl;
} }
if(SteamAPI_IsSteamRunning()){ if(SteamUtils()!=nullptr)
SteamUtils()->SetWarningMessageHook([](int severity,const char*message){ SteamUtils()->SetWarningMessageHook([](int severity,const char*message){
std::cout<<std::format("STEAM[{}]: {}",severity,std::string(message))<<std::endl; std::cout<<std::format("STEAM[{}]: {}",severity,std::string(message))<<std::endl;
}); });
if(SteamInput()!=nullptr)
SteamInput()->Init(false); SteamInput()->Init(false);
}
#endif #endif
gameInitialized=true; gameInitialized=true;
@ -2783,6 +2785,7 @@ bool AiL::IsReflectiveTile(TilesheetData tileSheet,int tileID){
} }
bool AiL::OnUserDestroy(){ bool AiL::OnUserDestroy(){
SteamAPI_Shutdown();
GFX.Reset(); GFX.Reset();
for(auto&[key,value]:MAP_DATA){ for(auto&[key,value]:MAP_DATA){
if(MAP_DATA[key].optimizedTile!=nullptr){ if(MAP_DATA[key].optimizedTile!=nullptr){

View File

@ -39,7 +39,7 @@ All rights reserved.
#define VERSION_MAJOR 0 #define VERSION_MAJOR 0
#define VERSION_MINOR 5 #define VERSION_MINOR 5
#define VERSION_PATCH 1 #define VERSION_PATCH 1
#define VERSION_BUILD 8221 #define VERSION_BUILD 8224
#define stringify(a) stringify_(a) #define stringify(a) stringify_(a)
#define stringify_(a) #a #define stringify_(a) #a

View File

@ -4715,7 +4715,10 @@ namespace olc
// Create user resources as part of this thread // Create user resources as part of this thread
for (auto& ext : vExtensions) ext->OnBeforeUserCreate(); for (auto& ext : vExtensions) ext->OnBeforeUserCreate();
if (!OnUserCreate()) bAtomActive = false; if (!OnUserCreate()){
bAtomActive = false;
OnUserDestroy();
}
for (auto& ext : vExtensions) ext->OnAfterUserCreate(); for (auto& ext : vExtensions) ext->OnAfterUserCreate();
while (bAtomActive) while (bAtomActive)