Skip to content

Clear bsp_data from bsp_info after it has been used - #7754

Open
Shivansps wants to merge 2 commits into
scp-fs2open:masterfrom
Shivansps:clear-bsp_data
Open

Clear bsp_data from bsp_info after it has been used#7754
Shivansps wants to merge 2 commits into
scp-fs2open:masterfrom
Shivansps:clear-bsp_data

Conversation

@Shivansps

@Shivansps Shivansps commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

After taking a look at were bsp_data is used, i noticed that only submodel_get_num_polys() used it after it had completed model_load(), and this function was called only from freespace2.cpp when the -pofspew was used.

So i changed it to save the result of submodel_get_num_polys_sub() that submodel_get_num_polys() used when the -pofspew cmdline is used. Then i reseted the buffer.

Then i noticed -pofspew was causing an abort because submodel_get_num_polys_sub() had an infinite recursion bug when one of the list had a value of 0 and called submodel_get_num_polys_sub() again.
I confirmed this by running -pofspew on the current nightly and it crashes before exporting all models on BP 3.3.3 dataset, so this was probably broken for like, forever. I added a check to avoid this and how it works again.

As for the results of clearing the bsp_data cache:
On Icarus (with a dgpu)

Before:
with-bsp

After:
clear-bsp

Im not noticing any problems with this change, but ill recommend someone who knows more about the model system (and virtual pof) might want to check it out first.

P.D. i moved model_get_textures_used() declaration from models.h to modelinterp.h i just added because it seems cleaner since i was adding a new header.

@Goober5000 Goober5000 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall; one thing

Comment thread code/model/modelread.cpp
Comment on lines +3512 to +3515
if (sm->bsp_data == nullptr) {
sm->num_polys = 0;
continue;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This unfortunately has the side effect of leaving a collision tree with dangling data. So model_remove_bsp_collision_tree should be updated to set the freed pointers to nullptr and the counts to 0.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, then ill remove the if and the continue and move the nullprt check on before calling submodel_get_num_polys_sub()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants