Fix EXC_BAD_ACCESS, caused due to miss use of shared pointers.
This commit is contained in:
parent
14f0c05b68
commit
32dd4568c0
|
|
@ -18,7 +18,7 @@ namespace dyn::core {
|
||||||
using render_command = std::function<void()>;
|
using render_command = std::function<void()>;
|
||||||
using render_command_queue = command_queue<render_command>;
|
using render_command_queue = command_queue<render_command>;
|
||||||
|
|
||||||
class render_context {
|
class render_context : public std::enable_shared_from_this<render_context> {
|
||||||
public:
|
public:
|
||||||
render_context() = default;
|
render_context() = default;
|
||||||
virtual ~render_context() = default;
|
virtual ~render_context() = default;
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,5 @@ int main() {
|
||||||
|
|
||||||
ref<render_context> ctx = render_context::create(win);
|
ref<render_context> ctx = render_context::create(win);
|
||||||
ctx->init();
|
ctx->init();
|
||||||
auto vkctx = ref_as<vulkan_context>(ctx);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -12,6 +12,7 @@ namespace dyn::core {
|
||||||
vulkan_context::vulkan_context(const ref<window>& window) : _window(window) {}
|
vulkan_context::vulkan_context(const ref<window>& window) : _window(window) {}
|
||||||
|
|
||||||
vulkan_context::~vulkan_context() {
|
vulkan_context::~vulkan_context() {
|
||||||
|
DYN_DEBUG_LOG("vulkan_context::~vulkan_context()");
|
||||||
|
|
||||||
if (utils::vk_enable_validation_layers) {
|
if (utils::vk_enable_validation_layers) {
|
||||||
utils::vkDestroyDebugUtilsMessengerEXT(_instance, _debug_messenger, nullptr);
|
utils::vkDestroyDebugUtilsMessengerEXT(_instance, _debug_messenger, nullptr);
|
||||||
|
|
@ -26,7 +27,8 @@ namespace dyn::core {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto self = ref<vulkan_context>(this);
|
// changed to shared_from_this because making a ref using `this` causes the deconstructor to be called twice which causes EXC_BAD_ACCESS.
|
||||||
|
auto self = ref_as<vulkan_context>(shared_from_this());
|
||||||
|
|
||||||
// create vulkan instance
|
// create vulkan instance
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user