Blender V5.3
blender::WriteDataStableAddressIDs Struct Reference

#include <writefile.hh>

Public Attributes

std::shared_ptr< dna::pointers::PointersInDNA > sdna_pointers
Map< const void *, uint64_t > pointer_map
Set< uint64_t > used_ids
uint64_t next_id_hint = 0

Detailed Description

Definition at line 26 of file writefile.hh.

Member Data Documentation

◆ next_id_hint

uint64_t blender::WriteDataStableAddressIDs::next_id_hint = 0

The next stable address id is derived from this. This is modified in two cases:

  • A new stable address is needed, in which case this is just incremented.
  • A new "section" of the .blend file starts. In this case, this should be reinitialized with some hash of an identifier of the next section. This makes sure that if the number of pointers in the previous section is modified, the pointers in the new section are not affected. A "section" can be anything, but currently a section simply starts when a new data-block starts. In the future, an API could be added that allows sections to start within a data-block which could isolate stable pointer ids even more.

When creating the new address id, keep in mind that this may be 0 and it may collide with previous hints.

Definition at line 76 of file writefile.hh.

Referenced by blender::get_address_id_for_undo(), blender::get_address_id_int(), and blender::mywrite_id_begin().

◆ pointer_map

Map<const void *, uint64_t> blender::WriteDataStableAddressIDs::pointer_map

Maps each runtime-pointer to a unique identifier that's written in the .blend file.

Currently, for regular blendfile writing, no pointers are ever removed from this map during writing of a single file. Correctness wise, this is fine. However, when some data-blocks write temporary addresses, those may be reused across IDs while actually pointing to different data. This can break address id stability in some situations. In the future this could be improved by clearing such temporary pointers before writing the next data-block.

In undo case, only a very small sub-set of 'generated' addresses (temp data generated for writefile only) is added to this mapping, most pointers are written as-is (since their addresses are always stable in undo context: if unchanged, address remains the same). The mapping is also cleared after every ID writing, to allow temp allocated data to re-use the same source address across different IDs. The generated address ids will always be unique though (see also used_ids description below).

Definition at line 49 of file writefile.hh.

Referenced by blender::BlendStructWriterVoid::generated_ptr(), blender::get_address_id_int(), blender::mywrite_id_end(), and blender::prepare_stable_data_block_ids().

◆ sdna_pointers

std::shared_ptr<dna::pointers::PointersInDNA> blender::WriteDataStableAddressIDs::sdna_pointers

Knows which DNA members are pointers. Those members are overridden when serializing the .blend file to get more stable pointer identifiers.

Definition at line 31 of file writefile.hh.

Referenced by blender::BlendStructWriterVoid::generated_ptr(), blender::writedata_new(), and blender::writestruct_at_address_nr().

◆ used_ids

Set<uint64_t> blender::WriteDataStableAddressIDs::used_ids

Contains all the #pointer_map.values() ever generated during a writefile operation.

This is used to make sure that the same id is never reused for a different pointer. While this is technically allowed in .blend files (when the pointers are local data of different objects), we currently don't always know what type a pointer points to when writing it. So we can't determine if a pointer is local or not.

Note that in undo (memfile) case, this set is not reset after every ID writing, to ensure that all generated address ids remain unique across a whole blend-file writing operation.

Definition at line 61 of file writefile.hh.

Referenced by blender::get_next_stable_address_id().


The documentation for this struct was generated from the following file: