markcwm / openb3d.mod

OpenB3D BlitzMax wrapper, see openb3d.docs for examples
18 stars 7 forks source link

Fixed a crash bug with freeing animated meshes #21

Closed Kippykip closed 4 years ago

Kippykip commented 4 years ago

Ever since I started working with OpenB3D on my project, I've always had random inconsistant issues with using FreeEntity on animated meshes, and having the whole project crash on the next UpdateWorld(). But the workaround I've had in the root of my project since 2017 was just a custom FreeEntity function where it calls something like:

Function KFreeEntity(ent:TEntity) Animate(ent, 0) FreeEntity(ent) End Function

However now that I've added a lot more content to the project, I've noticed this issue starting to return seemingly at random again. Although it doesn't crash nearly as much as it does without the Animate(ent, 0) part.

It seems the issue starts from Global.cpp, UpdateEntityAnim was being called on entities that should have been freed with FreeEntity. Which then traced back to entity.cpp, where it seems the code for deleting the "animate_list" would only happen if anim_update was true. Which in a lot of cases it may be false (such as using SetAnimTime would set it to false)

Deleting the "if" check seems to fix the entire issue, I've been testing for an hour or so with no issues, including on other entities such as pivots and sprites.

Horray! Found the root cause after all this time! (hopefully)

markcwm commented 4 years ago

Hi KippyKip, I haven't tested but I think you're right about this. Thank you.

Kippykip commented 4 years ago

Yeah it would be epic if we had more community testing for this kinda stuff! 😀 But yeah this seems to be working perfectly in my game at least now. I don't have to use my custom function in my game anymore.