-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mky.mojo2 - Crash in Destroy() method of TMaterial #7
Comments
Can you please run it in a debug build and try to catch a "crash" so you can get a kind of backtrace (the debug-panel in maxide shows the "history" of commands and the content of the current objects) ... so maybe try to provide screenshots of them if you think that helps. (I cannot replicate it for now in my linux mint 21.1 setup). PS: had to update one line in it to make it compile at all:
|
Sorry, I should have put more information in my post. I tried it on Windows and it works okay, so it's a bit odd. It doesn't happen immediately on macOS...it takes around ten seconds or so. The error is, "Unhandled Exception:Attempt to access field or method of Null object". Unfortunately, the Debug panel doesn't work perfectly on macOS, so I'm not sure if the screenshot I've attached is missing anything. |
Seems "nodeenum" is null. Dunno if it tries to access this in the "hasnext" somehow. Which line does it highlight in the editor? Maybe @woollybah could check it out on his mac? |
In rendertoimage.bmx, it highlights: Local image:TImage = New TImage.Create( 256,256 ) It highlights the second line of the Destroy() method of TMaterial in graphics.bmx. |
Maybe something gets deleted while it is accessed via the enumerator? Eg a texture could be stored in the map multiple times with different keys (param) But...if the key/param is "ColorTexture"..then this is assigned to _colorTexture as well (with refcount possibly being 1) Then when deleting the material all textures stored there are "free()"d .. which also calls Destroy() and so removes gltextures etc. Am on my phone...so not that easy to check the code...so maybe behaviour as this leads to some null object somewhere...as soon as something eg goes out of scope and the GC thinks it is time to cleanup memory. Maybe prepend a GCSuspend() at the start of the file and check if it survives longer then |
I reinstalled BlitzMax to make sure I wasn't just using an old version, but the problem remains. Putting GCSuspend at the start of the example does allow it to survive. I do wonder if something is getting deleted before it should...or not even added when it should? I don't know enough about the garbage collector. |
in "debug builds" the elements survive "longer" - so sometimes the crashes do not happen there. Regarding debug panel: you might have a whirl with "vs code" and the blitzmax extension to have some debugging stuff spit out there. PS: as you confirmed that a GCSuspend() helps to survive it almost MUST be something cleaning up too much/early. |
I tried it in macos 12 (in a VM) and was not able to make it crash there ...maybe my VM is too slow to have the required effect. Edit: If you think TStringMap contains an issue ... (as it happens in the iteration over "_textures") you could replace (in graphics.bmx)
with
Maybe something there leads to the enumerator (or properties of it) become collected/inaccesible/null |
I just tried it on my Intel MacBook Air running 11.3 and it hasn't crashed/errored. The issue happens on my M2 Mac mini, so that's interesting. |
Another remark: checking graphics.bmx:
This means something is garbage collecting an TImage-Instance. And the example/sample code does that nowhere. Might the M2-stuff have issues with the bdwgc-garbage collector or the compiler doing unexpected things to our code @woollybah ? |
I checked what TImages are created: Might it be that the incbin goes kinda "out of scope" (so it is not that image in the example code but another one) ? @wombatswaffles - could you check out something? Add this to graphics.bmx
And find
Output for me is:
(you will see different memory addresses of course - both will differ to each other) If something is "officially" deleting an object (eg GC decides it is ripe for cleanup/ nobody using it) then you will also see And if that is the case you would know "which" image of the two is collected. If it is the first, then the incbin-font-image is cleaned up, if it is the second, then your image created in the example. |
I get:
And well, oddly, the problem has stopped happening for now. I guess I'll see how it goes over the next couple of days. Maybe rebuilding the modules fixed something? |
When running the rendertoimage.bmx example, it will eventually crash on the line where the image is created. The crash appears to be coming from the Destroy() method of TMaterial.
The text was updated successfully, but these errors were encountered: