Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Possible Memory Leak in SetSpriteShapePolygon()?

Author
Message
_Pauli_
AGK Developer
14
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 15th Oct 2014 11:04
Hi,

I experienced what could be a Memory Leak in the SetSpriteShapePolygon() function!
I'm using AppGameKit v1 Tier 1 (108, latest update) on Windows 7 64-Bit.

Here is some code to demonstrate:



If you then open your Windows Task Manager and observe the memory usage while running the code you will see it steadily go up, at about 16 Kb per second!
In one of my larger projects where I frequently need to update multiple polygon shapes it adds up quite a lot over time.

Can someone confirm that this is a memory leak or am I doing something wrong?

Play Super Footie Online: SuperFootie.com

Development News: Forum Thread
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 15th Oct 2014 11:11 Edited at: 15th Oct 2014 11:11
i believe here u need ,3=polygon
SetSpriteShape(spr, 0)
Docu:"Setting a shape removes all other shapes assigned to the sprite and replaces it with this one."
this i think u not need to use ClearSpriteShapes( iSpriteIndex )

AGK 108 (B)19 + AppGameKit V2 Alpha .. : Windows 8.1 Pro 64 Bit : AMD Radeon R7 265 : Mac mini
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 15th Oct 2014 15:03
I wonder if there's an issue internally with Box2D - I have a project that shows some weird behavior on Android - basically the program grinds down from 30 to 5 fps over about 5 seconds, as if a resource is being filled up. I didn't notice the same issue on the PC version. I am wondering if Box2D isn't clearing it's own buffers out.

Just to point out though - you don't want to be setting a sprite to polygon shapes in a main loop, as the command is slow due to it having to analyze the image quite closely... best to avoid those intensive calculations in the main loop. I know your code is just a test, saying this really for people new to AGK.

I am the one who knocks...
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 15th Oct 2014 15:55
hmm, the v1 version i used show me the memory increase also.
think is bug.

AGK 108 (B)19 + AppGameKit V2 Alpha .. : Windows 8.1 Pro 64 Bit : AMD Radeon R7 265 : Mac mini
_Pauli_
AGK Developer
14
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 15th Oct 2014 20:33 Edited at: 15th Oct 2014 20:35
Quote: "i believe here u need ,3=polygon"


It didn't work and I didn't expect it to. A parameter of 3 will cause the automatic creation of a best-fitting polygon, which is not what I want (and not very well suited for realtime use I guess).

Quote: "you don't want to be setting a sprite to polygon shapes in a main loop, as the command is slow due to it having to analyze the image quite closely"


Yes that's not what I want. I want to define the polygon manually. This would need to be done each frame only in extreme cases, but the construction speed impact doesn't seem to be a problem at this point. I'm more concerned about the increasing memory usage. This could cause a mobile app to crash quite rapidly.

I don't know if Box2D itself is the problem or how it is implemented in AGK. Also calling ClearSpriteShapes() before creating the polygon doesn't help. Even destroying and recreating the sprite each time won't fix it...
All these facts lead me to the conclusion that it's something internally going wrong.

Would be great if the AppGameKit developer could take a look at this!
Sometimes I wish AppGameKit would be Open Source so I could investigate the issue by myself

Play Super Footie Online: SuperFootie.com

Development News: Forum Thread
Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 16th Oct 2014 03:13
In 108.24 I got a leak of 4KB every 2-3 seconds, which went away if I used more than 2 points in the polygon. I couldn't replicate it in version 2. So it is not a high priority.
_Pauli_
AGK Developer
14
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 16th Oct 2014 10:55
Thanks for the feedback Paul!

Quote: "which went away if I used more than 2 points in the polygon"


I actually experienced this too. But this only stops memory usage from growing as long as you do not set the last point of the polygon - and if you do not set the last point it will revert back to a box shape.

Play Super Footie Online: SuperFootie.com

Development News: Forum Thread

Login to post a reply

Server time is: 2024-04-26 08:56:24
Your offset time is: 2024-04-26 08:56:24