3DS: Fix improper memory freeing (Sprite.vertices)#6434
3DS: Fix improper memory freeing (Sprite.vertices)#6434lephilousophe merged 1 commit intoscummvm:masterfrom
Conversation
|
I don't think all of this makes sense. The Sprite constructor must be called by the OSystem_3DS constructor and it is (I just checked the disassembly of What makes you think the Sprite constructor is not running? |
allocation_error_demo.txt What is actually output, however, is this:
With this PR, and with the following diff applied: |
|
You can't get the HERP DERP debug message because when Sprite is created (in the OSystem_3DS constructor), the debug facility is not yet setup (I got bitten by this on Android backend recently). About why linearGetSize returns the correct value, it's because the code is indeed wrong and you fixed it in your PR. You just have to move the |
backends/platform/3ds/sprite.cpp
Outdated
|
|
||
| void Sprite::free() { | ||
| linearFree(vertices); | ||
| memset(vertices, 0, sizeof(vertex) * 4); |
There was a problem hiding this comment.
And this one too although resetting the value is not necessary.
Anyway, I'll try your suggestion and see if that fixes the problem on my other work (my most recent commit caused it to go from this to this, and it was fixed by the changes in this PR). |
|
OK yeah, you're right. Just your suggestions fixed it. I'll change the PR. |
|
Thank you! Merging. |
Up to this point,Graphics::Surface-derivedSpriteobjects have simply been decalred in the 3DS backend'sosystem.hfile. As such, theSpriteclass's constructor was not being called, and the chunk of linear memorySprite._verticesis meant to point to wasn't being allocated. This PR rectifies that.The fact that the 3DS port has still been working to this point, despite writing into undefined space in main memory, is a happy accident. The undefined behavior only manifested during my efforts to make a framework with which 3DS hardware renderers can be created for 3D engines.Sprite.verticeswas being freed before it was meant to be freed.