Page MenuHome

GE crashes on exit because of using freed mtfaces from tessfaces
Closed, ResolvedPublic


Game Engine is crashing on exit (Esc button) with such backtrace if objects are using textures.
This happens because BlenderMaterial objects are storing a link to tface from DM's CD_MTFACE layer (link is setting up in BL_ConvertMesh function) but after initializing all pointers used DM is getting freed and all tesselation data is also getting freed so tface stored in BlenderMaterial points to a freed memory which leads to crash on BGE exit.
Attaching sample file. To reproduce simply hit P button and Esc button (sometimes it's needed to be done several times).



Event Timeline

Will try to look into this myself.

Think figured out reason and possible way to fix this issue.
GE converter is creating CDDM from mesh and gets pointers to some arrays like MTFACE and MTFACE. Pointer to MTFaces is stored in Material class which is used in runtime.
Before BMesh it was pretty safe because DM shared the same arrays as base mesh so in fact, GE was using references to arrays from Mesh. After BMesh merge such arrays are more "temporary" -- they're allocating for DM and frees on DM->release() which makes GE to point to freed memory.
Patch attached here makes GE used MTFACE array from base mesh which is exactly the same behavior as in pre-bmesh blender. Other layers aren't switched to be used from Mesh because they seems not be using during runtime, but from pedantic POV (like accessing all data in the same way) it might worth switching them to Mesh's data too. Hopefully order of faces in DM is the same as in tesselated Mesh. At least tests from our svn works smooth now without any crash.
Assigning to Campbell to verify patch and probably find nicer solution.

fixed r44858. pass NULL to GPU_set_tpage instead, looked through SVN history and cant find a good reason freeing a material should set the OpenGL image state.