From 4f389b7f6ab54a884730b09050d76a9964bee812 Mon Sep 17 00:00:00 2001 From: Max Thrun Date: Thu, 18 Aug 2016 11:00:23 -0700 Subject: [PATCH 1/5] Add null terminator to ShowStyleEditor output_type combo options Without a null terminator the Combo() function indexes outside of the "items_separated_by_zeros" string. --- imgui_demo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 67846e7a..0d9dbbcf 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -1670,7 +1670,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) } ImGui::LogFinish(); } - ImGui::SameLine(); ImGui::PushItemWidth(120); ImGui::Combo("##output_type", &output_dest, "To Clipboard\0To TTY"); ImGui::PopItemWidth(); + ImGui::SameLine(); ImGui::PushItemWidth(120); ImGui::Combo("##output_type", &output_dest, "To Clipboard\0To TTY\0"); ImGui::PopItemWidth(); ImGui::SameLine(); ImGui::Checkbox("Only Modified Fields", &output_only_modified); static ImGuiColorEditMode edit_mode = ImGuiColorEditMode_RGB; From 3234f81cb17a2dc0b8d63bf4ae8a610f93f9a1ce Mon Sep 17 00:00:00 2001 From: Marcell Kiss Date: Sat, 20 Aug 2016 13:08:34 +0200 Subject: [PATCH 2/5] maxImageCount may be 0; add missing sType; change to 1 push constant range --- examples/vulkan_example/imgui_impl_glfw_vulkan.cpp | 12 +++++------- examples/vulkan_example/main.cpp | 9 ++++++++- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/examples/vulkan_example/imgui_impl_glfw_vulkan.cpp b/examples/vulkan_example/imgui_impl_glfw_vulkan.cpp index 33d8e997..fa17959f 100644 --- a/examples/vulkan_example/imgui_impl_glfw_vulkan.cpp +++ b/examples/vulkan_example/imgui_impl_glfw_vulkan.cpp @@ -661,19 +661,16 @@ bool ImGui_ImplGlfwVulkan_CreateDeviceObjects() if (!g_PipelineLayout) { - VkPushConstantRange push_constants[2] = {}; + VkPushConstantRange push_constants[1] = {}; push_constants[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; push_constants[0].offset = sizeof(float) * 0; - push_constants[0].size = sizeof(float) * 2; - push_constants[1].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; - push_constants[1].offset = sizeof(float) * 2; - push_constants[1].size = sizeof(float) * 2; + push_constants[0].size = sizeof(float) * 4; VkDescriptorSetLayout set_layout[1] = {g_DescriptorSetLayout}; VkPipelineLayoutCreateInfo layout_info = {}; layout_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; layout_info.setLayoutCount = 1; layout_info.pSetLayouts = set_layout; - layout_info.pushConstantRangeCount = 2; + layout_info.pushConstantRangeCount = 1; layout_info.pPushConstantRanges = push_constants; err = vkCreatePipelineLayout(g_Device, &layout_info, g_Allocator, &g_PipelineLayout); ImGui_ImplGlfwVulkan_VkResult(err); @@ -750,7 +747,8 @@ bool ImGui_ImplGlfwVulkan_CreateDeviceObjects() VkDynamicState dynamic_states[2] = { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR }; VkPipelineDynamicStateCreateInfo dynamic_state = {}; - dynamic_state.dynamicStateCount = 2; + dynamic_state.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; + dynamic_state.dynamicStateCount = 2; dynamic_state.pDynamicStates = dynamic_states; VkGraphicsPipelineCreateInfo info = {}; diff --git a/examples/vulkan_example/main.cpp b/examples/vulkan_example/main.cpp index 130fd870..040ff241 100644 --- a/examples/vulkan_example/main.cpp +++ b/examples/vulkan_example/main.cpp @@ -88,7 +88,14 @@ static void resize_vulkan(GLFWwindow* /*window*/, int w, int h) VkSurfaceCapabilitiesKHR cap; err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(g_Gpu, g_Surface, &cap); check_vk_result(err); - info.minImageCount = (cap.minImageCount + 2 < cap.maxImageCount) ? (cap.minImageCount + 2) : cap.maxImageCount; + if (cap.maxImageCount > 0) + { + info.minImageCount = (cap.minImageCount + 2 < cap.maxImageCount) ? (cap.minImageCount + 2) : cap.maxImageCount; + } + else + { + info.minImageCount = cap.minImageCount + 2; + } if (cap.currentExtent.width == 0xffffffff) { fb_width = w; From 4bc6a951fe11d34c0e64af08d1802aef011f2215 Mon Sep 17 00:00:00 2001 From: Marcell Kiss Date: Sat, 20 Aug 2016 13:27:03 +0200 Subject: [PATCH 3/5] tabs to space, remove braces --- examples/vulkan_example/imgui_impl_glfw_vulkan.cpp | 4 ++-- examples/vulkan_example/main.cpp | 12 ++++-------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/examples/vulkan_example/imgui_impl_glfw_vulkan.cpp b/examples/vulkan_example/imgui_impl_glfw_vulkan.cpp index fa17959f..a9c18f33 100644 --- a/examples/vulkan_example/imgui_impl_glfw_vulkan.cpp +++ b/examples/vulkan_example/imgui_impl_glfw_vulkan.cpp @@ -747,8 +747,8 @@ bool ImGui_ImplGlfwVulkan_CreateDeviceObjects() VkDynamicState dynamic_states[2] = { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR }; VkPipelineDynamicStateCreateInfo dynamic_state = {}; - dynamic_state.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; - dynamic_state.dynamicStateCount = 2; + dynamic_state.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; + dynamic_state.dynamicStateCount = 2; dynamic_state.pDynamicStates = dynamic_states; VkGraphicsPipelineCreateInfo info = {}; diff --git a/examples/vulkan_example/main.cpp b/examples/vulkan_example/main.cpp index 040ff241..f3318fed 100644 --- a/examples/vulkan_example/main.cpp +++ b/examples/vulkan_example/main.cpp @@ -88,14 +88,10 @@ static void resize_vulkan(GLFWwindow* /*window*/, int w, int h) VkSurfaceCapabilitiesKHR cap; err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(g_Gpu, g_Surface, &cap); check_vk_result(err); - if (cap.maxImageCount > 0) - { - info.minImageCount = (cap.minImageCount + 2 < cap.maxImageCount) ? (cap.minImageCount + 2) : cap.maxImageCount; - } - else - { - info.minImageCount = cap.minImageCount + 2; - } + if (cap.maxImageCount > 0) + info.minImageCount = (cap.minImageCount + 2 < cap.maxImageCount) ? (cap.minImageCount + 2) : cap.maxImageCount; + else + info.minImageCount = cap.minImageCount + 2; if (cap.currentExtent.width == 0xffffffff) { fb_width = w; From 82768e05f3e6b0b85b0d45253c7017692cb86833 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sat, 20 Aug 2016 13:30:42 +0200 Subject: [PATCH 4/5] Ignore list for Visual Studio --- examples/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/.gitignore b/examples/.gitignore index 8157afff..41704453 100644 --- a/examples/.gitignore +++ b/examples/.gitignore @@ -33,6 +33,7 @@ opengl3_example/opengl3_example *.obj *.exe *.pdb +*.ilk ## Ini files imgui.ini From 63d47bc5a4b26d21549a640ce6af4b5b40022d26 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 23 Aug 2016 16:55:06 +0200 Subject: [PATCH 5/5] ImFormatString() Fixed an overflow handling bug with implementation of vsnprintf() that do not return -1 (#793) --- imgui.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index cb334f15..a8cddc64 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -944,21 +944,30 @@ const char* ImStristr(const char* haystack, const char* haystack_end, const char return NULL; } + +// MSVC version appears to return -1 on overflow, whereas glibc appears to return total count (which may be >= buf_size). +// Ideally we would test for only one of those limits at runtime depending on the behavior the vsnprintf(), but trying to deduct it at compile time sounds like a pandora can of worm. int ImFormatString(char* buf, int buf_size, const char* fmt, ...) { + IM_ASSERT(buf_size > 0); va_list args; va_start(args, fmt); int w = vsnprintf(buf, buf_size, fmt, args); va_end(args); - buf[buf_size-1] = 0; - return (w == -1) ? buf_size : w; + if (w == -1 || w >= buf_size) + w = buf_size - 1; + buf[w] = 0; + return w; } int ImFormatStringV(char* buf, int buf_size, const char* fmt, va_list args) { + IM_ASSERT(buf_size > 0); int w = vsnprintf(buf, buf_size, fmt, args); - buf[buf_size-1] = 0; - return (w == -1) ? buf_size : w; + if (w == -1 || w >= buf_size) + w = buf_size - 1; + buf[w] = 0; + return w; } // Pass data_size==0 for zero-terminated strings