mirror of
https://github.com/redstrate/Novus.git
synced 2025-04-20 11:47:45 +00:00
Fix a crash in VulkanWindow when trying to close one
This commit is contained in:
parent
546ebfd0bd
commit
09e1d25d09
3 changed files with 32 additions and 10 deletions
|
@ -20,8 +20,7 @@ VulkanWindow::VulkanWindow(MDLPart *part, Renderer *renderer, QVulkanInstance *i
|
|||
|
||||
void VulkanWindow::exposeEvent(QExposeEvent *)
|
||||
{
|
||||
if (isExposed()) {
|
||||
if (!m_initialized) {
|
||||
if (isExposed() && !m_initialized) {
|
||||
m_initialized = true;
|
||||
|
||||
auto surface = m_instance->surfaceForWindow(this);
|
||||
|
@ -30,6 +29,10 @@ void VulkanWindow::exposeEvent(QExposeEvent *)
|
|||
else
|
||||
render();
|
||||
}
|
||||
|
||||
if (!isExposed() && m_initialized) {
|
||||
m_initialized = false;
|
||||
m_renderer->destroySwapchain();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,8 +45,17 @@ bool VulkanWindow::event(QEvent *e)
|
|||
case QEvent::Resize: {
|
||||
QResizeEvent *resizeEvent = (QResizeEvent *)e;
|
||||
auto surface = m_instance->surfaceForWindow(this);
|
||||
m_renderer->resize(surface, resizeEvent->size().width() * screen()->devicePixelRatio(), resizeEvent->size().height() * screen()->devicePixelRatio());
|
||||
if (surface != nullptr) {
|
||||
m_renderer->resize(surface,
|
||||
resizeEvent->size().width() * screen()->devicePixelRatio(),
|
||||
resizeEvent->size().height() * screen()->devicePixelRatio());
|
||||
}
|
||||
} break;
|
||||
case QEvent::PlatformSurface:
|
||||
if (static_cast<QPlatformSurfaceEvent *>(e)->surfaceEventType() == QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed && m_initialized) {
|
||||
m_renderer->destroySwapchain();
|
||||
}
|
||||
break;
|
||||
case QEvent::MouseButtonPress: {
|
||||
auto mouseEvent = dynamic_cast<QMouseEvent *>(e);
|
||||
|
||||
|
|
|
@ -68,6 +68,8 @@ public:
|
|||
bool initSwapchain(VkSurfaceKHR surface, int width, int height);
|
||||
void resize(VkSurfaceKHR surface, int width, int height);
|
||||
|
||||
void destroySwapchain();
|
||||
|
||||
RenderModel addModel(const physis_MDL &model, int lod);
|
||||
void reloadModel(RenderModel &model, uint32_t lod);
|
||||
RenderTexture addTexture(uint32_t width, uint32_t height, const uint8_t *data, uint32_t data_size);
|
||||
|
|
|
@ -426,6 +426,14 @@ void Renderer::resize(VkSurfaceKHR surface, int width, int height)
|
|||
initSwapchain(surface, width, height);
|
||||
}
|
||||
|
||||
void Renderer::destroySwapchain()
|
||||
{
|
||||
if (swapchain != VK_NULL_HANDLE) {
|
||||
vkDestroySwapchainKHR(device, swapchain, nullptr);
|
||||
swapchain = VK_NULL_HANDLE;
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer::render(std::vector<RenderModel> models)
|
||||
{
|
||||
vkWaitForFences(device, 1, &inFlightFences[currentFrame], VK_TRUE, std::numeric_limits<uint64_t>::max());
|
||||
|
|
Loading…
Add table
Reference in a new issue