diff options
| -rw-r--r-- | demos/main/main.cpp | 1 | ||||
| -rw-r--r-- | include/cru/ui/render/LayoutRenderObject.h | 39 | ||||
| -rw-r--r-- | src/platform/graphics/direct2d/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/platform/graphics/direct2d/Factory.cpp | 12 | ||||
| -rw-r--r-- | src/platform/gui/win/UiApplication.cpp | 5 |
5 files changed, 39 insertions, 20 deletions
diff --git a/demos/main/main.cpp b/demos/main/main.cpp index 70861539..71c084ec 100644 --- a/demos/main/main.cpp +++ b/demos/main/main.cpp @@ -1,7 +1,6 @@ #include "cru/platform/bootstrap/Bootstrap.h" #include "cru/platform/gui/UiApplication.h" #include "cru/platform/gui/Window.h" -#include "cru/ui/Base.h" #include "cru/ui/components/PopupButton.h" #include "cru/ui/components/Select.h" #include "cru/ui/controls/Button.h" diff --git a/include/cru/ui/render/LayoutRenderObject.h b/include/cru/ui/render/LayoutRenderObject.h index c0e4218d..9970c16c 100644 --- a/include/cru/ui/render/LayoutRenderObject.h +++ b/include/cru/ui/render/LayoutRenderObject.h @@ -11,9 +11,11 @@ class LayoutRenderObject : public RenderObject { private: struct ChildData { + /** + * May be nullptr. + */ RenderObject* render_object; ChildLayoutData layout_data; - bool render_object_destroyed; EventHandlerRevokerListGuard event_guard; }; @@ -27,32 +29,36 @@ class LayoutRenderObject : public RenderObject { ~LayoutRenderObject() override = default; Index GetChildCount() const { return static_cast<Index>(children_.size()); } + RenderObject* GetChildAt(Index position) { Expects(position >= 0 && position < GetChildCount()); return children_[position].render_object; } + void AddChild(RenderObject* render_object, Index position) { if (position < 0) position = 0; if (position > GetChildCount()) position = GetChildCount(); - children_.insert(children_.begin() + position, - ChildData{render_object, ChildLayoutData(), false}); + auto iter = children_.insert(children_.begin() + position, + ChildData{render_object, ChildLayoutData()}); render_object->SetParent(this); - render_object->DestroyEvent()->AddSpyOnlyHandler([this, render_object] { - auto iter = std::ranges::find_if( - children_, [render_object](const ChildData& data) { - return data.render_object == render_object; - }); - if (iter != children_.cend()) { - iter->render_object_destroyed = true; - } - }); + iter->event_guard += + render_object->DestroyEvent()->AddSpyOnlyHandler([this, render_object] { + auto iter = std::ranges::find_if( + children_, [render_object](const ChildData& data) { + return data.render_object == render_object; + }); + if (iter != children_.cend()) { + iter->render_object = nullptr; + } + }); InvalidateLayout(); } void RemoveChild(Index position) { Expects(position >= 0 && position < GetChildCount()); - if (!children_[position].render_object_destroyed) { - children_[position].render_object->SetParent(nullptr); + auto render_object = children_[position].render_object; + if (render_object) { + render_object->SetParent(nullptr); } children_.erase(children_.begin() + position); InvalidateLayout(); @@ -60,8 +66,9 @@ class LayoutRenderObject : public RenderObject { void ClearChildren() { for (auto child : children_) { - if (!child.render_object_destroyed) { - child.render_object->SetParent(nullptr); + auto render_object = child.render_object; + if (render_object) { + render_object->SetParent(nullptr); } } children_.clear(); diff --git a/src/platform/graphics/direct2d/CMakeLists.txt b/src/platform/graphics/direct2d/CMakeLists.txt index 322c91e9..e5fb9faf 100644 --- a/src/platform/graphics/direct2d/CMakeLists.txt +++ b/src/platform/graphics/direct2d/CMakeLists.txt @@ -11,6 +11,6 @@ add_library(CruPlatformGraphicsDirect2d WindowPainter.cpp WindowRenderTarget.cpp ) -target_link_libraries(CruPlatformGraphicsDirect2d PUBLIC D3D11 D2d1 DWrite) +target_link_libraries(CruPlatformGraphicsDirect2d PUBLIC D3D11 D2d1 DWrite dxgi dxguid) target_link_libraries(CruPlatformGraphicsDirect2d PUBLIC CruPlatformGraphics) target_compile_definitions(CruPlatformGraphicsDirect2d PRIVATE CRU_WIN_GRAPHICS_DIRECT_EXPORT_API) diff --git a/src/platform/graphics/direct2d/Factory.cpp b/src/platform/graphics/direct2d/Factory.cpp index 6be4f797..ef355c72 100644 --- a/src/platform/graphics/direct2d/Factory.cpp +++ b/src/platform/graphics/direct2d/Factory.cpp @@ -6,6 +6,9 @@ #include "cru/platform/graphics/direct2d/ImageFactory.h" #include "cru/platform/graphics/direct2d/TextLayout.h" +#include <dxgi1_3.h> +#include <dxgidebug.h> +#include <cstdlib> #include <utility> namespace cru::platform::graphics::direct2d { @@ -18,6 +21,13 @@ DirectGraphicsFactory::DirectGraphicsFactory() : DirectGraphicsResource(this) { #ifdef CRU_DEBUG creation_flags |= D3D11_CREATE_DEVICE_DEBUG; + + atexit([] { + Microsoft::WRL::ComPtr<IDXGIDebug1> dxgi_debug; + CheckHResult(DXGIGetDebugInterface1(0, IID_PPV_ARGS(&dxgi_debug))); + CheckHResult( + dxgi_debug->ReportLiveObjects(DXGI_DEBUG_ALL, DXGI_DEBUG_RLO_ALL)); + }); #endif const D3D_FEATURE_LEVEL feature_levels[] = { @@ -36,7 +46,7 @@ DirectGraphicsFactory::DirectGraphicsFactory() : DirectGraphicsResource(this) { CheckHResult(d3d11_device_->QueryInterface(dxgi_device.GetAddressOf())); CheckHResult(D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, - IID_PPV_ARGS(&d2d1_factory_))); + IID_PPV_ARGS(&d2d1_factory_))); CheckHResult(d2d1_factory_->CreateDevice(dxgi_device.Get(), &d2d1_device_)); diff --git a/src/platform/gui/win/UiApplication.cpp b/src/platform/gui/win/UiApplication.cpp index e1c21d59..1069928c 100644 --- a/src/platform/gui/win/UiApplication.cpp +++ b/src/platform/gui/win/UiApplication.cpp @@ -45,7 +45,10 @@ WinUiApplication::WinUiApplication() { clipboard_ = std::make_unique<WinClipboard>(this); } -WinUiApplication::~WinUiApplication() { instance = nullptr; } +WinUiApplication::~WinUiApplication() { + delete_later_pool_.Clean(); + instance = nullptr; +} int WinUiApplication::Run() { MSG msg; |
