From 165c5a7a5ed9522fb2a7a999adbe7f8fd3459f51 Mon Sep 17 00:00:00 2001 From: Kbz-8 Date: Thu, 22 May 2025 15:50:25 +0200 Subject: [PATCH] truly fixing crash error --- Application/World.cpp | 2 +- Application/World.h | 4 +--- Application/main.cpp | 23 ++++--------------- ScopEngine/Runtime/Includes/Graphics/Model.h | 1 + .../Includes/Renderer/Pipelines/Shader.h | 11 +++++++++ ScopEngine/Runtime/Sources/Core/Engine.cpp | 1 + 6 files changed, 20 insertions(+), 22 deletions(-) diff --git a/Application/World.cpp b/Application/World.cpp index 4cf9db1..b03814b 100644 --- a/Application/World.cpp +++ b/Application/World.cpp @@ -52,7 +52,7 @@ World::World(Scop::Scene& scene) : m_scene(scene), m_previous_chunk_position(-10 m_scene.CreateNarrator().AttachScript(std::make_shared(std::function{}, narrator_update, std::function{})); } -void World::Quit() noexcept +World::~World() { m_generation_status = GenerationState::Quitting; while(m_generation_status != GenerationState::Finished) diff --git a/Application/World.h b/Application/World.h index 782558b..ce61351 100644 --- a/Application/World.h +++ b/Application/World.h @@ -26,14 +26,12 @@ class World public: World(Scop::Scene& scene); - void Quit() noexcept; - [[nodiscard]] inline Scop::Scene& GetScene() noexcept { return m_scene; } [[nodiscard]] inline std::shared_ptr GetBlockMaterial() const { return p_block_material; } [[nodiscard]] Scop::NonOwningPtr GetChunk(Scop::Vec2i position); [[nodiscard]] Noise& GetNoiseGenerator() noexcept { return m_noise; } - ~World() = default; + ~World(); private: void UnloadChunks(); diff --git a/Application/main.cpp b/Application/main.cpp index e5ccd9f..1bf1461 100644 --- a/Application/main.cpp +++ b/Application/main.cpp @@ -8,20 +8,8 @@ int main(int ac, char** av) { Scop::ScopEngine engine(ac, av, "Vox", 0, 0, GetExecutablePath().parent_path().parent_path() / "ScopEngine/Assets"); - Scop::Scene& splash_scene = SplashScreen(); - - Scop::ShaderLayout shader_layout( - { - { 1, - Scop::ShaderSetLayout({ - { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER }, - { 1, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER } - }) - } - }, {} - ); - std::shared_ptr shader = Scop::LoadShaderFromFile(GetExecutablePath().parent_path().parent_path() / "Resources/Fragment.spv", Scop::ShaderType::Fragment, std::move(shader_layout)); + std::shared_ptr shader = Scop::LoadShaderFromFile(GetExecutablePath().parent_path().parent_path() / "Resources/Fragment.spv", Scop::ShaderType::Fragment, Scop::DefaultShaderLayout); Scop::SceneDescriptor main_scene_desc; main_scene_desc.fragment_shader = shader; @@ -32,10 +20,9 @@ int main(int ac, char** av) Scop::Vec2ui32 skybox_size; main_scene.AddSkybox(std::make_shared(Scop::LoadBMPFile(GetResourcesPath() / "skybox.bmp", skybox_size), skybox_size.x, skybox_size.y)); - World world(main_scene); - - engine.Run(); - - world.Quit(); + { + World world(main_scene); + engine.Run(); + } return 0; } diff --git a/ScopEngine/Runtime/Includes/Graphics/Model.h b/ScopEngine/Runtime/Includes/Graphics/Model.h index dec05e0..a9bff4a 100644 --- a/ScopEngine/Runtime/Includes/Graphics/Model.h +++ b/ScopEngine/Runtime/Includes/Graphics/Model.h @@ -15,6 +15,7 @@ namespace Scop // Only static meshes for now class Model { + friend class ScopEngine; friend Model LoadModelFromObjFile(std::filesystem::path path) noexcept; public: diff --git a/ScopEngine/Runtime/Includes/Renderer/Pipelines/Shader.h b/ScopEngine/Runtime/Includes/Renderer/Pipelines/Shader.h index dc0d222..bc05e77 100644 --- a/ScopEngine/Runtime/Includes/Renderer/Pipelines/Shader.h +++ b/ScopEngine/Runtime/Includes/Renderer/Pipelines/Shader.h @@ -74,6 +74,17 @@ namespace Scop }; std::shared_ptr LoadShaderFromFile(const std::filesystem::path& filepath, ShaderType type, ShaderLayout layout); + + static const Scop::ShaderLayout DefaultShaderLayout( + { + { 1, + Scop::ShaderSetLayout({ + { 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER }, + { 1, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER } + }) + } + }, {} + ); } #endif diff --git a/ScopEngine/Runtime/Sources/Core/Engine.cpp b/ScopEngine/Runtime/Sources/Core/Engine.cpp index 0bb6a9b..08554f0 100644 --- a/ScopEngine/Runtime/Sources/Core/Engine.cpp +++ b/ScopEngine/Runtime/Sources/Core/Engine.cpp @@ -117,6 +117,7 @@ namespace Scop #endif m_scene_renderer.Destroy(); m_renderer.Destroy(); + Model::s_default_material.reset(); p_renderer_core.reset(); SDL_Quit(); Message("Successfully executed !");