From 408a0b58d48ed798cd9fa4bbe70eec85be585473 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Wed, 15 Oct 2025 11:09:01 +0200 Subject: [PATCH 1/2] Fix #147317 Crash on undo/redo with PackedData. The issue here was that when an archive library ID is read from blendfile (memfile undo buffer in that case), a new split main is immediately created for it in `direct_link_library`, and the newly read Library is assigned to its `Main::curlib` pointer. However, in undo readfile code, when an old matching ID is found, the new data is moved into that old address, to avoid modifying all other unchanged ID using that re-read data-block. For (archive) libraries, it means that their split main `curlib` pointer also needs to be re-assigned to the re-used old address. Pull Request: https://projects.blender.org/blender/blender/pulls/147744 --- source/blender/blenloader/intern/readfile.cc | 25 ++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/source/blender/blenloader/intern/readfile.cc b/source/blender/blenloader/intern/readfile.cc index 862650ac1ad..196ad3ca5e8 100644 --- a/source/blender/blenloader/intern/readfile.cc +++ b/source/blender/blenloader/intern/readfile.cc @@ -3094,6 +3094,31 @@ static void read_libblock_undo_restore_at_old_address(FileData *fd, Main *main, BLI_addtail(new_lb, id_old); BLI_addtail(old_lb, id); + + /* In case a library has been re-read, it has added already its own split main to the new Main + * (see #direct_link_library code). + * + * Since we are replacing it with the 'id_old' address, we need to update that Main::curlib + * pointer accordingly. + * + * Note that: + * - This code is only for undo, and on undo we do not re-read regular libraries, only archive + * ones for packed data. + * - The new split main should still be empty at this stage (this code and adding the split + * Main in #direct_link_library are part of the same #read_libblock call). + */ + if (GS(id_old->name) == ID_LI) { + Library *lib_old = blender::id_cast(id_old); + Library *lib = blender::id_cast(id); + BLI_assert(lib_old->flag & LIBRARY_FLAG_IS_ARCHIVE); + + for (Main *bmain_iter : *fd->bmain->split_mains) { + if (bmain_iter->curlib == lib) { + BLI_assert(BKE_main_is_empty(bmain_iter)); + bmain_iter->curlib = lib_old; + } + } + } } static bool read_libblock_undo_restore( From 6c241737e846ebc891b26ba7228d8441f0ff3870 Mon Sep 17 00:00:00 2001 From: weizhen Date: Wed, 15 Oct 2025 11:23:52 +0200 Subject: [PATCH 2/2] Fix: Cycles volume performance issue on Nvidia Pass by value instead of reference partially fixes the performance issue mentioned in #147921 Pull Request: https://projects.blender.org/blender/blender/pulls/147989 --- intern/cycles/kernel/integrator/shade_volume.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/intern/cycles/kernel/integrator/shade_volume.h b/intern/cycles/kernel/integrator/shade_volume.h index c609abaa0b9..af3093befcc 100644 --- a/intern/cycles/kernel/integrator/shade_volume.h +++ b/intern/cycles/kernel/integrator/shade_volume.h @@ -304,28 +304,29 @@ ccl_device_noinline Extrema volume_estimate_extrema(KernelGlobals kg, const IntegratorGenericState state, const ccl_private RNGState *rng_state, const uint32_t path_flag, - const ccl_private OctreeTracing &octree) + const Interval t, + const VolumeStack entry) { - const bool homogeneous = volume_is_homogeneous(kg, octree.entry); + const bool homogeneous = volume_is_homogeneous(kg, entry); const int samples = homogeneous ? 1 : 4; const float shade_offset = homogeneous ? 0.5f : path_state_rng_2D(kg, rng_state, PRNG_VOLUME_SHADE_OFFSET).y; - const float step_size = octree.t.length() / float(samples); + const float step_size = t.length() / float(samples); /* Do not allocate closures. */ sd->num_closure_left = 0; Extrema extrema = {FLT_MAX, -FLT_MAX}; for (int i = 0; i < samples; i++) { - const float shade_t = octree.t.min + (shade_offset + i) * step_size; + const float shade_t = t.min + (shade_offset + i) * step_size; sd->P = ray->P + ray->D * shade_t; sd->closure_transparent_extinction = zero_float3(); sd->closure_emission_background = zero_float3(); volume_shader_eval_entry( - kg, state, sd, octree.entry, path_flag); + kg, state, sd, entry, path_flag); const float sigma = reduce_max(sd->closure_transparent_extinction); const float emission = reduce_max(sd->closure_emission_background); @@ -359,7 +360,8 @@ ccl_device_inline Extrema volume_object_get_extrema(KernelGlobals kg, return octree.node->sigma * object_volume_density(kg, octree.entry.object); } - return volume_estimate_extrema(kg, ray, sd, state, rng_state, path_flag, octree); + return volume_estimate_extrema( + kg, ray, sd, state, rng_state, path_flag, octree.t, octree.entry); } /* Find the octree root node in the kernel array that corresponds to the volume stack entry. */