MakieOrg / Makie.jl

Interactive data visualizations and plotting in Julia
https://docs.makie.org/stable
MIT License
2.4k stars 306 forks source link

GLMakie segfaults using Threads.@spawn #3867

Closed xlxs4 closed 4 months ago

xlxs4 commented 4 months ago

I had some GLMakie visualization code that ran inside a @spawn block. It used translate! and rotate! calls on text, arrow and mesh plots without fail. When I tried to change a Label's text I immediately got segfaults. Replacing @spawn with @async fixed the issue. Note that I only get a segfault when I try to change the value of text[]. Accessing it (e.g. to print) works without any issue. The segfault was happening consistently, i.e. in every single execution, without any loops, other tasks, any sort of race condition etc. I managed to find a similar issue in a discourse post: https://discourse.julialang.org/t/unexpected-behavior-when-using-threads-spawn/103497

Here's a MWE:

  using Base.Threads: @spawn
  using GLMakie

  function init()
      GLMakie.activate!()
      fig = Figure(; size=(600, 600))
      GLMakie.Screen(fig.scene) # works fine without
      fig[1, 1] = textgrid = GridLayout()
      txt = Label(textgrid[1, 1]; text="Hello")
      return txt
  end

  function segfault(txt)
      println(txt.text[]) # works fine
      txt.text[] = "Goodbye" # crashes
      return nothing
  end

  txt = init()
  segfault(txt) # works fine
  @async segfault(txt) # works fine
  @spawn segfault(txt) # crashes
output of `st` ```julia [7d9f7c33] Accessors v0.1.36 [c61b5328] AstroTime v0.7.0 [d360d2e6] ChainRulesCore v1.23.0 [aaaa29a8] Clustering v0.15.7 [2569d6c7] ConcreteStructs v0.2.3 [5218b696] Configurations v0.17.6 [150eb455] CoordinateTransformations v0.6.3 [44557152] DateFormats v0.1.18 [b4f34e82] Distances v0.10.11 [5789e2e9] FileIO v1.16.3 [f6369f11] ForwardDiff v0.10.36 [c9556dd2] ForwardDiffChainRules v0.2.1 [5c1252a2] GeometryBasics v0.4.11 [4e3cecfd] ImageShow v0.3.8 [a98d9a8b] Interpolations v0.15.1 [033835bb] JLD2 v0.4.47 [682c06a0] JSON v0.21.4 [6fafb56a] Memoization v0.2.1 [7269a6da] MeshIO v0.4.11 [eacbb407] Meshes v0.42.2 [b8a86587] NearestNeighbors v0.4.16 [ca34efa3] OpenScienceFramework v0.2.7 [42171d58] PlyIO v1.1.2 [189a3867] Reexport v1.2.2 [6ac157d9] SatelliteToolbox v0.12.2 [5718ef0a] SatelliteToolboxAtmosphericModels v0.1.2 [9fc549ba] SatelliteToolboxGeomagneticField v0.1.0 [6c6a2e73] Scratch v1.2.1 [90137ffa] StaticArrays v1.9.3 [8bd03d06] StructEqualHash v0.1.3 [8bf52ea8] CRC32c [ade2ca70] Dates [f43a241f] Downloads v1.6.0 [37e2e46d] LinearAlgebra [9a3f8284] Random [10745b16] Statistics v1.10.0 [fa267f1f] TOML v1.0.3 ```
output of `st -m` ```julia [1520ce14] AbstractTrees v0.4.5 [7d9f7c33] Accessors v0.1.36 [79e6a3ab] Adapt v4.0.4 [dce04be8] ArgCheck v2.3.0 ⌅ [ec485272] ArnoldiMethod v0.1.0 [c61b5328] AstroTime v0.7.0 [13072b0f] AxisAlgorithms v1.1.0 [198e06fe] BangBang v0.4.2 [9718e550] Baselet v0.1.1 [0e736298] Bessels v0.2.8 [d1d4a3ce] BitFlags v0.1.8 [d360d2e6] ChainRulesCore v1.23.0 [7a955b69] CircularArrays v1.4.0 [aaaa29a8] Clustering v0.15.7 [944b1d66] CodecZlib v0.7.4 [35d6a980] ColorSchemes v3.25.0 [3da002f7] ColorTypes v0.11.5 [c3611d14] ColorVectorSpace v0.10.0 [03fe91ce] Colorfy v0.1.4 [5ae59095] Colors v0.12.11 [bbf7d656] CommonSubexpressions v0.3.0 [34da2185] Compat v4.15.0 [a33af91c] CompositionsBase v0.1.2 [2569d6c7] ConcreteStructs v0.2.3 [f0e56b4a] ConcurrentUtilities v2.4.1 [5218b696] Configurations v0.17.6 [187b0558] ConstructionBase v1.5.5 [150eb455] CoordinateTransformations v0.6.3 [a8cc5b0e] Crayons v4.1.1 [9a962f9c] DataAPI v1.16.0 [864edb3b] DataStructures v0.18.20 [e2d170a0] DataValueInterfaces v1.0.0 [44557152] DateFormats v0.1.18 [244e2a9f] DefineSingletons v0.1.2 [8bb1440f] DelimitedFiles v1.9.1 [163ba53b] DiffResults v1.1.0 [b552c78f] DiffRules v1.15.1 [c78775a3] DifferentiableFlatten v0.1.1 [b4f34e82] Distances v0.10.11 [ffbed154] DocStringExtensions v0.9.3 [732a3c5d] EarthOrientation v0.7.2 [460bff9d] ExceptionUnwrapping v0.1.10 [55351af7] ExproniconLite v0.10.7 [411431e0] Extents v0.1.2 [5789e2e9] FileIO v1.16.3 [53c48c17] FixedPointNumbers v0.8.5 [f6369f11] ForwardDiff v0.10.36 [c9556dd2] ForwardDiffChainRules v0.2.1 [cf35fbd7] GeoInterface v1.3.4 [5c1252a2] GeometryBasics v0.4.11 [cd3eb016] HTTP v1.10.8 [c817782e] ImageBase v0.1.7 [a09fc81d] ImageCore v0.10.2 [4e3cecfd] ImageShow v0.3.8 [d25df0c9] Inflate v0.1.4 [22cec73e] InitialValues v0.3.1 [a98d9a8b] Interpolations v0.15.1 [3587e190] InverseFunctions v0.1.14 [92d709cd] IrrationalConstants v0.2.2 [d5eda45b] ItemGraphs v0.4.0 [c8e1da08] IterTools v1.10.0 [82899510] IteratorInterfaceExtensions v1.0.0 [033835bb] JLD2 v0.4.47 [692b3bcd] JLLWrappers v1.5.0 [682c06a0] JSON v0.21.4 [0f8b85d8] JSON3 v1.14.0 [2f5f767c] LeapSeconds v1.1.0 [093fc24a] LightGraphs v1.3.5 [2ab3a3ac] LogExpFunctions v0.3.27 [e6f89c97] LoggingExtras v1.0.3 [1914dd2f] MacroTools v0.5.13 [dbb5928d] MappedArrays v0.4.2 [739be429] MbedTLS v1.1.9 [6fafb56a] Memoization v0.2.1 [7269a6da] MeshIO v0.4.11 [eacbb407] Meshes v0.42.2 [128add7d] MicroCollections v0.2.0 [e1d29d7a] Missings v1.2.0 [e94cdb99] MosaicViews v0.3.4 [46d2c3a1] MuladdMacro v0.2.4 [77ba4419] NaNMath v1.0.2 [d9ec5142] NamedTupleTools v0.14.3 [b8a86587] NearestNeighbors v0.4.16 [6fe1bfb0] OffsetArrays v1.14.0 [4d8831e6] OpenSSL v1.4.3 [ca34efa3] OpenScienceFramework v0.2.7 [fbd9d27c] OptionalData v1.0.0 [bac558e1] OrderedCollections v1.6.3 [5432bcbf] PaddedViews v0.5.12 [d96e819e] Parameters v0.12.3 [69de0a69] Parsers v2.8.1 [42171d58] PlyIO v1.1.2 [3a141323] PolynomialRoots v1.0.0 [aea7be01] PrecompileTools v1.2.1 [21216c6a] Preferences v1.4.3 [94ee1d12] Quaternions v0.7.6 [c84ed2f1] Ratios v0.4.5 [c1ae055f] RealDot v0.1.0 [189a3867] Reexport v1.2.2 [74f56ac7] ReferenceFrameRotations v3.0.0 [cbe49d4c] RemoteFiles v0.5.0 [ae029012] Requires v1.3.0 [6038ab10] Rotations v1.7.0 [6ac157d9] SatelliteToolbox v0.12.2 [5718ef0a] SatelliteToolboxAtmosphericModels v0.1.2 [9e17983a] SatelliteToolboxBase v0.3.0 [b0edd99f] SatelliteToolboxCelestialBodies v0.1.1 [9fc549ba] SatelliteToolboxGeomagneticField v0.1.0 [bd9e9728] SatelliteToolboxGravityModels v0.1.4 [7fa26607] SatelliteToolboxLegendre v1.0.1 [c2b69894] SatelliteToolboxPropagators v0.3.0 [ba14ac17] SatelliteToolboxSgp4 v2.1.2 [7ff27aeb] SatelliteToolboxTle v1.0.4 [6b019ec1] SatelliteToolboxTransformations v0.1.6 [6c6a2e73] Scratch v1.2.1 [efcf1570] Setfield v1.1.1 [777ac1f9] SimpleBufferStream v1.1.0 [699a6c99] SimpleTraits v0.9.4 [a2af1166] SortingAlgorithms v1.2.1 [5a540a4e] SpaceIndices v1.1.2 [276daf66] SpecialFunctions v2.4.0 [171d559e] SplittablesBase v0.1.15 [cae243ae] StackViews v0.1.1 [90137ffa] StaticArrays v1.9.3 [1e83bf80] StaticArraysCore v1.4.2 [82ae8749] StatsAPI v1.7.0 [2913bbd2] StatsBase v0.34.3 [09ab397b] StructArrays v0.6.18 [8bd03d06] StructEqualHash v0.1.3 [856f2bd8] StructTypes v1.10.0 [3783bdb8] TableTraits v1.0.1 [bd369af6] Tables v1.11.1 [62fd8b95] TensorCore v0.1.1 [3bb67fe8] TranscodingStreams v0.10.8 [28d57a85] Transducers v0.4.82 [28dd2a49] TransformsBase v1.4.1 [5c2747f8] URIs v1.5.1 [3a884ed6] UnPack v1.0.2 [1986cc42] Unitful v1.19.1 [efce3f68] WoodburyMatrices v1.0.0 [5ae413db] EarCut_jll v2.2.4+0 [458c3c95] OpenSSL_jll v3.0.13+1 [efe28fd5] OpenSpecFun_jll v0.5.5+0 [0dad84c5] ArgTools v1.1.1 [56f22d72] Artifacts [2a0f44e3] Base64 [8bf52ea8] CRC32c [ade2ca70] Dates [8ba89e20] Distributed [f43a241f] Downloads v1.6.0 [7b1f6079] FileWatching [9fa8497b] Future [b77e0a4c] InteractiveUtils [b27032c2] LibCURL v0.6.4 [76f85450] LibGit2 [8f399da3] Libdl [37e2e46d] LinearAlgebra [56ddb016] Logging [d6f4376e] Markdown [a63ad114] Mmap [ca575930] NetworkOptions v1.2.0 [44cfe95a] Pkg v1.10.0 [de0858da] Printf [3fa0cd96] REPL [9a3f8284] Random [ea8e919c] SHA v0.7.0 [9e88b42a] Serialization [1a1011a3] SharedArrays [6462fe0b] Sockets [2f01184e] SparseArrays v1.10.0 [10745b16] Statistics v1.10.0 [fa267f1f] TOML v1.0.3 [a4e569a6] Tar v1.10.0 [8dfed614] Test [cf7118a7] UUIDs [4ec0a83e] Unicode [e66e0078] CompilerSupportLibraries_jll v1.1.1+0 [deac9b47] LibCURL_jll v8.4.0+0 [e37daf67] LibGit2_jll v1.6.4+0 [29816b5a] LibSSH2_jll v1.11.0+1 [c8ffd9c3] MbedTLS_jll v2.28.2+1 [14a3606d] MozillaCACerts_jll v2023.1.10 [4536629a] OpenBLAS_jll v0.3.23+4 [05823500] OpenLibm_jll v0.8.1+2 [bea87d4a] SuiteSparse_jll v7.2.1+1 [83775a58] Zlib_jll v1.2.13+1 [8e850b90] libblastrampoline_jll v5.8.0+1 [8e850ede] nghttp2_jll v1.52.0+1 [3f19e933] p7zip_jll v17.4.0+2 ```
segmentation fault logs ```julia [68568] signal (11.2): Segmentation fault: 11
in expression starting at none:0 glBindBuffer at /System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib (unknown line) glBindBuffer at /Users/xlxs4/.Julia/packages/ModernGL/yNrOu/src/functionloading.jl:64 [inlined] bind at /Users/xlxs4/.Julia/packages/GLMakie/UPa0N/src/GLAbstraction/GLBuffer.jl:30 Allocations: 114265699 (Pool: 114099642; Big: 166057); GC: 89 ```

I don't know of how much help this is, since the behavior isn't reproducible in a temp env. I can try adding the other packages back until I get a segfault, if that helps. Let me know what I can do.

SimonDanisch commented 4 months ago

Duplicate of: https://github.com/MakieOrg/Makie.jl/issues/3833