ObjectDB misses instances: empty --verbose leak list, missing orphan nodes, wrong OBJECT_COUNT

Aperta
#1,549 0 commenti 1 reazione 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
50/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
cpp

Direzione di ricerca

Start with the ObjectDB slot and block handling in core/object/object.cpp, especially get_object_count(), cleanup(), and debug_objects(). Compare the reported loops and ID construction with the block layout introduced by #1121, then inspect the linked fix for its unit test. Done means the count, orphan listing, leak IDs, and cleanup cover all allocated blocks; the reported reproduction checks should match the fixed results.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug needs testing topic:core
Tested versions
  • Reproducible in: v26.3.stable.official [85e520394]
  • Also reproducible in an unmodified local build of the same commit.
  • The same code is on master and dev. Upstream Godot is not affected: it still uses a single flat object_slots array, while the block layout came with #1121.
System information

Windows 10 Pro 22H2 (build 19045), x86-64. Reproduced headless with the Dummy audio driver, so the GPU and renderer are not involved.

Issue description

Four things that read the ObjectDB report wrong numbers or miss objects:

  1. --verbose does not list leaked instances. The engine prints ObjectDB instances leaked at exit (run with --verbose for details), but with --verbose it prints only the hint line and no Leaked instance: lines.
  2. Node.print_orphan_nodes() and Node.get_orphan_node_ids() miss orphan nodes. In the MRP, get_orphan_node_ids() finds 0 of 3 orphan nodes.
  3. Performance.OBJECT_COUNT is wrong. In the MRP it goes from 542 to 518 after creating 1000 objects.
  4. The leak warning can be skipped. It is missed when the leaked objects happen to fill whole blocks exactly. This one comes from the code and was not reproduced.

Cause. Since #1121, ObjectDB stores its slots in growing blocks (blocks[1..block_max], of sizes 128, 256, 512, ...). Free slots are handed out as a stack that runs across the blocks:

  • block_count is the block that holds the top of that stack, not the number of allocated blocks;
  • slot_count is the position inside that block, not the number of live objects.

Because freed slots are reused, a live object can be in any allocated block, up to block_max.

The older single-array code treated slot_count as the total, and the block code still does in several places. In core/object/object.cpp:

int ObjectDB::get_object_count() {
	return slot_count; // Only the slots used in the current block.
}

void ObjectDB::cleanup() {
	if (slot_count > 0) { // Skips the warning when the current block is exactly empty.
		...
		for (uint32_t i = 1; i < block_count; i++) { // Skips block `block_count` and every block above it.
			...
			uint64_t id = uint64_t(i) | (uint64_t(blocks[i][j].validator) << OBJECTDB_SLOT_MAX_COUNT_BITS) | ...; // Block number and wrong shift, not the slot position.
	...
	for (uint32_t i = 1; i < block_count; i++) {
		memfree(blocks[i]); // Blocks from `block_count` up to `block_max` are never freed.
	}
}

debug_objects(), which the orphan-node functions use, has the same i < block_count loop.

At exit, most objects have been freed and few slots are in use, so block_count is usually 1. The listing loop then runs zero times.

Fix available. dominicbytes/redot-engine#11 (single commit 7a2fe51, against 26.3-stable) does four things:

  • counts live instances as the full blocks below block_count plus slot_count;
  • walks every allocated block in cleanup() and debug_objects();
  • rebuilds the printed ID from the slot position;
  • frees every block at cleanup.

It also adds a unit test, which fails without the change: 202 counted instead of 1098, and 798 of 1000 objects visited.

Check Official 26.3-stable With the fix
OBJECT_COUNT change after creating 1000 objects -24 +1000
Orphan nodes found by get_orphan_node_ids() 0 of 3 3 of 3
Leaked instance: lines for the 3 leaked nodes none 3, with IDs matching get_instance_id()
Steps to reproduce
  1. Download and extract the attached MRP.
  2. Import it once: redot --headless --path <mrp> --import.
  3. Run: redot --headless --audio-driver Dummy --path <mrp> --verbose.
  4. The output shows the wrong OBJECT_COUNT difference, 0 of 3 orphan nodes, and a leak warning with no Leaked instance: lines.
Minimal reproduction project (MRP)

objectdb-count-and-listing-mrp.zip

Lingua principale
C++
Stelle
6.1k
Fork
337
Merge medio
5g 8h
PR unite (30g)
13

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Redot-Engine/redot-engine

Tutte le issue di Redot-Engine/redot-engine

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.