Ooops
May 30, 2020, 04:03:46 PM

Author Topic: Openb3d (FreeTexture crash)  (Read 10645 times)

Offline markcwm

  • Sr. Member
  • ****
  • Posts: 453
Openb3d (FreeTexture crash)
« on: June 12, 2017, 04:48:52 PM »
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.

Offline Krischan

  • Full Member
  • ***
  • Posts: 211
    • Krischan's Homepage
Re: Openb3d wrapper (Part 5)
« Reply #1 on: June 12, 2017, 09:20:36 PM »
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
  1. SuperStrict
  2.  
  3. Framework openb3d.B3dglgraphics
  4. 'Framework sidesign.minib3d
  5.  
  6. Import brl.tgaloader
  7. Import brl.Map
  8.  
  9. Graphics3D(1024, 600, 32, 2)
  10.  
  11. Global cam:TCamera = CreateCamera()
  12. Global BSP:TBSP = New TBSP
  13.  
  14. Print "Start: " + GCMemAlloced()
  15.  
  16. Local ms:Int = MilliSecs()
  17.  
  18. For Local i:Int = 1 To 100
  19.  
  20.         Print "Run #" + i
  21.         BSP.AddAll
  22.         BSP.DeleteAll
  23.  
  24. Next
  25.  
  26. Print MilliSecs() - ms
  27.        
  28. End
  29.  
  30. Type TBSP
  31.  
  32.         Field pivot:TPivot
  33.         Field candle:TCandle
  34.        
  35.         Field candlemap:TMap
  36.         Global candlelist:TList
  37.                
  38.         Method New()
  39.                
  40.                 candlemap = CreateMap()
  41.                 candlelist = CreateList()
  42.                
  43.         End Method
  44.        
  45.         Method AddAll()
  46.        
  47.                 Local num:Int = Rand(100, 1000)
  48.        
  49.                 For Local i:Int = 1 To num
  50.                
  51.                         BSP.AddCandle(i)
  52.                        
  53.                 Next
  54.                
  55.                 GCCollect()
  56.                 Print "Created " + num + " Candles"': " + GCMemAlloced() + " Bytes used"
  57.        
  58.         End Method
  59.        
  60.         Method DeleteAll()
  61.        
  62.                 Local num:Int
  63.        
  64.                 For Local c:TCandle = EachIn candlelist
  65.                                
  66.                         DeleteCandle(c)
  67.                         num:+1
  68.                
  69.                 Next
  70.  
  71.                 GCCollect()
  72.                 Print "Deleted " + num + " Candles: " + GCMemAlloced() + " Bytes used"
  73.                        
  74.         End Method
  75.        
  76.         Method AddCandle(id:Int)
  77.        
  78.                 Local c:TCandle = New TCandle
  79.                 c.id = id
  80.                 c.ent = CreateSprite()
  81.                 c.tex = LoadTexture("candle.tga")
  82.                 c.x = Rnd(-100, 100)
  83.                 c.y = Rnd(-10, 10)
  84.                 c.z = Rnd(-100, 100)
  85.                
  86.                 PositionEntity c.ent, c.x, c.y, c.z
  87.                
  88.                 MapInsert(candlemap, String(c.id), c)
  89.        
  90.         End Method
  91.        
  92.         Method DeleteCandle(c:TCandle)
  93.                        
  94.                 MapRemove(candlemap, String(c.id))
  95.                 ListRemove(candlelist, c)
  96.                
  97.                 c.ent.FreeEntity
  98.                 'Print "ENT OK: " + c.id
  99.  
  100.                 c.tex.FreeTexture
  101.                 'Print "TEX OK: " + c.id
  102.  
  103.                 c = Null
  104.                
  105.         End Method
  106.  
  107. End Type
  108.  
  109. Type TCandle
  110.        
  111.         Method New()
  112.        
  113.                 ListAddLast(TBSP.candlelist, Self)
  114.        
  115.         End Method
  116.  
  117.         Field id:Int
  118.         Field ent:TSprite
  119.         Field tex:TTexture
  120.         Field parent:TEntity
  121.         Field child:TEntity
  122.         Field x:Float
  123.         Field y:Float
  124.         Field z:Float
  125.  
  126. 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
  1. Print "Start: " + GCMemAlloced()
  2.  
  3. For Local i:Int = 1 To 10000
  4.  
  5.         Local tex:TTexture = LoadTexture("candle.tga")
  6.         tex.FreeTexture
  7.         GCCollect()
  8.        
  9. Next
  10.  
  11. Print "Finish: " + GCMemAlloced()
Kind regards
Krischan

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

Offline markcwm

  • Sr. Member
  • ****
  • Posts: 453
Re: Openb3d wrapper (Part 5)
« Reply #2 on: June 13, 2017, 01:37:23 AM »
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.

Offline Krischan

  • Full Member
  • ***
  • Posts: 211
    • Krischan's Homepage
Re: Openb3d wrapper (Part 5)
« Reply #3 on: June 13, 2017, 08:03:05 AM »
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]
My Blitzbasic Archive | Extrasolar Project | My Github projects

Offline Krischan

  • Full Member
  • ***
  • Posts: 211
    • Krischan's Homepage
Re: Openb3d wrapper (Part 5)
« Reply #4 on: June 13, 2017, 07:12:02 PM »
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]
My Blitzbasic Archive | Extrasolar Project | My Github projects

Offline markcwm

  • Sr. Member
  • ****
  • Posts: 453
Re: Openb3d wrapper (Part 5)
« Reply #5 on: June 13, 2017, 09:01:24 PM »
Krischan, I was using OS Bmx (1.52) not NG so that could be the problem. I'll have a look later tonight.

Offline GW

  • Full Member
  • ***
  • Posts: 199
Re: Openb3d wrapper (Part 5)
« Reply #6 on: June 13, 2017, 09:16:25 PM »
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.

Offline Krischan

  • Full Member
  • ***
  • Posts: 211
    • Krischan's Homepage
Re: Openb3d wrapper (Part 5)
« Reply #7 on: June 13, 2017, 09:20:29 PM »
I 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]
My Blitzbasic Archive | Extrasolar Project | My Github projects

Offline GW

  • Full Member
  • ***
  • Posts: 199
Re: Openb3d wrapper (Part 5)
« Reply #8 on: June 13, 2017, 10:58:01 PM »
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'?

Offline Krischan

  • Full Member
  • ***
  • Posts: 211
    • Krischan's Homepage
Re: Openb3d wrapper (Part 5)
« Reply #9 on: June 13, 2017, 11:31:01 PM »
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]
My Blitzbasic Archive | Extrasolar Project | My Github projects

Offline markcwm

  • Sr. Member
  • ****
  • Posts: 453
Re: Openb3d wrapper (Part 5)
« Reply #10 on: June 14, 2017, 01:26:08 AM »
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.

Offline GW

  • Full Member
  • ***
  • Posts: 199
Re: Openb3d wrapper (Part 5)
« Reply #11 on: June 14, 2017, 02:13:17 AM »
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.


 

Offline markcwm

  • Sr. Member
  • ****
  • Posts: 453
Re: Openb3d wrapper (Part 5)
« Reply #12 on: June 14, 2017, 06:06:14 AM »
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.
Code: [Select]
'Text ProjectedX(),ProjectedY(),"X"
Text Int(ProjectedX()),Int(ProjectedY()),"X"
TCamera.bmx line 564
Code: [Select]
'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
Code: [Select]
'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.

Offline GW

  • Full Member
  • ***
  • Posts: 199
Re: Openb3d wrapper (Part 5)
« Reply #13 on: June 14, 2017, 07:14:22 AM »
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.

Offline Krischan

  • Full Member
  • ***
  • Posts: 211
    • Krischan's Homepage
Re: Openb3d wrapper (Part 5)
« Reply #14 on: June 14, 2017, 07:23:33 AM »
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]
My Blitzbasic Archive | Extrasolar Project | My Github projects

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal