May 30, 2020, 03:22:35 PM

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

Offline Krischan

  • Full Member
  • ***
  • Posts: 211
    • Krischan's Homepage
Re: Openb3d wrapper (Part 5)
« Reply #30 on: June 17, 2017, 12:46:20 PM »
Good to hear Mark, and I really hope that OpenB3D becomes the real successor to miniB3D which has been never finished - if you have time for it. I'm not very familar with the C++ subroutines to help finding the deeper bugs but I can do the testing, and my current project already uses a lot of the OpenB3D functions.
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 #31 on: June 18, 2017, 01:55:40 AM »
Umm Mark, I'm not sure but I think I've found the solution for our problem. Your version could be ok if you can confirm this: just switch the FreeEntity/FreeTexture order in my demo and it'll run fine, I only had one (!) crash and I couldn't reproduce this one again. But I don't trust this solution so please try it yourself.

If it works I can't believe I've overseen this the last days as it makes sense to clear the texture first and then free the entity (to which the texture has been assigned!). I don't know why this worked flawless in miniB3D.

Wrong:
c.ent.FreeEntity
c.tex.FreeTexture

Right:
c.tex.FreeTexture
c.ent.FreeEntity

or to make sure the texture will be cleared from VRAM, see below:
c.tex.FreeTexture
glDeleteTextures 1, TTexture(c.tex).texture
c.ent.FreeEntity

Just one thing: my VRAM usage in the Open Hardware Monitor stays constant at 14,7% (I have 4GB VRAM) which is 0,6% more than before if I add the glDeleteTextures command. If I don't add it, the usage climbs up to 16.7% (see attached image). Perhaps you should add this command to the Freetexture routine to really free up the VRAM from all deleted textures?

Here's the complete test source I've used (with the glDeleteTextures command disabled)
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)
  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.tex.FreeTexture
  98.                 'glDeleteTextures 1, TTexture(c.tex).texture
  99.                 c.ent.FreeEntity
  100.  
  101.                 c = Null
  102.                
  103.         End Method
  104.  
  105. End Type
  106.  
  107. Type TCandle
  108.        
  109.         Method New()
  110.        
  111.                 ListAddLast(TBSP.candlelist, Self)
  112.        
  113.         End Method
  114.  
  115.         Field id:Int
  116.         Field ent:TSprite
  117.         Field tex:TTexture
  118.         Field parent:TEntity
  119.         Field child:TEntity
  120.         Field x:Float
  121.         Field y:Float
  122.         Field z:Float
  123.  
  124. End Type

and the fixed Method in TTexture.bmx:
Code: BlitzMax
  1.         ' SMALLFIXES New function from www.blitzbasic.com/Community/posts.php?topic=88263#1002039
  2.         Method FreeTexture()
  3.        
  4.                 If exists
  5.                         ListRemove( tex_list,Self ) ; tex_list_id:-1
  6.                        
  7.                         FreeTexture_( GetInstance(Self) )
  8.                         FreeObject( GetInstance(Self) )
  9.                         glDeleteTextures 1, texture
  10.                         exists=0
  11.                 EndIf
  12.                
  13.         End Method
  14.  
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 #32 on: June 18, 2017, 05:20:16 PM »
No I tried FreeTexture before FreeEntity and it's not a solution, also you don't want to have to do this as like you say, it makes no sense as entity and texture are different types.

I do have a solution though, the problem is in the c++, the textures are stored in tex_list and repeated entries of texture objects are prevented. So if you load the same texture again and then delete that reference, the second texture needs this reference so it crashes. When I removed this feature it stopped crashing, and I've been able to make it crash consistently. This doesn't happen in Minib3d because Tlist is more stable than c++ lists. So the fix is to have an extra list for repeat textures so it knows how many there are to delete.

Also, yes I think we need glDeleteTextures in there as it is in Minib3d and you have proved it does something, so thanks. I just need to get a commit out now.

Offline Krischan

  • Full Member
  • ***
  • Posts: 211
    • Krischan's Homepage
Re: Openb3d wrapper (Part 5)
« Reply #33 on: June 18, 2017, 05:58:55 PM »
Sounds good, looking forward to a fixed version to play with :-D
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 #34 on: June 19, 2017, 12:15:00 AM »
It's out, have fun. Hope it works, it did seem to on my initial test.

It has glDeleteTextures in FreeTexture and is managed by a new list named tex_list_all to check for repeat texture entries.

If you wonder how this relates to shader material textures, they don't get added to a list and can't be deleted other than with FreeShader.

Edit: oops, it still crashes.

Offline markcwm

  • Sr. Member
  • ****
  • Posts: 453
Re: Openb3d wrapper (Part 5)
« Reply #35 on: June 19, 2017, 03:27:16 AM »
I really think I've nailed this bug down now Krischan! I forgot to add to FreeTexture in TTexture.bmx and I made a mistake in how to add tex_list_all in texture.cpp. Other than that I believe my theory was correct! Tested it well and it runs nicely.

It's inspiring to know I can come back after a year and get into coding again quite easily, it's all still there in the mind, I suppose you could say it is "lurking". I was lurking quite often last year. lol

Offline Krischan

  • Full Member
  • ***
  • Posts: 211
    • Krischan's Homepage
Re: Openb3d wrapper (Part 5)
« Reply #36 on: June 19, 2017, 07:44:29 AM »
Good job Mark, it seems to work now! Unfortunately I've got a lot of work this week so I only can take a deeper look at the weekend to continue working on my Legend of Faerghail project and finish the media and level loader/unloader.
Kind regards
Krischan

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

Offline Naughty Alien

  • Hero Member
  • *****
  • Posts: 701
Re: Openb3d wrapper (Part 5)
« Reply #37 on: June 19, 2017, 05:17:09 PM »
..guys..which version i have to download?? Im using BMX vanilla 1.5 .. i did try https://github.com/markcwm/openb3d.mod ,
but it just doesnt work and i cant compile modules(using blide)..can you point me at proper version, please..

Offline Krischan

  • Full Member
  • ***
  • Posts: 211
    • Krischan's Homepage
Re: Openb3d wrapper (Part 5)
« Reply #38 on: June 19, 2017, 06:47:38 PM »
I'm using BlitzMax OS 1.52 with Mark's latest OpenB3D version, TDM GCC 5.102 (MinGW). This is the latest "Non-BlitzmaxNG" setup. As BLIde is not 100% compatible to Blitzmax NG yet you should use try this setup first unless you need 64bit support.

You can download my precompiled Blitzmax Installation for Windows, don't forget to set the MinGW environment variable/path to the MinGW subfolder. It includes a batch in the "bin" folder to recompile a new version from Mark and works with BLIde's latest version under Windows 10 (but you shouldn't (re)compile modules using BLIde anymore).
Kind regards
Krischan

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

Offline Naughty Alien

  • Hero Member
  • *****
  • Posts: 701
Re: Openb3d wrapper (Part 5)
« Reply #39 on: June 20, 2017, 05:59:02 AM »
..i did exactly as you suggested, and this is error im having now..



Offline Krischan

  • Full Member
  • ***
  • Posts: 211
    • Krischan's Homepage
Re: Openb3d wrapper (Part 5)
« Reply #40 on: June 20, 2017, 07:17:41 AM »
The 11th commandment: Thou shalt not build modules with BLIde anymore (unless there is a new patch, if ever).



And make sure your environment settings match the MinGW path (press Win+Pause, in my setup it is for example c:\Apps\Blitzmax\MinGW):
Kind regards
Krischan

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

Offline Naughty Alien

  • Hero Member
  • *****
  • Posts: 701
Re: Openb3d wrapper (Part 5)
« Reply #41 on: June 20, 2017, 07:43:53 AM »
..that is fine, i have set environment variable...now what would be 'manual' way of compiling mod which should do job?

Offline Krischan

  • Full Member
  • ***
  • Posts: 211
    • Krischan's Homepage
Re: Openb3d wrapper (Part 5)
« Reply #42 on: June 20, 2017, 07:54:17 AM »
Go to the BIN subfolder, open a commandline window and type (or create a Batch file and execute it)

bmk makemods -a openb3d

Beside that I tried again building modules in BLIde using my setup I've uploaded (see previous posts) and it still worked, so there must be something wrong with your setup. If it still doesn't work you can try my setup. But compiling modules in BLIde won't work correct if you're using Blitzmax NG (and BLIde has no option to build x64 yet).

You can use BLIde to check if your MinGW setup is correct (Tools > Configure the MinGW compiler):
Kind regards
Krischan

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

Offline Naughty Alien

  • Hero Member
  • *****
  • Posts: 701
Re: Openb3d wrapper (Part 5)
« Reply #43 on: June 20, 2017, 08:23:23 AM »
..okay..now, modules are built without error, however, i cant run example as im getting this error..


Offline Krischan

  • Full Member
  • ***
  • Posts: 211
    • Krischan's Homepage
Re: Openb3d wrapper (Part 5)
« Reply #44 on: June 20, 2017, 08:45:49 AM »
There is still something wrong with your setup. Did you try my Blitzmax installation?
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