Topic: Bug in smgr.getMeshFromFileIO ?

Hi gman,
since I use Irrlicht 1.6 I get a memory exception error at device.drop() in the following code:
(With this code I want to include some primitives via incbin and device.getfilesystem().creatememoryreadfile)
The code worked well with 1.5 (I didn't try it with 1.5.1) so I guess my code is correct.
The interesting thing is: If I turn the Garbage Collector off I don't get the error anymore.
I already tried this without the mtmp.drop() (in the Create...() functions) but this has no effect on
the error. It works if I load the meshes with smgr.getmesh without the incbin stuff what means
that the mesh files are not corrupted.

primitiveinclude.bmx:

Incbin "cone.b3d"
Incbin "cube.b3d"
Incbin "cylinder.b3d"
Incbin "pyramid.b3d"
Incbin "sphere.b3d"
Incbin "plane.b3d"

Function CreatePlane:ianimatedmeshscenenode()
Local mtmp:ireadfile=device.getfilesystem().creatememoryreadfile(IncbinPtr("plane.b3d"),IncbinLen("plane.b3d"),"Plane.b3d",False)
Local mtmpb:ianimatedmeshscenenode=smgr.addanimatedmeshscenenode(smgr.getMeshFromFileIO(mtmp))
mtmpb.setmaterialflag(emf_lighting,False)
mtmp.drop()
Return mtmpb
End Function

Function CreateCone:ianimatedmeshscenenode()
Local mtmp:ireadfile=device.getfilesystem().creatememoryreadfile(IncbinPtr("cone.b3d"),IncbinLen("cone.b3d"),"Cone.b3d",False)
Local mtmpb:ianimatedmeshscenenode=smgr.addanimatedmeshscenenode(smgr.getMeshFromFileIO(mtmp))
mtmpb.setmaterialflag(emf_lighting,False)
mtmp.drop()
Return mtmpb
End Function

Function CreateCube:ianimatedmeshscenenode()
Local mtmp:ireadfile=device.getfilesystem().creatememoryreadfile(IncbinPtr("cube.b3d"),IncbinLen("cube.b3d"),"Cube.b3d",False)
Local mtmpb:ianimatedmeshscenenode=smgr.addanimatedmeshscenenode(smgr.getMeshFromFileIO(mtmp))
mtmpb.setmaterialflag(emf_lighting,False)
mtmp.drop()
Return mtmpb
End Function

Function CreateCylinder:ianimatedmeshscenenode()
Local mtmp:ireadfile=device.getfilesystem().creatememoryreadfile(IncbinPtr("cylinder.b3d"),IncbinLen("cylinder.b3d"),"Cylinder.b3d",False)
Local mtmpb:ianimatedmeshscenenode=smgr.addanimatedmeshscenenode(smgr.getMeshFromFileIO(mtmp))
mtmpb.setmaterialflag(emf_lighting,False)
mtmp.drop()
Return mtmpb
End Function

Function CreatePyramid:ianimatedmeshscenenode()
Local mtmp:ireadfile=device.getfilesystem().creatememoryreadfile(IncbinPtr("pyramid.b3d"),IncbinLen("pyramid.b3d"),"Pyramid.b3d",False)
Local mtmpb:ianimatedmeshscenenode=smgr.addanimatedmeshscenenode(smgr.getMeshFromFileIO(mtmp))
mtmpb.setmaterialflag(emf_lighting,False)
mtmp.drop()
Return mtmpb
End Function

Function CreateSphere:ianimatedmeshscenenode()
Local mtmp:ireadfile=device.getfilesystem().creatememoryreadfile(IncbinPtr("sphere.b3d"),IncbinLen("sphere.b3d"),"Sphere.b3d",False)
Local mtmpb:ianimatedmeshscenenode=smgr.addanimatedmeshscenenode(smgr.getMeshFromFileIO(mtmp))
mtmpb.setmaterialflag(emf_lighting,False)
mtmp.drop()
Return mtmpb
End Function

primitives.bmx:

Framework brl.blitz
Import Irrlicht.Core
Import brl.standardio

Include "primitiveinclude.bmx"


Global device:IrrlichtDevice = IrrlichtDevice.Create(EDT_OPENGL, _DIMENSION2DI(640, 480), 32)
        
Global driver:IVideoDriver = device.getVideoDriver()
Global smgr:ISceneManager = device.getSceneManager()
Global camera:icamerascenenode=smgr.addcamerascenenodefps()

Local cone:ianimatedmeshscenenode=CreateCone()
Local cube:ianimatedmeshscenenode=CreateCube()
cube.setposition(_vector3df(100,0,0))
Local cy:ianimatedmeshscenenode=CreateCylinder()
cy.setposition(_vector3df(50,0,0))
Local py:ianimatedmeshscenenode=CreatePyramid()
py.setposition(_vector3df(-50,0,0))
Local sp:ianimatedmeshscenenode=CreateSphere()
sp.setposition(_vector3df(-100,0,0))
Local pl:ianimatedmeshscenenode=CreatePlane()
pl.setposition(_vector3df(-150,0,0))

cone.SetScale(_Vector3df(20,20,20))
cube.SetScale(_Vector3df(20,20,20))
cy.SetScale(_Vector3df(20,20,20))
py.SetScale(_Vector3df(20,20,20))
sp.SetScale(_Vector3df(20,20,20))
pl.SetScale(_Vector3df(20,20,20))


While(device.run())
        driver.beginScene(True, True, _SCOLOR(255,100,101,140))

    smgr.drawAll()
    
    Delay 5
    
    i=i+1
    If i>360 Then i=i-360
    cone.SetRotation(_vector3df(i,i,i))
    cube.SetRotation(_vector3df(i,i,i))
    cy.SetRotation(_vector3df(i,i,i))
    py.SetRotation(_vector3df(i,i,i))
    sp.SetRotation(_vector3df(i,i,i))
    pl.SetRotation(_vector3df(i,i,i))

    driver.endScene()
Wend
device.drop()

End

Download (source, binary and meshes included): http://www.file-upload.net/download-211 … s.rar.html

I also did the same with textures and it works:

Function IrrIncBinTexture:itexture(ib:String,name:String)
Local fij:ireadfile=device.getfilesystem().createMemoryReadFile(IncbinPtr(ib),IncbinLen(ib),name,0)
Local drjz:itexture=driver.getTextureFromStream(fij)
fij.drop()
Return drjz
End Function

Due to the reason that this only doesn't work with meshes I guess that there's something wrong
with smgr.getMeshFromFileIO .

greetings,
porcus

Re: Bug in smgr.getMeshFromFileIO ?

greetings porcus!  its been a while i hope all is well smile  thank you very much for the detailed bug report and especially the compilable code.  it really helps when troubleshooting issues.  you were correct in there was an issue with the getMeshFromFileIO method.  whenever a C++ object is wrapped, by the Irrlicht mod i must be sure to say whether it needs dropped or not.  essentially, any method that starts with "create" i must be sure to tell the wrapping BMAX type to decrement the internal reference counter when dropped.  anything that starts with "add" or "get" i must tell it to not decrement the counter.  in this instance i incorrectly told it to decrement when it should not, causing the exception.  a new version of the mod has been uploaded with the appropriate fix.  you may download it by visiting the v1.6 announcements forum entry.