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 / [BUG] remove sprite in collision detect loop crashes player

Author
Message
tmu
7
Years of Service
User Offline
Joined: 2nd Feb 2017
Location:
Posted: 23rd Jul 2017 20:16
The following code crashes the AppGameKit player. Most likely because the getSpriteNextContact() is trying to reference a sprite that was just deleted. I resolved it by doing any delete after the loop. But something other than crashing the player would be nice.




Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 23rd Jul 2017 21:09
if you delete a sprite id you should also reset the sprite id variable to 0
DeleteSprite(sid1)
sid1=0

myself prefer do loop with exit after a condition
AGK (Steam) V2017.07.19 : Windows 10 Pro 64 Bit : AMD (17.4.4) Radeon R7 265 : Mac mini OS Sierra (10.12.2)
PartTimeCoder
AGK Tool Maker
9
Years of Service
Recently Online
Joined: 9th Mar 2015
Location: London UK
Posted: 23rd Jul 2017 21:31 Edited at: 23rd Jul 2017 21:34
both your sprites are created at the same position so the contact is immediate, the first loop deletes the sprite so the second loop caused "GetSpriteFirstContact(sid1)" to cause an error because sid1 no longer exists, but that being said, you should always check for a sprites existence before trying to use its variable, especially if the sprite gets deleted at some point.

tmu
7
Years of Service
User Offline
Joined: 2nd Feb 2017
Location:
Posted: 25th Jul 2017 13:48
This was just an example to illustrate what i found. The point being the AppGameKit Player should not crash (core dump style) on me but rather give me an error. At least it would be quite a bit easier to debug what I did wrong.

I have no problem agreeing on not deleteing the sprite before asking if it has more collisions. It was a silly implementation but that is how most of my implementations start and then get improved to be slightly less silly.

PartTimeCoder
AGK Tool Maker
9
Years of Service
Recently Online
Joined: 9th Mar 2015
Location: London UK
Posted: 25th Jul 2017 14:34
oh ok, well it didn't crash for me it threw an error "sprite xxx does not exist ....", I agree it does not help when it crashes.
Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 25th Jul 2017 21:11
Thanks, fixed for the next version.

Login to post a reply

Server time is: 2024-04-25 21:54:23
Your offset time is: 2024-04-25 21:54:23