markcwm / openb3d.mod

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

What causes OpenB3D to crash on .B3D Blender exports? #16

Closed Kippykip closed 4 years ago

Kippykip commented 4 years ago

Heya, I've briefly mentioned about this before on syntaxbomb a long time ago but never got around to making an example of this bug. I've got two models, one exported in MilkShape 3D and the other exported in Blender with the MineTest .B3D exporter. (https://github.com/Kippykip/B3DExport)

The blender model export reads fine in FragMotion and loads in classic Blitz3D, but on OpenB3D EXCEPTION_ACCESSVIOLATION crashes occur. (When I export without textures, the debugger scrolls to Local inst:Byte Ptr=LoadAnimMesh) https://i.imgur.com/Jb2y6E5.png

Here's the code for both BlitzMax-NG and Blitz3D, with the models and everything included. Example.zip

Also I noticed that OpenB3D doesn't seem to light meshes with groups correctly, when compared to the Blitz3D example.

markcwm commented 4 years ago

Hi Kippy, sorry I'm a bit too busy at the moment to look at this but it seems like you're using the CPP loader, but could you test if standard Minib3d can load the model and also if the Openb3d BMX loader will work, use MeshLoader "bmx".

Kippykip commented 4 years ago

Ah, looks like it doesn't load in MiniB3D or under the BMX loader. However loading it under minib3d has revealed a a lot more on why it's crashing! "Attempt to index array element beyond array length" at this position: https://i.imgur.com/8TY7a0S.png

Under the BMX loader I get the error here: https://i.imgur.com/UKowFhl.png

Kippykip commented 4 years ago

Ok, so here's basically what was going down. Blender Model K_Frame:1, bo_bone.keys.flags: 480 K_Frame:480, bo_bone.keys.flags: 480 EXCEPTION_ACCESS_VIOLATION

Milkshape Model K_Frame:1, bo_bone.keys.flags: 481 K_Frame:480, bo_bone.keys.flags: 481

Basically it goes going above the array which crashed OpenB3D and MiniB3D, this also explains why I've also had some random "model has no animation" errors in Blitz3D in the past with this exporter. So I fixed the exporter to add a +1 to the animation frames integer that it writes to the file. This has fixed it and now functions across Blitz3D/MiniB3D/OpenB3D. https://github.com/Kippykip/B3DExport

Not too sure if it's worth adding an overflow check into OpenB3D or not, as it's technically an invalid export in the first place.