void RecurseDestroy(CCObject * pObj) { if (pObj == NULL) return; if (pObj->isOfClass(CCObject::ClassOfCCDictionary)) { CCDictionary * pDict = (CCDictionary *)pObj; CCDictionary::const_iterator itDict = pDict->begin(); while(itDict != pDict->end()) { RecurseDestroy(itDict->second); itDict++; } pDict->erase(pDict->begin(), pDict->end()); V_SAFE_DELETE(pDict); } else if (pObj->isOfClass(CCObject::ClassOfCCArray)) { CCArray * pArray = (CCArray *)pObj; int iCount = (int)pArray->size(); for (int i = 0; i < iCount; i++) { RecurseDestroy((*pArray)[i]); } V_SAFE_DELETE(pArray); } else if (pObj->isOfClass(CCObject::ClassOfCCString)) { CCString * pString = (CCString*)pObj; V_SAFE_DELETE(pString); } else { V_SAFE_DELETE(pObj); } }
bool VRSDClient::StopProfiling(unsigned int* puiProfilingResultCount /*= NULL*/) { if(!m_bProfilingEnabled) return false; Vision::Callbacks.OnEditorModeChanged -= this; // tell the client language implementation that we are stopping to profile (just in case it has something special to do) if(GetClientLanguageImplementation()->StopProfiling()) { m_bProfilingEnabled = false; if(puiProfilingResultCount) *puiProfilingResultCount = m_pProfilingInformations.GetValidSize(); Vision::Error.SystemMessage("Stopped script profiling."); if(!SendProfilingResults()) Vision::Error.Warning("Couldn't transmit profiling results!"); else Vision::Error.SystemMessage("Sent profiling results."); V_SAFE_DELETE(m_pProfilingStack); unsigned int uiArraySize = m_pProfilingInformations.GetValidSize(); for(unsigned int i = 0; i < uiArraySize; i++) V_SAFE_DELETE(m_pProfilingInformations[i]); m_pProfilingInformations.Reset(); return true; } return false; }
VPlayableCharacterComponent::~VPlayableCharacterComponent() { V_SAFE_DELETE(m_pInputMap); #if defined(SUPPORTS_MULTITOUCH) V_SAFE_DELETE(m_pVirtualThumbStick); #endif Vision::Callbacks.OnVideoChanged -= this; }
void VScriptComponent::Serialize( VArchive &ar ) { char iLocalVersion = VERSION_CURRENT; IVObjectComponent::Serialize(ar); if (ar.IsLoading()) { ar >> iLocalVersion; if (iLocalVersion<VERSION_INITIAL||iLocalVersion>VERSION_CURRENT) hkvLog::FatalError("Invalid script serialization version - please re-export scene."); // This is a workaround for [#21287] : This component must be immediately added to the owner's component list, // otherwise script function calls on it create a new script component which results in one object having two script components // [8.1: need to serialize it here] VisTypedEngineObject_cl *pOwner = ar.ReadObject<VisTypedEngineObject_cl>(); if (pOwner != NULL && !pOwner->Components().Contains(this)) ((VObjectComponentCollection &)pOwner->Components()).Add(this); // additionally we have to temporarily pretend the owner is set: m_pOwner = pOwner; m_iScriptRefID = LUA_REFNIL; VScriptInstance *pInstance = NULL; ar >> pInstance; // we shouldn't call SetScriptInstance since it calls the Lua OnCreate function, which may try to access the object //SetScriptInstance(pInstance); m_spInstance = pInstance; if(iLocalVersion >= VERSION_CUSTOM_EXPOSED_MEMBERS) { int iNumOfSerializedMembers; ar >> iNumOfSerializedMembers; m_CustomExposeVars.Clear(); // read all members storead as Name+Type for(int i = 0;i < iNumOfSerializedMembers; i++) { char szBuffer1[64]; char szBuffer2[64]; bool bAllocated1 = false; bool bAllocated2 = false; const char *szName = ar.ReadEncryptedString(szBuffer1, 64, bAllocated1); const char *szValue = ar.ReadEncryptedString(szBuffer2, 64, bAllocated2); m_CustomExposeVars.Add(VScriptMember(szName, szValue)); if(bAllocated1) V_SAFE_DELETE(szName); if(bAllocated2) V_SAFE_DELETE(szValue); } }
bool VRSDClient::StartProfiling() { if(m_bProfilingEnabled) { StopProfiling(); return false; } Vision::Callbacks.OnEditorModeChanged += this; // tell the client language implementation that we are now profiling (just in case it has something special to do) if(GetClientLanguageImplementation()->StartProfiling()) { V_SAFE_DELETE(m_pProfilingStack); m_pProfilingStack = new VPListStack<VRSDProfilingSample*>(); m_bProfilingEnabled = true; Vision::Error.SystemMessage("Starting script profiling.."); return true; } /// \todo Editor Play Mode starten // if(!Vision::Editor.IsPlaying()) // Vision::Editor.SetMode(VisEditorManager_cl::EDITORMODE_PLAYING_IN_EDITOR); return false; }
void VRSDClient::HandleScriptEventForProfiling(VRSDScriptEvent* pScriptEvent) { if(!pScriptEvent) return; const char* pFileName = pScriptEvent->pFileName ? pScriptEvent->pFileName : ""; const char* pFunctionName = pScriptEvent->pFunctionName ? pScriptEvent->pFunctionName : ""; int iLineDefined = pScriptEvent->iLineDefined; // Note: This code is not very memory friendly.. if(pScriptEvent->eEventType == VRSDScriptEvent::EVENT_ENTER_FUNCTION) { m_pProfilingStack->Push(new VRSDProfilingSample(pFileName, pFunctionName, pScriptEvent->iLineDefined)); } else if(pScriptEvent->eEventType == VRSDScriptEvent::EVENT_LEAVE_FUNCTION) { // safe guard if(!m_pProfilingStack->IsEmpty()) { uint64 uiStopTime = VGLGetTimer(); VRSDProfilingSample* pSample = m_pProfilingStack->Pop(); uint64 uiTimeTaken = uiStopTime - pSample->m_uiStartTime; // Store the profiling information UpdateProfilingInformation(pFileName, iLineDefined == -1 ? "(native)" : pFunctionName, iLineDefined, uiTimeTaken); V_SAFE_DELETE(pSample); } } }
void VRendererNodeCommon::OnHandleCallback(IVisCallbackDataObject_cl *pData) { if (pData->m_pSender == &Vision::Callbacks.OnBeforeVideoChanged) { if (GetFinalTargetContext() != NULL && RendersIntoBackBuffer() && IsInitialized()) { m_pDeinitDuringVideoResize = new VScopedRendererNodeDeinit(this); } } else if (pData->m_pSender == &Vision::Callbacks.OnVideoChanged) { V_SAFE_DELETE(m_pDeinitDuringVideoResize); } #if defined(_VISION_WIN32) && defined(_VR_DX9) else if (pData->m_pSender == &Vision::Callbacks.OnEnterForeground) { if(IsInitialized()) { InitializePostProcessors(); } } #endif else if (pData->m_pSender == &Vision::Callbacks.OnUpdateSceneFinished) { UpdateTimeOfDay(); } }
void VStringInputMapManager::Release() { for(unsigned int i=0; i<(unsigned int)m_instances.GetSize(); i++) { V_SAFE_DELETE(m_instances[i]); } }
bool VFmodAnimationEventSoundTrigger::CommonInit() { // Initialize base component if (!IVAnimationEventTrigger::CommonInit()) return false; // Fill the event trigger info if (m_iEventTriggerInfoCount <= 0) { VFmodEventSoundTriggerInfo_t* info = NULL; if(m_pActiveTriggerInfo == NULL) //make sure it does not get created more than once { // Create new list with only one entry and set properties info = new VFmodEventSoundTriggerInfo_t(); } else { info = (VFmodEventSoundTriggerInfo_t*)m_pActiveTriggerInfo; } // Get sound resource info->m_spSoundResource = VFmodManager::GlobalManager().LoadSoundResource(SoundFilename, VFMOD_RESOURCEFLAG_DEFAULT); if (info->m_spSoundResource == NULL || !GetEventTriggerInfoBaseData(info)) //set sequence and event id { V_SAFE_DELETE(info); m_pActiveTriggerInfo = NULL; return false; } // Set it as the active event trigger info m_pActiveTriggerInfo = info; } return true; }
VThrowItemComponent::~VThrowItemComponent() { // Register Callback Vision::Callbacks.OnUpdateSceneBegin -= this; V_SAFE_DELETE(m_pInputMap); }
inline void DestroyMap(VStringInputMap * pMap) { if (pMap != NULL) { V_SAFE_DELETE(pMap); } }
void VRendererNodeCommon::DeInitializeSharedFeatures() { FreeCustomTextureRefs(m_spSceneDepthTechnique); FreeCustomTextureRefs(m_spDepthOnlyTechnique); m_spColorReadTarget = NULL; m_spDepthReadTarget = NULL; m_spSceneDepthTechnique = NULL; m_spDepthOnlyTechnique = NULL; V_SAFE_DELETE(m_pColorBufferResolver); #ifdef _VISION_XENON FreeCustomTextureRefs(m_spDepthOnlyTechnique360); if(m_bDepthRestoreInitialized) { VisHiZHelper_cl::DestroyFastDepthRestore(m_fastRestoreData); m_bDepthRestoreInitialized = false; } m_spDepthOnlyTechnique360 = NULL; #endif #ifdef _VISION_PS3 m_spDummyDepthTexture = NULL; #endif }
void VRendererNodeCommon::UpdateColorBufferResolver() { const bool bNeedsColorResolver = m_ObjectsUsingResolvedColorBuffer.GetCount() > 0; if (bNeedsColorResolver) { if (m_pColorBufferResolver == NULL) { m_pColorBufferResolver = new VBufferResolver(this, GetReferenceContext(), m_uiResolveColorBufferRenderHook); if (!m_pColorBufferResolver->Initialize(VBufferResolver::VIM_CreateNewResolveBuffer)) { V_SAFE_DELETE(m_pColorBufferResolver); return; } } if(m_iAutomaticResolveCounter > 0) { m_pColorBufferResolver->SetRenderHook(m_uiResolveColorBufferRenderHook); } else { m_pColorBufferResolver->SetRenderHook(VRH_INVALID); } } else { // If we have an existing color buffer resolver, just disable it - it's very likely we will need it again later. if(m_pColorBufferResolver) { m_pColorBufferResolver->SetRenderHook(VRH_INVALID); } } }
extern "C" bool VisionRunFunction() { VASSERT(VAppIOS::s_pAppInstance != NULL); if ((VAppIOS::s_pStartupModules != NULL) && (VAppIOS::s_pStartupModules->GetSize() > 0)) { if (VAppIOS::ProcessStartupModule(0)) return true; delete VAppIOS::s_pStartupModules->GetAt(0).m_pModule; VAppIOS::s_pStartupModules->RemoveAt(0); if(static_cast<VAppIOS*>(VAppBase::Get())->WantsToQuit()) { V_SAFE_DELETE(static_cast<VAppIOS*>(VAppBase::Get())->m_pAppImpl); return false; } if (VAppIOS::s_pStartupModules->GetSize() > 0) VAppIOS::s_pStartupModules->GetAt(0).m_pModule->Init(); else VAppIOS::s_pAppInstance->AppInit(); return true; } else { return VAppIOS::s_pAppInstance->AppRun(); } }
void VAppBase::ProcessStartupModules() { if (s_pStartupModules == NULL) return; while (s_pStartupModules->GetSize() > 0 && !VAppBase::Get()->WantsToQuit()) { VStartupModule* pModule = s_pStartupModules->GetAt(0).m_pModule; s_pStartupModules->RemoveAt(0); pModule->Init(); // Run the startup module as long it returns true bool bResult = true; while (bResult) { bResult &= VAppBase::Get()->PlatformRun(); bResult = bResult && pModule->Run(); } pModule->DeInit(); delete pModule; } V_SAFE_DELETE(s_pStartupModules); }
void VAppBase::OnHandleCallback(IVisCallbackDataObject_cl* pData) { if (pData->m_pSender == &Vision::Callbacks.OnBeforeSceneLoaded) { m_eAppState = VAppHelper::AS_SCENE_LOADING; } else if (pData->m_pSender == &Vision::Callbacks.OnLeaveForeground) { if (m_eAppState == VAppHelper::AS_RUNNING) { // On WIN32 this event is already triggered inside Run(). #if !defined(WIN32) // Draw frame to enable application modules to grab frame buffer // content via Vision::Callbacks.OnBeforeSwapBuffers Run(); #endif } } else if (pData->m_pSender == &Vision::Callbacks.OnEngineInit) { Vision::Callbacks.OnLeaveForeground += this; } else if (pData->m_pSender == &Vision::Callbacks.OnEngineDeInit) { Vision::Callbacks.OnLeaveForeground -= this; VASSERT(m_pAppImpl != NULL); m_pAppImpl->EngineDeInit(); V_SAFE_DELETE(m_pAppImpl); } }
VRSDClient::~VRSDClient() { SetClientLanguageImplementation(NULL); m_pConnection = NULL; // clear user data accessors for(int i = 0; i < m_UserDataAccessors.GetLength(); i++) { V_SAFE_DELETE(m_UserDataAccessors[i]); } V_SAFE_DELETE(m_pProfilingStack); unsigned int uiArraySize = m_pProfilingInformations.GetValidSize(); for(unsigned int i = 0; i < uiArraySize; i++) V_SAFE_DELETE(m_pProfilingInformations[i]); }
void VPostProcessTranslucencies::DeInitializePostProcessor() { if (!m_bIsInitialized) return; V_SAFE_DELETE(m_TempParticleGroupCollection); V_SAFE_DELETE(m_TempMeshBufferObjectCollection); #if !defined(_VISION_MOBILE) && !defined(_VISION_PSP2) m_spLowResContext = NULL; m_spLowResDepthTexture = NULL; m_spLowResColorTexture = NULL; #endif GetOwner()->RemoveContext(GetTargetContext()); m_bIsInitialized = false; }
bool VAnimationEventEffectTrigger::CommonInit() { // Initialize base component if (!IVTransitionEventTrigger::CommonInit()) return false; // Get owner entity VisBaseEntity_cl *pEntity = (VisBaseEntity_cl *)m_pOwner; if (pEntity == NULL) return false; // Fill the event trigger info if (m_iEventTriggerInfoCount <= 0) { VEventEffectTriggerInfo_t* info = NULL; if(m_pActiveTriggerInfo == NULL) //make sure it does not get created more than once { // Create new list with only one entry and set properties info = new VEventEffectTriggerInfo_t(); } else { info = (VEventEffectTriggerInfo_t*)m_pActiveTriggerInfo; } info->m_vPositionOffset = PositionOffset; info->m_vOrientationOffset= OrientationOffset; // Get effect file info->m_spEffectFile = VisParticleGroupManager_cl::GlobalManager().LoadFromFile(EffectFilename); if (info->m_spEffectFile == NULL || !GetEventTriggerInfoBaseData(info)) { V_SAFE_DELETE(info); m_pActiveTriggerInfo = NULL; return false; } // Get Bone Index if specified if (!AttachToBone.IsEmpty()) { VDynamicMesh* pMesh = pEntity->GetMesh(); if (pMesh == NULL) return false; VisSkeleton_cl *pSkeleton = pMesh->GetSkeleton(); if (pSkeleton == NULL) return false; info->m_iAttachToBone = pSkeleton->GetBoneIndexByName(AttachToBone); } // Set it as the active event trigger info m_pActiveTriggerInfo = info; } return true; }
VSampleTouchMenu::~VSampleTouchMenu() { Vision::Callbacks.OnUpdateSceneBegin -= this; for(int i=0;i<m_Children.GetSize();i++) { m_InputMap.SetMapping(m_Children[i]->m_iControlIndex, m_Children[i]->m_iAlternative, NULL); V_SAFE_DELETE(m_Children[i]); } }
VDialog::~VDialog() { // necessary to clear these to have a well defined de-init order in case OnControlDisposed is called at the end of this d'tor m_spFocusItem = NULL; for (int i=0;i<VGUIUserInfo_t::GUIMaxUser;i++) m_spMouseOverItem[i] = NULL; V_SAFE_DELETE(m_pImage); }
void VDebugOptions::DeInit() { Vision::Callbacks.OnUpdateSceneBegin -= this; Vision::Callbacks.OnBeforeSwapBuffers -= this; Vision::Callbacks.OnRenderHook -= this; DeRegisterCallbacks(); DeRegisterCallbacks(m_debugInfos); V_SAFE_DELETE(m_pTimeStepGraph); }
inline VStringInputMap * CreateMap(const char * szMapName, int iNumTriggers=32, int iNumAlternatives=4) { // Check if map already exists VStringInputMap* pMap = VStringInputMap::FindByKey(szMapName); if (pMap != NULL) { V_SAFE_DELETE(pMap); } return new VStringInputMap(szMapName, iNumTriggers, iNumAlternatives); }
void RPG_Effect::DisposeObject() { // ensure that attachment is cleared in the event of a termination without Finish() if (m_attachment) { V_SAFE_DELETE(m_attachment); m_attachment = NULL; } RPG_BaseEntity::DisposeObject(); }
void VArabicSupport_cl::SetText(const VString & utf8ArabicText, bool isContextualArabic, bool duplicateSpacesDuringConversion) { // Convert to wide char as Arabic support helper requires wide char strings. int iBufSize = utf8ArabicText.GetLen() + 1; wchar_t *pWCharBuf = new wchar_t[iBufSize]; V_UTF8_TO_WCHAR(utf8ArabicText.AsChar(), pWCharBuf, iBufSize); SetText(pWCharBuf, isContextualArabic, duplicateSpacesDuringConversion); V_SAFE_DELETE(pWCharBuf); }
void VRTLSupport_cl::SetText(const wchar_t *pText) { VASSERT(pText!=NULL); //clear text vars for multiple SetText calls if(m_ppTextLines!=NULL) { for(int i=0;i<m_iTextLines;i++) { V_SAFE_FREE(m_ppTextLines[i]); } } V_SAFE_FREE(m_ppTextLines); //create a tokenizer in order to separate the text lines VArrayHelper_cl<wchar_t> tokenizer(pText, L"\n"); //create line pointers m_iTextLines = tokenizer.CalcNumberOfTokens(); m_ppTextLines = (char **)vMemAlloc(m_iTextLines * sizeof(char *)); int iLineIndex=0; int iWLen, iSize; while( tokenizer.HasNextToken() ) { //get the current text line const wchar_t *pCurrentLine = tokenizer.NextToken(); //length of the current line int iLength = VArrayHelper_cl<wchar_t>::Length(pCurrentLine); //allocate the target buffer (original length + terminator) wchar_t *pReversed = (wchar_t *) vMemAlloc(sizeof(wchar_t)*(iLength+1)); //pre-terminate buffer pReversed[iLength] = 0; //transform LTR to RTL for(int i=0;i<iLength;i++) { pReversed[iLength-i-1] = pCurrentLine[i]; } // Convert to UTF8 and assign the reversed line iWLen = (int)wcslen(pReversed); iSize = VString::ConvertWCharToUTF8String(pReversed, iWLen, NULL, 0); m_ppTextLines[iLineIndex] = new char[iSize+1]; VString::ConvertWCharToUTF8String(pReversed, iWLen, m_ppTextLines[iLineIndex], iSize); m_ppTextLines[iLineIndex][iSize] = '\0'; V_SAFE_DELETE(pReversed); iLineIndex++; } }
void VRTLSupport_cl::SetText(const VString & utf8String) { // Convert to wide char as RTL support helper requires wide char strings. int iBufSize = utf8String.GetLen() + 1; wchar_t *pWCharBuf = new wchar_t[iBufSize]; V_UTF8_TO_WCHAR(utf8String.AsChar(), pWCharBuf, iBufSize); SetText(pWCharBuf); V_SAFE_DELETE(pWCharBuf); }
void ClothEntity_cl::DeInitFunction() { VThreadedTask *pTask = GetPreparationTask(); if (pTask!=NULL) { WAIT_UNTIL_FINISHED(pTask); SetPreparationTask(NULL); V_SAFE_DELETE(pTask); } m_spMesh = NULL; }
void RPG_GuiManager::DestroyInstance() { if (s_instance) { V_SAFE_DELETE(s_instance); s_instance = NULL; } else { VASSERT_MSG(false, "Tried to destroy GUIManager instance after it has already been destroyed."); } }
void VFmodManager::OneTimeDeInit() { Vision::UnregisterModule(&g_FmodModule); Vision::ResourceSystem.UnregisterResourceManager(m_pSoundResourceManager); V_SAFE_DELETE(m_pSoundResourceManager); Vision::ResourceSystem.UnregisterResourceManager(m_pEventGroupManager); V_SAFE_DELETE(m_pEventGroupManager); Vision::Callbacks.OnEngineInit -= this; Vision::Callbacks.OnEngineDeInit -= this; Vision::Callbacks.OnWorldInit -= this; Vision::Callbacks.OnWorldDeInit -= this; Vision::Callbacks.OnUpdateSceneFinished -= this; #if defined(_VISION_MOBILE) Vision::Callbacks.OnLeaveForeground -= this; Vision::Callbacks.OnEnterForeground -= this; #endif IVScriptManager::OnRegisterScriptFunctions -= this; }