This function attempts to release all device resources that have been allocated using the D3DPOOL_DEFAULT pool (level == TRIRO_DEFAULT) or all device resources (level == TRIRO_ALL). This is necessary prior to resetting the device.
| 491 | //using the D3DPOOL_DEFAULT pool (level == TRIRO_DEFAULT) or all device resources (level == TRIRO_ALL). |
| 492 | //This is necessary prior to resetting the device. |
| 493 | void TriDevice::ReleaseDeviceResources( TriStorage s ) |
| 494 | { |
| 495 | // Call those objects that registered with us. This is the preferred modus operandi in future. |
| 496 | //The new resource registry. Objects put themselves here. |
| 497 | auto& rs = GetResourcesRegistered(); |
| 498 | |
| 499 | s_iteratingForRelease = true; |
| 500 | for( auto it = rs.begin(); it != rs.end(); ++it ) |
| 501 | { |
| 502 | if( !*it ) |
| 503 | { |
| 504 | CCP_LOGWARN( "NULL TriDeviceResource found in resource set during TriDevice::ReleaseDeviceResources!" ); |
| 505 | } |
| 506 | else if( s_resourcesToBeRemoved.find( *it ) != s_resourcesToBeRemoved.end() ) |
| 507 | { |
| 508 | // ignore, was Unregistered while iterating. We could erase() right here and now, |
| 509 | // but then we could leave an object dangling until the next reset: happens if we already |
| 510 | // saw that object earlier in this loop, but gets unregistered due to a ReleaseResources |
| 511 | // call that comes next. |
| 512 | } |
| 513 | else |
| 514 | { |
| 515 | ( *it )->ReleaseResources( s ); |
| 516 | } |
| 517 | } |
| 518 | s_iteratingForRelease = false; |
| 519 | for( auto it = s_resourcesToBeRemoved.cbegin(); it != s_resourcesToBeRemoved.cend(); ++it ) |
| 520 | { |
| 521 | rs.erase( *it ); |
| 522 | } |
| 523 | s_resourcesToBeRemoved.clear(); |
| 524 | |
| 525 | USE_MAIN_THREAD_RENDER_CONTEXT(); |
| 526 | |
| 527 | // Same goes for the effect state manager |
| 528 | renderContext.m_esm.ReleaseDeviceResources( s ); |
| 529 | Tr2Renderer::ReleaseDeviceResources( s ); |
| 530 | |
| 531 | #if BLUE_WITH_PYTHON |
| 532 | //And the python objects too: |
| 533 | if( m_pyResourceSet ) |
| 534 | { |
| 535 | auto gil = PyGILState_Ensure(); |
| 536 | ON_BLOCK_EXIT( [&gil] { PyGILState_Release( gil ); } ); |
| 537 | |
| 538 | #if PY_MAJOR_VERSION == 2 |
| 539 | BluePySeq keys = BluePy( PyObject_CallMethod( m_pyResourceSet, const_cast<char*>( "keys" ), 0 ) ); |
| 540 | if( !keys ) |
| 541 | { |
| 542 | CCP_LOGERR( "TriDev: Python callback failed in \"ReleaseDeviceResources\"" ); |
| 543 | PyOS->PyError(); |
| 544 | } |
| 545 | Py_ssize_t n = keys.Size(); |
| 546 | for( Py_ssize_t i = 0; i < n; i++ ) |
| 547 | { |
| 548 | BluePy item( keys.Get( i ) ); |
| 549 | if( !PyObject_HasAttrString( item.o, "OnInvalidate" ) ) |
| 550 | { |
nothing calls this directly
no test coverage detected