OpenB3D FreeEntity crash with 3DS files

Started by Kippykip, November 13, 2017, 20:40:17

Previous topic - Next topic

Kippykip

Hey everyone, I'm currently making my project load .3DS maps but I found out that if I free the map, and load a new one in the same variable there's a 50/50 chance that it'll crash pointing to RenderWorld.
Not exactly sure why that happens, if I make the map load and unload using CreateCube etc, it seems to work just fine.
This doesn't seem to happen with .B3D models, but I haven't tested this thoroughly enough since my main map editor doesn't support B3D.
Anybody else have this problem?

EDIT 1: I'm struggling to replicate it outside my project, which is really odd.
EDIT 2: It also has something to do with parents, as it doesn't crash it if I get rid of the parent
EDIT 3: Getting rid of my "If(FileType(DEFS.STR_MapDir:String + TMP_FileName:String + ".3ds"))" also makes it not crash, even with and else statement of the same thing it just works...

Flanker

Maybe try something like that when you free your mesh :
FreeEntity(mesh)
mesh = Null


I remember having similar problems a few months ago, and the Null pointer solved it. I guess it's related to the garbage collector wich is called only when there is enough data to free or something like that, there were discussions about it on the old forum. Maybe you can use GCCollect() there too.
Everyone knew it was impossible, until someone who didn't know made it.

Kippykip

#2
Yeah it sets it to null, but it still crashes after doing the function twice.
Type Map
Global MapMesh:TEntity

Function LoadMap(TMP_FileName:String)

'Unload existing stuff
If(MapMesh:TEntity)
FreeEntity(MapMesh:TEntity)
MapMesh:TEntity = Null
EndIf

If(FileType(DEFS.STR_MapDir:String + TMP_FileName:String + ".3ds"))
'Wtf? models are case sensitive in openb3d?
MapMesh:TEntity = LoadAnimMesh(DEFS.STR_MapDir:String + TMP_FileName:String + ".3ds", Game.World:TEntity)
RotateEntity(MapMesh:TEntity, - 90, 0, 0)       'Sketchup rotes it
ScaleEntity MapMesh:TEntity, - 16, 16, 16 'Scale roughly to meters
FlipMesh(TMesh(MapMesh:TEntity))    'Sketchup inverts it?
Else
MapMesh:TEntity = CreateCube()        'Stops crashes if it doesn't exist
Console.AddText("Error: Map doesn't exist! Map = CreateCube")
EndIf
EntityFX MapMesh:TEntity, 1 + 2 + 4 'Full-bright.
End Function
End Type


Here's a summarised bit of my code, it's really weird

EDIT: Changing
If(FileType(DEFS.STR_MapDir:String + TMP_FileName:String + ".3ds"))
to
If(True)

Fixes it, what?!??!

EDIT 2: Okay now it doesn't after adding a couple extra lines nearby.
I'm at a loss on what is going on here.

markcwm

#3
Unless your map has animation data you should just use LoadMesh.

I recently added a new 3DS loader so you should try that first, you call LoadMesh(file,par) for the native loaders (3DS/B3D but no animation, that's what I'm working on atm), for the library loaders you must now set the 3rd parameter to False ie. LoadMesh(file,Null,0), the native 3ds loader is better, and less likely to fail, the old 3DS loader is really not reliable (same for X). You can also debug with "T3DS.Log_Chunks=1" which might help (I'll change this soon to just Log_Chunks).

If this doesn't work you could try the Assimp 3DS loader unless you're in Windows with MinGW 5.1 (or less) in which case 3ds files won't load due to a missing dependency, upgrading to a later GCC should fix it but I haven't tried this yet. Anyway you use aiLoadMesh(file,par,flags) where the 3rd parameter now sets processing steps -1 for smooth shaded, -2 for flat, anything else for custom (common.bmx).

Kippykip

#4
Quote from: markcwm on November 14, 2017, 00:54:54
Unless your map has animation data you should just use LoadMesh.

I recently added a new 3DS loader so you should try that first, you call LoadMesh(file,par) for the native loaders (3DS/B3D but no animation, that's what I'm working on atm), for the library loaders you must now set the 3rd parameter to False ie. LoadMesh(file,Null,0), the native 3ds loader is better, and less likely to fail, the old 3DS loader is really not reliable (same for X). You can also debug with "T3DS.Log_Chunks=1" which might help (I'll change this soon to just Log_Chunks).

If this doesn't work you could try the Assimp 3DS loader unless you're in Windows with MinGW 5.1 (or less) in which case 3ds files won't load due to a missing dependency, upgrading to a later GCC should fix it but I haven't tried this yet. Anyway you use aiLoadMesh(file,par,flags) where the 3rd parameter now sets processing steps -1 for smooth shaded, -2 for flat, anything else for custom (common.bmx).

Thanks dude, I'll experiment with the latest version a try, plus using LoadMesh instead of LoadAnimMesh (as there's no animations on my maps) etc.
I'll update on how this goes

EDIT 1:
Having it set to LoadMesh instead of LoadAnimMesh crashes it in TEntity.bmx at:
Method FreeEntity()

If exists
Local inst:Byte Ptr=GetInstance(Self)
FreeEntityList()
FreeEntity_(inst)
exists=0
EndIf

End Method

Specifically at this part:
FreeEntity_(inst)

If I set it back to LoadAnimMesh it doesn't give me any output with T3DS.Log_Chunks = 1, but otherwise it seems to give me the full output when loading it.
It's when I'm actually freeing it that I now have a problem.
However it's probably because of no reference, as there's no textures on the model and the postion/rotate commands don't do anything to it.

Edit 2: After just adding new code to completely unrelated areas of the program, the problem is gone again.
I'm starting to think this is a problem with the Blitzmax-NG compiler at this point.