Skip to content

Commit

Permalink
Fix #8: do not destroy external handles
Browse files Browse the repository at this point in the history
  • Loading branch information
serenity4 committed Apr 15, 2021
1 parent 61e9edc commit 4c7ef09
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
4 changes: 2 additions & 2 deletions generated/vulkan_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5318,7 +5318,7 @@ function get_swapchain_images_khr(device::Device, swapchain::SwapchainKHR, fun_p
pSwapchainImages = Vector{VkImage}(undef, pSwapchainImageCount[])
@check vkGetSwapchainImagesKHR(device, swapchain, pSwapchainImageCount, pSwapchainImages, fun_ptr)
end
Image.(pSwapchainImages, (x->destroy_image(device, x, fun_ptr_destroy; allocator)), device)
Image.(pSwapchainImages, identity, device)
end

destroy_swapchain_khr(device::Device, swapchain::SwapchainKHR, fun_ptr::FunctionPtr; allocator = C_NULL)::Cvoid = vkDestroySwapchainKHR(device, swapchain, allocator, fun_ptr)
Expand Down Expand Up @@ -10197,7 +10197,7 @@ function get_swapchain_images_khr(device::Device, swapchain::SwapchainKHR)::Resu
pSwapchainImages = Vector{VkImage}(undef, pSwapchainImageCount[])
@check vkGetSwapchainImagesKHR(device, swapchain, pSwapchainImageCount, pSwapchainImages)
end
Image.(pSwapchainImages, (x->destroy_image(device, x; allocator)), device)
Image.(pSwapchainImages, identity, device)
end

destroy_swapchain_khr(device::Device, swapchain::SwapchainKHR; allocator = C_NULL)::Cvoid = vkDestroySwapchainKHR(device, swapchain, allocator)
Expand Down
15 changes: 8 additions & 7 deletions generator/src/wrapper/wrap/return.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,22 @@ function wrap_implicit_return(spec::SpecFunc, args...; kwargs...)
must_return_success_code(spec) ? :(($ex, _return_code)) : ex
end

function wrap_implicit_handle_return(handle::SpecHandle, ex::Expr, parent_handle::SpecHandle, parent_ex, with_func_ptr)
function wrap_implicit_handle_return(handle::SpecHandle, ex::Expr, parent_handle::SpecHandle, parent_ex, destroy::Bool, with_func_ptr)
@match ex begin
:($f($v[])) => :($f($v[], $(destructor(handle; with_func_ptr)), $parent_ex))
:($f.($v)) => :($f.($v, $(destructor(handle; with_func_ptr)), $parent_ex))
:($f($v[])) => :($f($v[], $(!destroy ? :identity : destructor(handle; with_func_ptr)), $parent_ex))
:($f.($v)) => :($f.($v, $(!destroy ? :identity : destructor(handle; with_func_ptr)), $parent_ex))
end
end

function wrap_implicit_handle_return(handle::SpecHandle, ex::Expr, with_func_ptr)
function wrap_implicit_handle_return(handle::SpecHandle, ex::Expr, destroy::Bool, with_func_ptr)
@match ex begin
:($f($v[])) => :($f($v[], $(destructor(handle; with_func_ptr))))
:($f.($v)) => :($f.($v, $(destructor(handle; with_func_ptr))))
:($f($v[])) => :($f($v[], $(!destroy ? :identity : destructor(handle; with_func_ptr))))
:($f.($v)) => :($f.($v, $(!destroy ? :identity : destructor(handle; with_func_ptr))))
end
end

function wrap_implicit_handle_return(spec::SpecFunc, handle::SpecHandle, ex::Expr, with_func_ptr)
destroy = spec.type QUERY
args = @match parent_spec(handle) begin
::Nothing => (handle, ex)
p::SpecHandle => @match spec.type begin
Expand All @@ -79,7 +80,7 @@ function wrap_implicit_handle_return(spec::SpecFunc, handle::SpecHandle, ex::Exp
end
end

wrap_implicit_handle_return(args..., with_func_ptr)
wrap_implicit_handle_return(args..., destroy, with_func_ptr)
end

function wrap_return_type(spec::SpecFunc, ret_type)
Expand Down
12 changes: 12 additions & 0 deletions generator/test/wrapper/wrap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,18 @@ test_extend_handle_constructor(name, ex; kwargs...) = test_ex(extend_handle_cons
test_wrap_func(:vkGetFenceStatus, :(
get_fence_status(device::Device, fence::Fence)::Result{VkResult, VulkanError} = @check(vkGetFenceStatus(device, fence))
))

test_wrap_func(:vkGetSwapchainImagesKHR, :(
function get_swapchain_images_khr(device::Device, swapchain::SwapchainKHR)::Result{Vector{Image}, VulkanError}
pSwapchainImageCount = Ref{UInt32}()
@repeat_while_incomplete begin
@check vkGetSwapchainImagesKHR(device, swapchain, pSwapchainImageCount, C_NULL)
pSwapchainImages = Vector{VkImage}(undef, pSwapchainImageCount[])
@check vkGetSwapchainImagesKHR(device, swapchain, pSwapchainImageCount, pSwapchainImages)
end
Image.(pSwapchainImages, identity, device)
end
))
end

@testset "Additional constructors" begin
Expand Down

0 comments on commit 4c7ef09

Please sign in to comment.