godot_voxel: Valgrind: Invalid read of size 4 (pthread_mutex_lock.c:80)
Describe the bug GDExtension linux release build was crashing with: corrupted size vs. prev_size. So I checked with valgrind what’s going on and got the following result:
==43420== Memcheck, a memory error detector
==43420== Copyright (C) 2002-2024, and GNU GPL'd, by Julian Seward et al.
==43420== Using Valgrind-3.24.0 and LibVEX; rerun with -h for copyright info
==43420== Command: ./Minecraft.x86_64
==43420== Parent PID: 31227
==43420==
==43420== Invalid read of size 4
==43420== at 0x4EFAC54: pthread_mutex_lock@@GLIBC_2.2.5 (pthread_mutex_lock.c:80)
==43420== by 0x2E2C039: ??? (in /media/common/Projects/thegates-folder/ServerFiles/server_builds/Minecraft.x86_64)
==43420== by 0xFF8F9E0: ??? (in /media/common/Projects/thegates-folder/ServerFiles/server_builds/libvoxel.linux.template_release.x86_64.so)
==43420== by 0xFBF4065: ??? (in /media/common/Projects/thegates-folder/ServerFiles/server_builds/libvoxel.linux.template_release.x86_64.so)
==43420== by 0xFBF43B8: ??? (in /media/common/Projects/thegates-folder/ServerFiles/server_builds/libvoxel.linux.template_release.x86_64.so)
==43420== by 0xFCDDCAC: ??? (in /media/common/Projects/thegates-folder/ServerFiles/server_builds/libvoxel.linux.template_release.x86_64.so)
==43420== by 0xFE97B19: ??? (in /media/common/Projects/thegates-folder/ServerFiles/server_builds/libvoxel.linux.template_release.x86_64.so)
==43420== by 0x2E6E05A: ??? (in /media/common/Projects/thegates-folder/ServerFiles/server_builds/Minecraft.x86_64)
==43420== by 0x32B2CCA: ??? (in /media/common/Projects/thegates-folder/ServerFiles/server_builds/Minecraft.x86_64)
==43420== by 0x32C02E4: ??? (in /media/common/Projects/thegates-folder/ServerFiles/server_builds/Minecraft.x86_64)
==43420== by 0x43963C: ??? (in /media/common/Projects/thegates-folder/ServerFiles/server_builds/Minecraft.x86_64)
==43420== by 0x4E89487: (below main) (libc_start_call_main.h:58)
==43420== Address 0x108 is not stack'd, malloc'd or (recently) free'd
==43420==
==43420==
==43420== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==43420== Access not within mapped region at address 0x108
==43420== at 0x4EFAC54: pthread_mutex_lock@@GLIBC_2.2.5 (pthread_mutex_lock.c:80)
==43420== by 0x2E2C039: ??? (in /media/common/Projects/thegates-folder/ServerFiles/server_builds/Minecraft.x86_64)
==43420== by 0xFF8F9E0: ??? (in /media/common/Projects/thegates-folder/ServerFiles/server_builds/libvoxel.linux.template_release.x86_64.so)
==43420== by 0xFBF4065: ??? (in /media/common/Projects/thegates-folder/ServerFiles/server_builds/libvoxel.linux.template_release.x86_64.so)
==43420== by 0xFBF43B8: ??? (in /media/common/Projects/thegates-folder/ServerFiles/server_builds/libvoxel.linux.template_release.x86_64.so)
==43420== by 0xFCDDCAC: ??? (in /media/common/Projects/thegates-folder/ServerFiles/server_builds/libvoxel.linux.template_release.x86_64.so)
==43420== by 0xFE97B19: ??? (in /media/common/Projects/thegates-folder/ServerFiles/server_builds/libvoxel.linux.template_release.x86_64.so)
==43420== by 0x2E6E05A: ??? (in /media/common/Projects/thegates-folder/ServerFiles/server_builds/Minecraft.x86_64)
==43420== by 0x32B2CCA: ??? (in /media/common/Projects/thegates-folder/ServerFiles/server_builds/Minecraft.x86_64)
==43420== by 0x32C02E4: ??? (in /media/common/Projects/thegates-folder/ServerFiles/server_builds/Minecraft.x86_64)
==43420== by 0x43963C: ??? (in /media/common/Projects/thegates-folder/ServerFiles/server_builds/Minecraft.x86_64)
==43420== by 0x4E89487: (below main) (libc_start_call_main.h:58)
==43420== If you believe this happened as a result of a stack
==43420== overflow in your program's main thread (unlikely but
==43420== possible), you can try to increase the size of the
==43420== main thread stack using the --main-stacksize= flag.
==43420== The main thread stack size used in this run was 8388608.
==43420==
==43420== HEAP SUMMARY:
==43420== in use at exit: 47,556,334 bytes in 205,004 blocks
==43420== total heap usage: 833,721 allocs, 628,717 frees, 410,325,264 bytes allocated
==43420==
==43420== 8 bytes in 1 blocks are possibly lost in loss record 847 of 133,461
==43420== at 0x4D057A8: malloc (vg_replace_malloc.c:446)
==43420== by 0x32C4D28: ??? (in /media/common/Projects/thegates-folder/ServerFiles/server_builds/Minecraft.x86_64)
==43420== by 0x48758D: ??? (in /media/common/Projects/thegates-folder/ServerFiles/server_builds/Minecraft.x86_64)
==43420== by 0x4395B3: ??? (in /media/common/Projects/thegates-folder/ServerFiles/server_builds/Minecraft.x86_64)
==43420== by 0x4E89487: (below main) (libc_start_call_main.h:58)
... 40k lines of similar errors ...
==43420== 2,275,360 bytes in 28,442 blocks are possibly lost in loss record 133,461 of 133,461
==43420== at 0x4D057A8: malloc (vg_replace_malloc.c:446)
==43420== by 0x15CCEBED: ralloc_size (ralloc.c:118)
==43420== by 0x15CE931B: mesa_db_update_index (mesa_cache_db.c:313)
==43420== by 0x15CE9459: mesa_db_load (mesa_cache_db.c:384)
==43420== by 0x15CE9E8A: mesa_cache_db_open (mesa_cache_db.c:704)
==43420== by 0x15CD61DE: mesa_cache_db_multipart_init_part_locked (mesa_cache_db_multipart.c:60)
==43420== by 0x15CD61DE: mesa_cache_db_multipart_init_part.part.0 (mesa_cache_db_multipart.c:93)
==43420== by 0x15CD6536: mesa_cache_db_multipart_init_part (mesa_cache_db_multipart.c:89)
==43420== by 0x15CD6536: mesa_cache_db_multipart_entry_write (mesa_cache_db_multipart.c:182)
==43420== by 0x15CC85D4: disk_cache_db_write_item_to_disk (disk_cache_os.c:1178)
==43420== by 0x15CD3693: util_queue_thread_func (u_queue.c:294)
==43420== by 0x15CFB91C: impl_thrd_routine (threads_posix.c:43)
==43420== by 0x4EF7709: start_thread (pthread_create.c:448)
==43420== by 0x4F7B8B3: clone (clone.S:100)
==43420==
==43420== LEAK SUMMARY:
==43420== definitely lost: 160 bytes in 4 blocks
==43420== indirectly lost: 0 bytes in 0 blocks
==43420== possibly lost: 17,780,663 bytes in 76,439 blocks
==43420== still reachable: 29,767,943 bytes in 128,560 blocks
==43420== of which reachable via heuristic:
==43420== newarray : 80 bytes in 1 blocks
==43420== suppressed: 7,568 bytes in 1 blocks
==43420== Reachable blocks (those to which a pointer was found) are not shown.
==43420== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==43420==
==43420== For lists of detected and suppressed errors, rerun with: -s
==43420== ERROR SUMMARY: 36718 errors from 36718 contexts (suppressed: 0 from 0)
To Reproduce Steps to reproduce the behavior:
- Build godot_voxel as GDExtension with template_release target
- Create an empty project with voxel addon
- Export release build
- Run with valgrind --leak-check=yes --log-file=valgrind-out.txt ./name.x86_64
Expected behavior Open up without crash
Environment
- OS: Linux
- Graphics card: AMD Radeon RX 6600M
- Godot version: 4.3
- Module version: master
- Renderer used: Forward+
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 21 (21 by maintainers)
The affected features are:
Made a branch
fix_rd_singleton_gdextwith a potential workaround, I’ll have to test that later.Well the quick workaround is comment the code and give up on GPU features.
How would the extension know that? I know some people worked around this by making their singletons autoload nodes instead, but that requires user action to set this up… I don’t want users to have to setup an autoload nodes manually when actual singletons litterally exist. In addition, node being ready might be too late. The game could already have needed to load resources that require GPU initialization to have happened.
Meanwhile modules never had this limitation at all, and extensions are extremely similar to modules, so really it has to be possible. So the result is, the kind of workaround required here would be to defer everything and lazy-initialize everything somehow… and that would end up affecting the module version (or would have to maintain different code paths everywhere which is ugly af). It would also have to be still as early as possible, because the more it is deferred, the harder it gets to avoid issues with code trying to do stuff with GPU before that nebulous “moment when RenderingServer is available” has happened.