void CComponentInstanceManager::CloseFile(uint32_t uFileId) { std::vector<CComponentBase*> componentToDelete; UnloadFile(uFileId, &componentToDelete); BEYONDENGINE_CHECK_HEAP; for (size_t i = 0; i < componentToDelete.size(); ++i) { CComponentBase* pComponentBase = componentToDelete[i]; if (pComponentBase->IsInitialized()) { pComponentBase->Uninitialize(); } else { uint32_t uComponentId = pComponentBase->GetId(); if (uComponentId != 0xFFFFFFFF) { CComponentInstanceManager::GetInstance()->UnregisterInstance(pComponentBase); CComponentInstanceManager::GetInstance()->GetIdManager()->RecycleId(uComponentId); } } BEYONDENGINE_CHECK_HEAP; } for (uint32_t i = 0; i < componentToDelete.size(); ++i) { BEATS_SAFE_DELETE(componentToDelete[i]); BEYONDENGINE_CHECK_HEAP; } }
Video::~Video() { UnloadFile(); for (unsigned int i = 0; i < frameList.size(); i++) { delete frameList[i]; } frameList.clear(); }
//----------------------------------- /// Read the config file into memory /// Returns true for success bool CConfig::LoadFile(char * file) //----------------------------------- { char ch; FILE * fp; UnloadFile(); // open file fp = fopen(file, "r"); if (fp == NULL || fp == (FILE *)-1) { //fprintf(stderr,"Failed to open config file %s!",file); return false; } // get length of file fseek(fp,0,SEEK_END); long length = ftell(fp); rewind(fp); // allocate buffer pConfig = new char[length + 1]; if (pConfig == NULL) { fclose(fp); fprintf(stderr,"Failed to alloc config buffer length %d",(int32)length); return false; } memset(pConfig,0,length); // read data, stripping comments int i = 0; while (i < length) { ch = fgetc(fp); if (feof(fp)) break; if (ch == '#') { while (ch != 10 && !feof (fp)) { ch = fgetc(fp); } } pConfig[i++] = ch; } pConfig[i] = 0; // mark end of file buffer fclose(fp); return true; }
HRESULT KRLTarget::Exit() { HRESULT hr = E_FAIL; hr = Hide(); KGLOG_COM_CHECK_ERROR(hr); hr = UnloadFile(); KGLOG_COM_CHECK_ERROR(hr); m_pRLScene = NULL; return S_OK; }
TRESULT CFile::ReloadFile() { UnloadFile(); if( m_FileName.empty() || m_Mode.empty() ) return RE_FAILED; errno_t err = _wfopen_s( &m_pFilePtr, m_FileName.c_str(), m_Mode.c_str() ); if( err != 0 || NULL == m_pFilePtr ) { assert(0 && !"Can't open the file"); return RE_FAILED; } LoadFile(); fclose( m_pFilePtr ); m_pFilePtr = NULL; return RE_SUCCEED; }
void CComponentProxyManager::CloseFile(uint32_t uFileId) { ReSaveFreshFile(); // the file we are about to close may be in the fresh file list, so we always try to save it before it is closed. // TODO: Lock id manager, since we will recycle id in component's un-initialize function. // However, we don't want that, so we lock the id manager for now. m_pIdManager->Lock(); std::vector<CComponentBase*> unloadProxyList; UnloadFile(uFileId, &unloadProxyList); std::vector<CComponentBase*> componentToDelete; for (size_t i = 0; i < unloadProxyList.size(); ++i) { CComponentProxy* pProxy = static_cast<CComponentProxy*>(unloadProxyList[i]); componentToDelete.push_back(pProxy->GetHostComponent()); } for (uint32_t i = 0; i < componentToDelete.size(); ++i) { CComponentBase* pComponentBase = componentToDelete[i]; BEATS_ASSERT(!pComponentBase->IsLoaded()); if (pComponentBase->IsInitialized()) { pComponentBase->Uninitialize(); } } for (uint32_t i = 0; i < componentToDelete.size(); ++i) { CComponentBase* pComponentBase = componentToDelete[i]; BEATS_ASSERT(!pComponentBase->IsInitialized()); BEATS_SAFE_DELETE(pComponentBase); } if (GetCurrentViewFileId() == uFileId) { SetCurrentViewFileId(0xFFFFFFFF); } if (GetCurrLoadFileId() == uFileId) { SetCurrLoadFileId(0xFFFFFFFF); } m_pIdManager->UnLock(); }