Skip to content

Loading OrientedBoundingBox of some meshes is broken #125

@mmcomando

Description

@mmcomando

Problem

For meshes:
_WORK/DATA/ANIMS/_COMPILED/RAZOR_DEMON_BODY.MDL
_WORK/DATA/ANIMS/_COMPILED/SKE_BODY2.MDL
_WORK/DATA/ANIMS/_COMPILED/GOBBO_SKELETON_BODY.MDL
_WORK/DATA/ANIMS/_COMPILED/SKE_FLY_BODY.MDL
_WORK/DATA/ANIMS/_COMPILED/CRW_BODY.MDL
_WORK/DATA/ANIMS/_COMPILED/CR2_BODY.MDL

Loading each mesh takes around 8GB of memory and a lot of CPU time.

Cause

Meshes or loading code is broken.
Meshes are in vfs archive and steam verified files integrity so I suspect loading code.

Seems that OrientedBoundingBox loads random binary data.

Code

void OrientedBoundingBox::load(Read* r) {
	center = r->read_vec3();
	axes[0] = r->read_vec3();
	axes[1] = r->read_vec3();
	axes[2] = r->read_vec3();
	half_width = r->read_vec3();

	children.resize(r->read_ushort());
	for (auto& child : children) {
		child.load(r);
	}
}

Debugging

Part of gdb backtrace:

#1617 0x00007ffff7d339ed in zenkit::OrientedBoundingBox::load (...) at (...) Boxes.cc:28
#1618 0x00007ffff7d339ed in zenkit::OrientedBoundingBox::load (...) at (...) Boxes.cc:28
#1619 0x00007ffff7d339ed in zenkit::OrientedBoundingBox::load (...) at (...) Boxes.cc:28
#1620 0x00007ffff7d339ed in zenkit::OrientedBoundingBox::load (...) at (...) Boxes.cc:28
#1621 0x00007ffff7d339ed in zenkit::OrientedBoundingBox::load (...) at (...) Boxes.cc:28

This shows that there is huge recursion 1600, and there is a huge number of OBBs loaded.

gdb shows that second call to zenkit::OrientedBoundingBox::load has garbage values:

print this->center
print this->axes[0]
print this->axes[1]
print this->axes[2]
print this->half_width
print this->children.size()
$7 = {x = 7.88534546, y = 3.64349955e-35, z = 1.54658364e+30}
$8 = {x = 2.70450604e-43, y = -0, z = 8.82818033e-44}
$9 = {x = 0, y = 0, z = -0}
$10 = {x = -8.82818033e-44, y = 8.82818033e-44, z = 0}
$11 = {x = -1.6928243e-06, y =  ---->>>  -7.46888917e+32  <<<---- , z = 7.44605876e-35}
$12 = 1601

No OBB will have such a huge half_width y value.

Solution?

  • Find out how to load OrientedBoundingBox on these models
  • If no one uses children of OrientedBoundingBox don't load them

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions