Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory-related error when used under Blender #565

Open
paulmelis opened this issue Oct 17, 2024 · 1 comment
Open

Memory-related error when used under Blender #565

paulmelis opened this issue Oct 17, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@paulmelis
Copy link

paulmelis commented Oct 17, 2024

Affects: JuliaCall

Describe the bug

Some time ago I made a proof-of-concept of using Julia within Blender (which embeds a Python interpreter) to do some geometry processing. That was with Julia 1.8.5 and Blender 3.4.2 and it worked great.

However, an at-exit memory error occurred, related to munmap_chunk() (see below, probably an invalid free()?). That already happened with the older versions of Julia and Blender, and today I tried to update that code to Julia 1.11.1 and Blender 4.2.3, but the issue is still there.

Given this simple script:

$ cat t_init.py
print('Initializing Julia environment ...')

from juliacall import Main as jl
jl.println("Hello from Julia!")

print("Active Julia project = %s" % jl.seval("Base.active_project()"))

Running it from within Blender gives a memory-related error at exit:

melis@blackbox 11:51:~/concepts/blender-julia-test$ ~/software/blender-4.2.3-linux-x64/blender -b -P t_init.py 
Blender 4.2.3 LTS (hash 0e22e4fcea03 built 2024-10-14 23:31:34)
Initializing Julia environment ...
[juliapkg] Found dependencies: /home/melis/software/blender-4.2.3-linux-x64/4.2/python/lib/python3.11/site-packages/juliacall/juliapkg.json
[juliapkg] Found dependencies: /home/melis/software/blender-4.2.3-linux-x64/4.2/python/lib/python3.11/site-packages/juliapkg/juliapkg.json
[juliapkg] Locating Julia ~1.6.1, ~1.7, ~1.8, ~1.9, =1.10.0, ^1.10.3
[juliapkg] Using Julia 1.11.1 at /home/melis/.julia/juliaup/julia-1.11.1+0.x64.linux.gnu/bin/julia
[juliapkg] Using Julia project at /home/melis/.julia/environments/pyjuliapkg
[juliapkg] Installing packages:
           julia> import Pkg
           julia> Pkg.Registry.update()
           julia> Pkg.add([Pkg.PackageSpec(name="PythonCall", uuid="6099a3de-0909-46bc-b1f4-468b9a2dfc0d")])
           julia> Pkg.resolve()
           julia> Pkg.precompile()
    Updating registry at `~/.julia/registries/General.toml`
   Resolving package versions...
    Updating `~/.julia/environments/pyjuliapkg/Project.toml`
  [6099a3de] + PythonCall v0.9.23
    Updating `~/.julia/environments/pyjuliapkg/Manifest.toml`
  [992eb4ea] + CondaPkg v0.2.23
  [9a962f9c] + DataAPI v1.16.0
  [e2d170a0] + DataValueInterfaces v1.0.0
  [82899510] + IteratorInterfaceExtensions v1.0.0
  [692b3bcd] + JLLWrappers v1.6.1
  [0f8b85d8] + JSON3 v1.14.1
  [1914dd2f] + MacroTools v0.5.13
  [0b3b1443] + MicroMamba v0.1.14
  [bac558e1] + OrderedCollections v1.6.3
  [69de0a69] + Parsers v2.8.1
  [fa939f87] + Pidfile v1.3.0
  [aea7be01] + PrecompileTools v1.2.1
  [21216c6a] + Preferences v1.4.3
  [6099a3de] + PythonCall v0.9.23
  [ae029012] + Requires v1.3.0
  [6c6a2e73] + Scratch v1.2.1
  [856f2bd8] + StructTypes v1.11.0
  [3783bdb8] + TableTraits v1.0.1
  [bd369af6] + Tables v1.12.0
  [e17b2a0c] + UnsafePointers v1.0.0
  [f8abcde7] + micromamba_jll v1.5.8+0
  [0dad84c5] + ArgTools v1.1.2
  [56f22d72] + Artifacts v1.11.0
  [2a0f44e3] + Base64 v1.11.0
  [ade2ca70] + Dates v1.11.0
  [f43a241f] + Downloads v1.6.0
  [7b1f6079] + FileWatching v1.11.0
  [b77e0a4c] + InteractiveUtils v1.11.0
  [4af54fe1] + LazyArtifacts v1.11.0
  [b27032c2] + LibCURL v0.6.4
  [76f85450] + LibGit2 v1.11.0
  [8f399da3] + Libdl v1.11.0
  [56ddb016] + Logging v1.11.0
  [d6f4376e] + Markdown v1.11.0
  [a63ad114] + Mmap v1.11.0
  [ca575930] + NetworkOptions v1.2.0
  [44cfe95a] + Pkg v1.11.0
  [de0858da] + Printf v1.11.0
  [3fa0cd96] + REPL v1.11.0
  [9a3f8284] + Random v1.11.0
  [ea8e919c] + SHA v0.7.0
  [9e88b42a] + Serialization v1.11.0
  [6462fe0b] + Sockets v1.11.0
  [f489334b] + StyledStrings v1.11.0
  [fa267f1f] + TOML v1.0.3
  [a4e569a6] + Tar v1.10.0
  [8dfed614] + Test v1.11.0
  [cf7118a7] + UUIDs v1.11.0
  [4ec0a83e] + Unicode v1.11.0
  [deac9b47] + LibCURL_jll v8.6.0+0
  [e37daf67] + LibGit2_jll v1.7.2+0
  [29816b5a] + LibSSH2_jll v1.11.0+1
  [c8ffd9c3] + MbedTLS_jll v2.28.6+0
  [14a3606d] + MozillaCACerts_jll v2023.12.12
  [83775a58] + Zlib_jll v1.2.13+1
  [8e850ede] + nghttp2_jll v1.59.0+0
  [3f19e933] + p7zip_jll v17.4.0+2
  No Changes to `~/.julia/environments/pyjuliapkg/Project.toml`
  No Changes to `~/.julia/environments/pyjuliapkg/Manifest.toml`
Hello from Julia!
Active Julia project = /home/melis/.julia/environments/pyjuliapkg/Project.toml

Blender quit
munmap_chunk(): invalid pointer

[27088] signal 6 (-6): Aborted
in expression starting at none:0
unknown function (ip: 0x7e000fca53f4)
gsignal at /usr/lib/libc.so.6 (unknown line)
abort at /usr/lib/libc.so.6 (unknown line)
unknown function (ip: 0x7e000fc34353)
unknown function (ip: 0x7e000fcaf764)
unknown function (ip: 0x7e000fcafa3b)
__libc_free at /usr/lib/libc.so.6 (unknown line)
close_unit_1 at /workspace/srcdir/gcc-13.2.0/libgfortran/io/unit.c:742
close_units at /workspace/srcdir/gcc-13.2.0/libgfortran/io/unit.c:800
unknown function (ip: 0x7e0029c8c0f1)
unknown function (ip: 0x7e0029c8f3ed)
unknown function (ip: 0x7e000fc4e890)
exit at /usr/lib/libc.so.6 (unknown line)
unknown function (ip: 0xfa208b)
unknown function (ip: 0x72f440)
unknown function (ip: 0x7e000fc34e07)
__libc_start_main at /usr/lib/libc.so.6 (unknown line)
unknown function (ip: 0x83ebfd)
Allocations: 4063190 (Pool: 4062988; Big: 202); GC: 5
Aborted (core dumped)

GDB stacktrace:

Blender quit
[Thread 0x7fffc8c00000 (LWP 138853) exited]
[Thread 0x7fffc9200000 (LWP 138852) exited]
[Thread 0x7fffca400000 (LWP 138850) exited]
[Thread 0x7fffcac00000 (LWP 138849) exited]
[Thread 0x7fffcbe00000 (LWP 138847) exited]
[Thread 0x7fffcd400000 (LWP 138845) exited]
[Thread 0x7fffcda00000 (LWP 138844) exited]
munmap_chunk(): invalid pointer

Thread 1 "blender" received signal SIGABRT, Aborted.
__pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44
44	      return INTERNAL_SYSCALL_ERROR_P (ret) ? INTERNAL_SYSCALL_ERRNO (ret) : 0;
(gdb) bt
#0  __pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44
#1  0x00007fffeb2a5463 in __pthread_kill_internal (threadid=<optimized out>, signo=6) at pthread_kill.c:78
#2  0x00007fffeb24c120 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#3  0x00007fffeb2334c3 in __GI_abort () at abort.c:79
#4  0x00007fffeb234354 in __libc_message_impl (fmt=fmt@entry=0x7fffeb3c22f5 "%s\n") at ../sysdeps/posix/libc_fatal.c:132
#5  0x00007fffeb2af765 in malloc_printerr (str=str@entry=0x7fffeb3c4f30 "munmap_chunk(): invalid pointer") at malloc.c:5772
#6  0x00007fffeb2afa3c in munmap_chunk (p=p@entry=0x7fffd8a33bb0) at malloc.c:3040
#7  0x00007fffeb2b461a in __GI___libc_free (mem=0x7fffd8a33bc0) at malloc.c:3388
#8  0x00007fffa4073010 in close_unit_1 (u=0xa9d1820, locked=locked@entry=1) at /workspace/srcdir/gcc-13.2.0/libgfortran/io/unit.c:742
#9  0x00007fffa407319a in _gfortrani_close_units () at /workspace/srcdir/gcc-13.2.0/libgfortran/io/unit.c:800
#10 0x00007ffff7fc80f2 in _dl_call_fini (closure_map=closure_map@entry=0x7fffce3a4300) at dl-call_fini.c:43
#11 0x00007ffff7fcb3ee in _dl_fini () at dl-fini.c:114
#12 0x00007fffeb24e891 in __run_exit_handlers (status=0, listp=0x7fffeb3f6680 <__exit_funcs>, run_list_atexit=run_list_atexit@entry=true, run_dtors=run_dtors@entry=true) at exit.c:108
#13 0x00007fffeb24e95e in __GI_exit (status=<optimized out>) at exit.c:138
#14 0x00000000014c6dfa in WM_exit (C=0x7fffd7c3e068, exit_code=0) at /home/melis/c/blender-4.2.3/source/blender/windowmanager/intern/wm_init_exit.cc:712
#15 0x000000000046f624 in main (argc=4, argv=0x7fffffffe0a8) at /home/melis/c/blender-4.2.3/source/creator/creator.cc:587

Blender also comes with a separate python, which does not show the error:

melis@blackbox 12:13:~/concepts/blender-julia-test$ ~/software/blender-4.2.3-linux-x64/4.2/python/bin/python3.11 t_init.py 
Initializing Julia environment ...
Hello from Julia!
Active Julia project = /home/melis/.julia/environments/pyjuliapkg/Project.toml

So somehow the embedded version, together with however Blender sets up the Python embedding, causes the issue. Blender's WM_exit in the trace above simply calls exit(exit_code) at line 712, so it seems to go wrong in the exit handlers after that.

I don't have JULIA_NUM_THREADS set, but I do have PYTHON_JULIACALL_HANDLE_SIGNALS=yes set.

I'm not entirely sure where all this originates. I've tried running blender under valgrind, to get some insight into what could be accessed that is wrong, but for some reason that causes PythonCall to get precompiled and leads to different behaviour overall it seems:

melis@blackbox 12:08:~/concepts/blender-julia-test$ valgrind ~/software/blender-4.2.3-linux-x64/blender -b -P t_init.py 
==29435== Memcheck, a memory error detector
==29435== Copyright (C) 2002-2024, and GNU GPL'd, by Julian Seward et al.
==29435== Using Valgrind-3.23.0 and LibVEX; rerun with -h for copyright info
==29435== Command: /home/melis/software/blender-4.2.3-linux-x64/blender -b -P t_init.py
==29435== 
==29435== Warning: set address range perms: large range [0x2979f000, 0x4179f000) (noaccess)
Blender 4.2.3 LTS (hash 0e22e4fcea03 built 2024-10-14 23:31:34)
Initializing Julia environment ...
...
==29435==    by 0x49CAA07F: ???
==29435==    by 0x49647907: ???
==29435== 
Precompiling PythonCall...
==29435== Conditional jump or move depends on uninitialised value(s)
==29435==    at 0x4E6A6AB0: jl_genericmemory_to_string (genericmemory.c:202)
==29435==    by 0x5E07C93E: String; (string.jl:78)
...
==29435== 
┌ Warning: The call to compilecache failed to create a usable precompiled cache file for PythonCall [6099a3de-0909-46bc-b1f4-468b9a2dfc0d]
│   exception = Required dependency Base.PkgId(Base.UUID("e17b2a0c-0bdf-430a-bd0c-3a23cae4ff39"), "UnsafePointers") failed to load from a cache file.
└ @ Base loading.jl:2509
==29435== Conditional jump or move depends on uninitialised value(s)
...
==29435==    by 0x83AE0887: ???
==29435== 
Precompiling UnsafePointers...
  1 dependency successfully precompiled in 1 seconds
ERROR: LoadError: Unable to find compatible target in cached code image.
Target 0 (skylake): Rejecting this target due to use of runtime-disabled features

Stacktrace:
  [1] ==29435== Conditional jump or move depends on uninitialised value(s)
==29435==    at 0x4E6A6AB0: jl_genericmemory_to_string (genericmemory.c:202)
...
==29435==    by 0x574DC89B: ???
==29435== 
_include_from_serialized(pkg::Base.PkgId, path::String, ocachepath::String, depmods::Vector{Any}, ignore_native::Bool; register::Bool)
    @ Base ./loading.jl:1204
  [2] _include_from_serialized
    @ ./loading.jl:1169 [inlined]
  [3] _tryrequire_from_serialized(pkg::Base.PkgId, path::String, ocachepath::String)
    @ Base ./loading.jl:1902
  [4] _require(pkg::Base.PkgId, env::String)
    @ Base ./loading.jl:2507
  [5] __require_prelocked(uuidkey::Base.PkgId, env::String)
    @ Base ./loading.jl:2315
  [6] #invoke_in_world#3
    @ ./essentials.jl:1089 [inlined]
  [7] invoke_in_world
    @ ./essentials.jl:1086 [inlined]
  [8] _require_prelocked(uuidkey::Base.PkgId, env::String)
    @ Base ./loading.jl:2302
  [9] macro expansion
    @ ./loading.jl:2241 [inlined]
 [10] macro expansion
    @ ./lock.jl:273 [inlined]
 [11] __require(into::Module, mod::Symbol)
    @ Base ./loading.jl:2198
 [12] #invoke_in_world#3
    @ ./essentials.jl:1089 [inlined]
 [13] invoke_in_world
    @ ./essentials.jl:1086 [inlined]
 [14] require(into::Module, mod::Symbol)
    @ Base ./loading.jl:2191
 [15] include(mod::Module, _path::String)
    @ Base ./Base.jl:557
 [16] include(x::String)
    @ PythonCall ~/.julia/packages/PythonCall/Nr75f/src/PythonCall.jl:1
 [17] top-level scope
    @ ~/.julia/packages/PythonCall/Nr75f/src/PythonCall.jl:7
 [18] include(mod::Module, _path::String)
    @ Base==29435== Conditional jump or move depends on uninitialised value(s)
==29435==    at 0x4E390A0B: ???
...
==29435==    by 0x5D929AF7: ???
==29435== 
 ./Base.jl:557
 [19] _require(pkg::Base.PkgId, env::String)
    @ Base ./loading.jl:2531
 [20] __require_prelocked(uuidkey::Base.PkgId, env::String)
    @ Base ./loading.jl:2315
 [21] #invoke_in_world#3
    @ ./essentials.jl:1089 [inlined]
 [22] invoke_in_world
    @ ./essentials.jl:1086 [inlined]
 [23] _require_prelocked(uuidkey::Base.PkgId, env::String)
    @ Base ./loading.jl:2302
 [24] macro expansion
    @ ./loading.jl:2241 [inlined]
 [25] macro expansion
    @ ./lock.jl:273 [inlined]
 [26] __require(into::Module, mod::Symbol)
    @ Base ./loading.jl:2198
 [27] #invoke_in_world#3
    @ ./essentials.jl:1089 [inlined]
 [28] invoke_in_world
    @ ./essentials.jl:1086 [inlined]
 [29] require(into::Module, mod::Symbol)
    @ Base ./loading.jl:2191
 [30] top-level scope
    @ none:8
in expression starting at /home/melis/.julia/packages/PythonCall/Nr75f/src/C/C.jl:1
in expression starting at /home/melis/.julia/packages/PythonCall/Nr75f/src/PythonCall.jl:1Traceback (most recent call last):
  File "/home/melis/concepts/blender-julia-test/t_init.py", line 3, in <module>
    from juliacall import Main as jl
  File "/home/melis/software/blender-4.2.3-linux-x64/4.2/python/lib/python3.11/site-packages/juliacall/__init__.py", line 287, in <module>
    init()
  File "/home/melis/software/blender-4.2.3-linux-x64/4.2/python/lib/python3.11/site-packages/juliacall/__init__.py", line 239, in init
    raise Exception('PythonCall.jl did not start properly')
Exception: PythonCall.jl did not start properly

Blender quit
==29435== 
==29435== HEAP SUMMARY:
==29435==     in use at exit: 155,257,953 bytes in 150,624 blocks
==29435==   total heap usage: 4,452,715 allocs, 4,302,091 frees, 2,095,545,574 bytes allocated
==29435== 
==29435== LEAK SUMMARY:
==29435==    definitely lost: 814,372 bytes in 235 blocks
==29435==    indirectly lost: 65,812 bytes in 5 blocks
==29435==      possibly lost: 14,316,681 bytes in 54,383 blocks
==29435==    still reachable: 140,060,348 bytes in 95,998 blocks
==29435==         suppressed: 740 bytes in 3 blocks
==29435== Rerun with --leak-check=full to see details of leaked memory
==29435== 
==29435== Use --track-origins=yes to see where uninitialised values come from
==29435== For lists of detected and suppressed errors, rerun with: -s
==29435== ERROR SUMMARY: 36 errors from 34 contexts (suppressed: 0 from 0)

Your system

Arch Linux, 64-bit, kernel 6.11.2-arch1-1

Julia 1.11.1, Python 3.11.7

melis@blackbox 11:54:~/concepts/blender-julia-test$ cat ~/.julia/environments/pyjuliapkg/Project.toml
[deps]
PythonCall = "6099a3de-0909-46bc-b1f4-468b9a2dfc0d"

[compat]
PythonCall = "=0.9.23"
melis@blackbox 11:55:~/concepts/blender-julia-test$ ~/software/blender-4.2.3-linux-x64/4.2/python/bin/python3.11 -m pip list
DEPRECATION: Loading egg at /home/melis/.local/lib/python3.11/site-packages/fsb5-1.0-py3.11.egg is deprecated. pip 23.3 will enforce this behaviour change. A possible replacement is to use pip for package installation..
DEPRECATION: Loading egg at /home/melis/.local/lib/python3.11/site-packages/lz4-4.3.2-py3.11-linux-x86_64.egg is deprecated. pip 23.3 will enforce this behaviour change. A possible replacement is to use pip for package installation..
DEPRECATION: Loading egg at /home/melis/.local/lib/python3.11/site-packages/decrunch-0.4.0.post1-py3.11-linux-x86_64.egg is deprecated. pip 23.3 will enforce this behaviour change. A possible replacement is to use pip for package installation..
DEPRECATION: Loading egg at /home/melis/.local/lib/python3.11/site-packages/unitypack-0.10.0-py3.11.egg is deprecated. pip 23.3 will enforce this behaviour change. A possible replacement is to use pip for package installation..
Package            Version
------------------ -----------
autopep8           1.6.0
certifi            2021.10.8
charset-normalizer 2.0.10
Cython             0.29.30
decrunch           0.4.0.post1
decrunch           0.4.0.post1
fsb5               1.0
fsb5               1.0
fsb5               1.0
idna               3.3
juliacall          0.9.23
juliapkg           0.1.13
lz4                4.3.2
lz4                4.3.2
numpy              1.24.3
pip                23.2.1
pycodestyle        2.8.0
requests           2.27.1
semver             3.0.2
setuptools         63.2.0
toml               0.10.2
unitypack          0.10.0
unitypack          0.10.0
urllib3            1.26.8
zstandard          0.16.0

Adding

jl.seval("using InteractiveUtils")
print(jl.seval("versioninfo()"))

to t_init.py gives this info:

Julia Version 1.11.1
Commit 8f5b7ca12ad (2024-10-16 10:53 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 8 × Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, skylake)
Threads: 1 default, 0 interactive, 1 GC (on 8 virtual cores)
Environment:
  JULIA_PYTHONCALL_EXE = /home/melis/software/blender-4.2.3-linux-x64/4.2/python/bin/python3.11

Adding

jl.seval("using Pkg")
print(jl.seval("Pkg.status()"))

to t_init.py actually gives a new segfault:

Package status:
[Detaching after vfork from child process 28993]

Thread 1 "blender" received signal SIGSEGV, Segmentation fault.
0x0000000000fde979 in ?? ()
(gdb) bt
#0  0x0000000000fde979 in ?? ()
#1  0x00007fffafb33e82 in uv__finish_close (handle=0xa436c90) at src/unix/core.c:342
#2  0x00007fffafb33ec8 in uv__run_closing_handles (loop=0x7fffb000d900 <default_loop_struct>) at src/unix/core.c:356
#3  0x00007fffafb34170 in uv_run (loop=0x7fffb000d900 <default_loop_struct>, mode=UV_RUN_NOWAIT) at src/unix/core.c:445
#4  0x00007fffafa906e2 in ijl_process_events () at /cache/build/builder-demeter6-6/julialang/julia-master/src/jl_uv.c:395
#5  0x00007fff9c31c4df in process_events () at libuv.jl:125
#6  julia_wait_65223 () at task.jl:1023
#7  0x00007fff9ad81dd0 in julia_#wait#731_65234 () at condition.jl:130
#8  0x00007fff9b93fc5d in wait () at condition.jl:125
#9  julia_wait_readnb_49617 () at stream.jl:416
#10 0x00007fff9c6fb81b in julia_eof_49609 () at stream.jl:106
#11 0x00007fff9bcb6f3d in jfptr_eof_49610 () from /home/melis/.julia/juliaup/julia-1.11.1+0.x64.linux.gnu/lib/julia/sys.so
#12 0x00007fff745d77da in julia_eof_42260 () at io.jl:472
#13 0x00007fff743bbd2a in julia_#read_tarball#45_41967 () at /cache/build/builder-demeter6-6/julialang/julia-master/usr/share/julia/stdlib/v1.11/Tar/src/extract.jl:352
#14 0x00007fff74510eb2 in read_tarball () at /cache/build/builder-demeter6-6/julialang/julia-master/usr/share/julia/stdlib/v1.11/Tar/src/extract.jl:341
#15 #19 () at /cache/build/builder-demeter6-6/julialang/julia-master/usr/share/julia/stdlib/v1.11/Pkg/src/Registry/registry_instance.jl:264
#16 julia_#open#891_41952 () at process.jl:447
#17 0x00007fff743a69c0 in open () at process.jl:428
#18 julia_uncompress_registry_27784 () at /cache/build/builder-demeter6-6/julialang/julia-master/usr/share/julia/stdlib/v1.11/Pkg/src/Registry/registry_instance.jl:263
#19 0x00007fff7436f186 in julia_RegistryInstance_33428 () at /cache/build/builder-demeter6-6/julialang/julia-master/usr/share/julia/stdlib/v1.11/Pkg/src/Registry/registry_instance.jl:330
#20 0x00007fff7438c817 in julia_#reachable_registries#25_27842 () at /cache/build/builder-demeter6-6/julialang/julia-master/usr/share/julia/stdlib/v1.11/Pkg/src/Registry/registry_instance.jl:436
#21 0x00007fff7453e345 in reachable_registries () at /cache/build/builder-demeter6-6/julialang/julia-master/usr/share/julia/stdlib/v1.11/Pkg/src/Registry/registry_instance.jl:406
#22 julia_#download_default_registries#39_27931 () at /cache/build/builder-demeter6-6/julialang/julia-master/usr/share/julia/stdlib/v1.11/Pkg/src/Registry/Registry.jl:107
#23 0x00007fff743c9365 in download_default_registries () at /cache/build/builder-demeter6-6/julialang/julia-master/usr/share/julia/stdlib/v1.11/Pkg/src/Registry/Registry.jl:106
#24 julia_#status#97_32293 () at /cache/build/builder-demeter6-6/julialang/julia-master/usr/share/julia/stdlib/v1.11/Pkg/src/API.jl:149
#25 0x00007fff745d6ec7 in jfptr_YY.statusYY.97_32294 () from /home/melis/.julia/juliaup/julia-1.11.1+0.x64.linux.gnu/share/julia/compiled/v1.11/Pkg/tUTdb_GYsA8.so
#26 0x00007fff74555cfe in julia_status_34033 () at /cache/build/builder-demeter6-6/julialang/julia-master/usr/share/julia/stdlib/v1.11/Pkg/src/API.jl:148
#27 0x00007fff74423483 in jfptr_status_34034 () from /home/melis/.julia/juliaup/julia-1.11.1+0.x64.linux.gnu/share/julia/compiled/v1.11/Pkg/tUTdb_GYsA8.so
#28 0x00007fff7432fa6d in julia_#status#99_32308 () at /cache/build/builder-demeter6-6/julialang/julia-master/usr/share/julia/stdlib/v1.11/Pkg/src/API.jl:174
#29 0x00007fff742868e6 in julia_status_32289 () at /cache/build/builder-demeter6-6/julialang/julia-master/usr/share/julia/stdlib/v1.11/Pkg/src/API.jl:165
#30 0x00007fff7432fb09 in jfptr_status_32290 () from /home/melis/.julia/juliaup/julia-1.11.1+0.x64.linux.gnu/share/julia/compiled/v1.11/Pkg/tUTdb_GYsA8.so
#31 0x00007fffafa70365 in jl_apply (nargs=1, args=0x7fffffffc700) at /cache/build/builder-demeter6-6/julialang/julia-master/src/julia.h:2157
#32 do_call (args=0x7fffa5117580, nargs=nargs@entry=1, s=s@entry=0x7fffffffc990) at /cache/build/builder-demeter6-6/julialang/julia-master/src/interpreter.c:126
#33 0x00007fffafa6fe2d in eval_value (e=e@entry=0x7fffa51175b0, s=s@entry=0x7fffffffc990) at /cache/build/builder-demeter6-6/julialang/julia-master/src/interpreter.c:223
#34 0x00007fffafa70f98 in eval_stmt_value (s=0x7fffffffc990, stmt=<optimized out>) at /cache/build/builder-demeter6-6/julialang/julia-master/src/interpreter.c:174
#35 eval_body (stmts=<optimized out>, s=s@entry=0x7fffffffc990, ip=1, ip@entry=0, toplevel=toplevel@entry=1) at /cache/build/builder-demeter6-6/julialang/julia-master/src/interpreter.c:663
#36 0x00007fffafa71b3e in jl_interpret_toplevel_thunk (m=m@entry=0x7fff9fb9b870 <jl_system_image_data+50367280>, src=0x7fffa754b460) at /cache/build/builder-demeter6-6/julialang/julia-master/src/interpreter.c:821
#37 0x00007fffafa8dfde in jl_toplevel_eval_flex (m=m@entry=0x7fff9fb9b870 <jl_system_image_data+50367280>, e=<optimized out>, fast=fast@entry=1, expanded=expanded@entry=0)
    at /cache/build/builder-demeter6-6/julialang/julia-master/src/toplevel.c:943
#38 0x00007fffafa8e92a in jl_toplevel_eval_flex (m=m@entry=0x7fff9fb9b870 <jl_system_image_data+50367280>, e=e@entry=0x7fffa5117170, fast=fast@entry=1, expanded=expanded@entry=0)
    at /cache/build/builder-demeter6-6/julialang/julia-master/src/toplevel.c:886
#39 0x00007fffafa8f40c in ijl_toplevel_eval (m=m@entry=0x7fff9fb9b870 <jl_system_image_data+50367280>, v=v@entry=0x7fffa5117170) at /cache/build/builder-demeter6-6/julialang/julia-master/src/toplevel.c:952
#40 0x00007fffafa8f996 in ijl_toplevel_eval_in (m=0x7fff9fb9b870 <jl_system_image_data+50367280>, ex=0x7fffa5117170) at /cache/build/builder-demeter6-6/julialang/julia-master/src/toplevel.c:994
#41 0x00007fffb4326d56 in ?? ()
#42 0x0000000000000000 in ?? ()

Edit: managed to get a more useful stacktrace by building a debug version of Blender, slightly updated some text

Edit 2: commenting out the at_jl_exit definition in blender-4.2.3-debug/4.2/python/lib/python3.12/site-packages/juliacall/__init__.py did not help

@paulmelis paulmelis added the bug Something isn't working label Oct 17, 2024
@paulmelis
Copy link
Author

paulmelis commented Oct 19, 2024

Ah, after digging some further the exit issue seems to be caused by Blender using jemalloc. If I build blender with WITH_MEM_JEMALLOC=OFF the munmap_chunk() error goes away. That's unfortunate, as the official Blender binaries use jemalloc (and so does the Arch blender package).

Edit for documentation: some jemalloc-related info on Julia at JuliaLang/julia#46298

Edit 2: well, well... the trick to LD_PRELOAD Julia's libgfortran.so mentioned in the issue actually works to get rid of the memory error, even with the official Blender binaries:

melis@blackbox 02:04:~/concepts/blender-julia-test$ ~/software/blender-4.2.3-linux-x64/blender -b -P t_init.py 
Blender 4.2.3 LTS (hash 0e22e4fcea03 built 2024-10-14 23:31:34)
Initializing Julia environment ...
Hello from Julia!
Active Julia project = /home/melis/.julia/environments/pyjuliapkg/Project.toml

Blender quit
munmap_chunk(): invalid pointer
Aborted (core dumped)

melis@blackbox 02:04:~/concepts/blender-julia-test$ LD_PRELOAD=/home/melis/.julia/juliaup/julia-1.11.1+0.x64.linux.gnu/lib/julia/libgfortran.so ~/software/blender-4.2.3-linux-x64/blender -b -P t_init.py 
Blender 4.2.3 LTS (hash 0e22e4fcea03 built 2024-10-14 23:31:34)
Initializing Julia environment ...
Hello from Julia!
Active Julia project = /home/melis/.julia/environments/pyjuliapkg/Project.toml

Blender quit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant