Openb3d (FreeTexture crash)

Started by markcwm, June 12, 2017, 16:48:52

Previous topic - Next topic

markcwm

Well development continues here at Syntaxbomb then thanks to Qube! Since Syntaxbomb topics have a page per 15 posts, I think it's better to post new issues with the wrapper in new topics now. Thanks.

For download links see Openb3d Roadmap.

Krischan

#1
I'm hunting a nasty bug in OpenB3D, nasty because it only happens sometimes and within a Type. For my BSP Loader it is absolutely necessary to load AND unload entities and textures within a Type (and using a TMap, too for comparison reasons but that is not used in my example yet).

The following code crashes in OpenB3D after a few iterations while in miniB3D it works fine until the end. Can you please take a look at it? I've tested it with both versions of OpenB3D (Main Branch and DruggedBunny). I think it crashes either at FreeEntity or FreeTexture in the DeleteCandle Method, but its hard to track it.

Code (BlitzMax) Select
SuperStrict

Framework openb3d.B3dglgraphics
'Framework sidesign.minib3d

Import brl.tgaloader
Import brl.Map

Graphics3D(1024, 600, 32, 2)

Global cam:TCamera = CreateCamera()
Global BSP:TBSP = New TBSP

Print "Start: " + GCMemAlloced()

Local ms:Int = MilliSecs()

For Local i:Int = 1 To 100

Print "Run #" + i
BSP.AddAll
BSP.DeleteAll

Next

Print MilliSecs() - ms

End

Type TBSP

Field pivot:TPivot
Field candle:TCandle

Field candlemap:TMap
Global candlelist:TList

Method New()

candlemap = CreateMap()
candlelist = CreateList()

End Method

Method AddAll()

Local num:Int = Rand(100, 1000)

For Local i:Int = 1 To num

BSP.AddCandle(i)

Next

GCCollect()
Print "Created " + num + " Candles"': " + GCMemAlloced() + " Bytes used"

End Method

Method DeleteAll()

Local num:Int

For Local c:TCandle = EachIn candlelist

DeleteCandle(c)
num:+1

Next

GCCollect()
Print "Deleted " + num + " Candles: " + GCMemAlloced() + " Bytes used"

End Method

Method AddCandle(id:Int)

Local c:TCandle = New TCandle
c.id = id
c.ent = CreateSprite()
c.tex = LoadTexture("candle.tga")
c.x = Rnd(-100, 100)
c.y = Rnd(-10, 10)
c.z = Rnd(-100, 100)

PositionEntity c.ent, c.x, c.y, c.z

MapInsert(candlemap, String(c.id), c)

End Method

Method DeleteCandle(c:TCandle)

MapRemove(candlemap, String(c.id))
ListRemove(candlelist, c)

c.ent.FreeEntity
'Print "ENT OK: " + c.id

c.tex.FreeTexture
'Print "TEX OK: " + c.id

c = Null

End Method

End Type

Type TCandle

Method New()

ListAddLast(TBSP.candlelist, Self)

End Method

Field id:Int
Field ent:TSprite
Field tex:TTexture
Field parent:TEntity
Field child:TEntity
Field x:Float
Field y:Float
Field z:Float

End Type


Edit: just to mention that the following code works flawlass in OpenB3D (and is much faster than in miniB3D). Hmmm it looks like if the texture object isn't available anymore sometimes when the execution reaches the freetexture section (you can check this if you add a print command AFTER each "free" command in the example above, in my runs I always see as last entry the print output after the Freeentity command, but never the print output after the FreeTexture command (I've edited the code above now and commented the lines), so I assume there lies the problem.

Code (BlitzMax) Select
Print "Start: " + GCMemAlloced()

For Local i:Int = 1 To 10000

Local tex:TTexture = LoadTexture("candle.tga")
tex.FreeTexture
GCCollect()

Next

Print "Finish: " + GCMemAlloced()
Kind regards
Krischan

Windows 10 Pro | i7 9700K@ 3.6GHz | RTX 2080 8GB]
Metaverse | Blitzbasic Archive | My Github projects

markcwm

Krischan, I've tested your code in win7 using Druggedbunny and my branch and Minib3d 0.54 and can't reproduce the crash. Openb3d was 2 to 3 times slower than Minib3d but always finished at 100.

Maybe the tga file your using is not properly supported by Openb3d, so try the file I was using examples/media/compressed.tga. I think FreeEntity and FreeTexture should be okay, I remember fixing all the free commands. It could also be a lib conflict due to your MinGW, sometimes that makes inexplicable things happen, I'm using TDM64-GCC 5.1.0-2.

I can't think of anything else.

Krischan

Hmm the TGA is ok, I've tried it now with a complete new setup (NG: BlitzMax_win32_0.87.3.16.7z | DruggedBunny: openb3d.mod-master.zip) and only copied my BLIde to the folder, rebuilt all modules, restarted BLIde. It still compiles fine but the error stays, with both TGA's (attached my Candle TGA here). I must try your setup later, must go to work now.

Kind regards
Krischan

Windows 10 Pro | i7 9700K@ 3.6GHz | RTX 2080 8GB]
Metaverse | Blitzbasic Archive | My Github projects

Krischan

#4
Mark, I can't get your setup running and I'm confused how to do the setup correctly. I'm using Windows 10 (x64) fully patched with an nVidia GTX 780M (Driver 381.89) and did this:

1. already had an environment variable MinGW pointing to c:\Apps\Blitzmax\MinGW
2. installed BlitzMax150_win32x86.exe from here to c:\Apps\Blitzmax
3. installed tdm64-gcc-5.1.0-2.exe from here with standard Settings to c:\Apps\Blitzmax\MinGW
3. copied my (already installed) BLIde folder to c:\Apps\Blitzmax\BLIde
4. copied the "sidesign.mod" folder from this ZIP archive to c:\Apps\Blitzmax\mod
5. copied the "openb3d.mod" folder from this ZIP archive to c:\Apps\Blitzmax\mod
6. run BLIde (MinGW path is already configured to c:\Apps\Blitzmax\MinGW there), checked this before
7. rebuilt all modules using BLIde's Advanced Module Builder (not threaded and miniB3d/OpenB3D modules are listed)
8. all modules were built without any errors ("84 modules built and 0 modules not built"), checked the mod subfolders and they are all populated with a lot of .a and .i files now
9. closed and reopened BLIde and executed my posted source above

MiniB3D compiles fine only in Debug mode while OpenB3D refuses compiling (see error message below). So I repeated the steps 5 to 9 with your version from here, renamed the openb3d.mod-master to openb3d.mod and recompiled only this mod branch, this time with 2 errors ("5 modules built and 2 modules not built"), the b3dglsdlgraphics and openb3dsdl were the two modules. Same result, OpenB3D still not working.

Did I miss something? I can't remember how I did the setup a year ago but its still working when I copy my backup folder to the same location (the Readme says "GCC 4.6 & 4.7 Series", don't know which exact version I have there, the gcc.exe date is August 15, 2012 06:37).
Kind regards
Krischan

Windows 10 Pro | i7 9700K@ 3.6GHz | RTX 2080 8GB]
Metaverse | Blitzbasic Archive | My Github projects

markcwm

Krischan, I was using OS Bmx (1.52) not NG so that could be the problem. I'll have a look later tonight.

GW

I use OS BMax too and have no issue openb3d. Not sure if the older Bmax used the -m32 flag when compiling C. Which may mean your trying to mix x86 and x64.  I also use the mingw that comes with the BmaxNG binary package.

Krischan

Quote from: GW on June 13, 2017, 21:16:25I also use the mingw that comes with the BmaxNG binary package.
Hmm which package from where? I recently tried the 0.87 (BlitzMax_win32_0.87.3.16.7z) and I only noticed that the module built process was extremely slow and it won't compile miniB3D or OpenB3D. Guys, I'm really stuck and could need some help as this is a showstopper for my current project :-(

Or could you upload a working current BlitzMax+MinGW+OpenB3D+miniB3D development environment archive somewhere?
Kind regards
Krischan

Windows 10 Pro | i7 9700K@ 3.6GHz | RTX 2080 8GB]
Metaverse | Blitzbasic Archive | My Github projects

GW

You can get Blitzmax OS here: https://github.com/blitz-research/blitzmax
If you downloaded BmaxNG 087 did you notice a directory inside called 'Mingw32'?

Krischan

Quote from: GW on June 13, 2017, 22:58:01
You can get Blitzmax OS here: https://github.com/blitz-research/blitzmax
If you downloaded BmaxNG 087 did you notice a directory inside called 'Mingw32'?

Yes, and I did rename MinGW32 to MinGW to match my environment variable.

Ok, now I downloaded Blitzmax OS, installed the tdm64-gcc-5.1.0-2.exe and compiled the setup using the install.bat - worked. After that I copied sidesign and openb3d to the mod folder and compiled both - worked. Now, when I run my test script above BOTH mods crash, before that only OpenB3D crashed. I don't understand it anymore what's going wrong here.

Going to bed now, I'm depressed :-(
Kind regards
Krischan

Windows 10 Pro | i7 9700K@ 3.6GHz | RTX 2080 8GB]
Metaverse | Blitzbasic Archive | My Github projects

markcwm

#10
Yes it's not the TGA file, sorry that was a long shot. Thanks for uploading the file for me Krischan. :)

Okay, you're using the wrong version of MinGW with Bmx 1.50, it needs an older version. TDM gcc 4.8.1 is maximum. If you use OS Bmx you can (and should) use TDM gcc 5.1.0. This is possible because you can rebuild bcc exe with OS Bmx whereas Bmx 1.50 bcc was closed source (built with gcc 4.6.1 iirc).

Just a word about MinGW I realized this just yesterday. The official MinGW is on sourceforge, then there's the w64 fork which is 64 bit, then there's TDM which takes these two to provide it's 32/64 bit version and Nuwen which is 32 bit. Each have different build numbers and should work with Bmx if the build is compatible.

The problem with my branch of openb3d is the sdl/gles stuff is broken and I don't know how to fix it, for now you can remove/rename the two mod folders named sdl and it will build and run fine. [Removed in latest commit]

If you're using a TDM 64 bit MinGW you should be able to build 64 or 32 bit without issues. I think GW means the older Nuwen MinGW version which was 32 bit only.

I did have openb3d building with Bmx NG but I used v0.77 which I got from Dabz NG site that's your best bet. There is a v0.70 on Brucey's NG git which might work and there's a v0.81 source there I'd like to try, dated july 2016. As a rule of thumb, if Minib3d doesn't work then it's a Bmx NG bug.

You don't have to rename the MinGW folder to match the MINGW env var name, the env var contains the path, I think the env var does need to be called "mingw".

The crash of both mods is strange, it must be something wrong with your setup. I don't have win10 to test unfortunately but make sure you set the right MinGW env var AND path, I have forget that a few times. Also always run an example to make sure it's working before tests. Also you must build OS Bmx with the same gcc you later build modules with.

Anyway I hope you can sort it out Krischan.

GW

Btw, I use BmaxOS and NG I have only one copy of mingw installed and it's the one that comes with NG (5.1.0)
Openb3d works fine for me with both blitzmax' 32 and 64 bit. My openb3d mod is labeled as 1.0. not sure if that is the latest one.


My point is that people no longer have to to deal with different copies of mingw scattered all over their system like the past.
Drop bmax 1.50 official.. Use bmaxOS and bmaxNG and everything should be good for both 32 and 64 bit.



markcwm

Okay, I built Bmax NG 0.77 and tried Minib3d but had to change a few source lines for type cast errors, I'm just going to list them here as I don't have a fork of Minib3d.
TDebug.bmx line 228,239.
'Text ProjectedX(),ProjectedY(),"X"
Text Int(ProjectedX()),Int(ProjectedY()),"X"

TCamera.bmx line 564
'accPerspective(ATan((1.0/(zoom#*ratio#)))*2.0,ratio#,range_near#,range_far#,jx#,jy#,0.0,0.0,1.0)
accPerspective(Float(ATan((1.0/(zoom#*ratio#)))*2.0),ratio#,range_near#,range_far#,jx#,jy#,0.0,0.0,1.0)

TMesh.bmx line 1886
'glTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE, 2.0)
glTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE, 2)


Openb3d didn't compile with NG but I fixed the errors which weren't too many and have a new commit on my git. I removed the sdl stuff and added a FindChild fix by DruggedBunny which I need to test yet.

I agree GW, no need for Bmax 1.50 when we have 1.52 which has some extra fixes and no lib conflict issues. The copy of MinGW in Bmx NG is the same as I use 5.1.0, I just prefer the TDM installer.

GW

NG supports method overloading, so it will complain about mismatched types, even primitive types, so passing a float to a function that expects an int will error out.
If you use the BMK flag -w it will suppress these errors to warnings and everything should build fine.

Krischan

Wow. Thanks guys, I must give it another try later. Perhaps we should add a new step-by-step installation instruction in the first post as it is very confusing.
Kind regards
Krischan

Windows 10 Pro | i7 9700K@ 3.6GHz | RTX 2080 8GB]
Metaverse | Blitzbasic Archive | My Github projects