danilw / nanovg-vulkan-glfw-integration-demo

Example code from Vulkan-tutorial Depth buffering modified adding NanoVG integration. Using C++ and GLFW.
MIT License
2 stars 0 forks source link

Fix DPI scale #1

Open danilw opened 2 years ago

danilw commented 2 years ago

Just to track the problem.

Problem: This nanovg-vulkan-glfw-integration-demo crash/segfault on resize. Happening only when C code of nonovg library builded with C++ code. Happening at random - can be first resize or multiple resizes.

Debug: valgrind show no memory leaks, and same as gdb when crash happening it point on:

Thread 1 "example-vk_glfw" received signal SIGSEGV, Segmentation fault.
vknvg_renderCreateTexture (uptr=0xd86e90, type=1, w=1024, h=512, imageFlags=0, data=0x0) at /home/danil/2021_vulkan_projects/not_clean/nanovg-vulkan-glfw-integration-demo/example/../src/nanovg_vk.h:1457

https://github.com/danilw/nanovg-vulkan-glfw-integration-demo/blob/main/src/nanovg_vk.h#L1457

Not Vulkan or driver bug: Changing VK_PRESENT_MODE_IMMEDIATE_KHR to VK_PRESENT_MODE_FIFO_KHR - crash still happening. Changing MAX_FRAMES_IN_FLIGHT to 1 or 10 - crash still happening.

But pressing hotkey 3 (keyboard number 3) or commenting https://github.com/danilw/nanovg-vulkan-glfw-integration-demo/blob/main/example/example_vulkan_glfw_integration.cpp#L1414 to 1435 (removing nanovg render from loop) - no crash.

Bug in the C-code of nanovg. And it does look like "double free or corruption" bug - https://youtu.be/xVT1y0xWgww

I checked static variables, and lots of other stuff, still can not see the source of problem... will update when find problem.

danilw commented 2 years ago

Crash happening only on winWidth change and look like because float pxRatio = swapChainExtent.width / (float)winWidth; this line ...

danilw commented 2 years ago

Look like it worst case scenario - problem in font rendering in nanovg source code. Looking on it.

Edit - not worst case it simple malloc out of free space, should be simple to fix .... or no

danilw commented 2 years ago

DPI scale NOT fixed just fixed two mistakes, to not make it crash on normal DPI https://github.com/danilw/nanovg-vulkan-glfw-integration-demo/commit/d1efe736cd7a8b1aa89fd87d3ae67187af069d22 https://github.com/danilw/nanovg-vulkan-glfw-integration-demo/commit/29293954ecf8262b3cb97f2365d98fb5c08a45df

danilw commented 2 years ago

found commit where I did this change https://github.com/danilw/nanovg_vulkan/commit/3e2feb3c8ffe49fb955c8ecd653914835faabd52

but I dont remember why and what for (currently I have broken Vulkan render loop because texture allocation when pixel size not 1 (dpi scale), still looking for correct fix)