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 / [SOLVED] Crash with no error message: spaces(-1)

Author
Message
Nieb
10
Years of Service
User Offline
Joined: 13th May 2014
Location: Lurking
Posted: 22nd Jun 2022 23:56
If spaces(-1) is executed the app will crash. It just disappears, no error message box.

The author of this post has marked a post as an answer.

Go to answer

Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 23rd Jun 2022 01:29
This post has been marked by the post author as the answer.
Dark Raven
10
Years of Service
User Offline
Joined: 27th Jul 2014
Location: United States
Posted: 25th Jun 2022 04:48
I'm not sure about the crashing with error message but I believe it probably has something to do with the negative 1. On the help site if you set to show c++ version it is looking to pass a unsigned integer which mean there should be an error message because of the passing of a negative number. So the lack of error and crashing is a bug but the negative number is probably what is causing it. So I'm wondering if any other function that can't take a negative number will do the same thing.
Nieb
10
Years of Service
User Offline
Joined: 13th May 2014
Location: Lurking
Posted: 4th Jul 2022 15:13
After the update it now shows the new error message with spaces(0). This was fine before, it did not cause a crash.
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 4th Jul 2022 16:04 Edited at: 4th Jul 2022 16:05
yah, i'd say the bug is a little worse now.

i dont want an error on 0. we might have a variable that inserts spaces for formatting reasons and 0 should be valid.

seems like the attempted fix did:


vs


ie, probably a simple typo which is why i want to see the fix in the first place.

ah, well. in the meantime:

Zaxxan
Developer
4
Years of Service
User Offline
Joined: 17th Nov 2020
Location: England
Posted: 6th Jul 2022 15:16
Unfortunately this is unlikely to get fixed for another 3 months.
MadBit
VIP Member
Gold Codemaster
15
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 7th Jul 2022 12:19
From the github repository -


The way the function is set up here, it should never stop at negative values.
Since the parameter length is defined as unsigned int (as Dark Raven has already noted), a -1 in hex notation would be equal to 0xffffffff (32 bit) and always positive.
Consequently, the termination condition is never reached.
Or do I see this wrong?
Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)
Nieb
10
Years of Service
User Offline
Joined: 13th May 2014
Location: Lurking
Posted: 7th Jul 2022 16:29 Edited at: 7th Jul 2022 16:35
Good catch. I've noticed if you, mistakenly, put a print() in a long loop bad things happen, even if the loop only executes once.

Example:

Here, my FPS will only be ~17 after running the long print loop only once. Also, windows reports using 600MB of RAM and high CPU usage.

So, perhaps the original issue wasn't "can't do negative spaces" but, instead "can't print a string with 4294967295 characters".
Maybe the print() function could use some safety checks on string-length and number-of-calls per-frame.

Only changing the spaces() code to: if ( length < 0 ) is still fine. If the most significant bit (or signed bit) is set it's a good indication something went wrong.
MadBit
VIP Member
Gold Codemaster
15
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 8th Jul 2022 06:45
Nieb wrote: "So, perhaps the original issue wasn't "can't do negative spaces" but, instead "can't print a string with 4294967295 characters".
Maybe the print() function could use some safety checks on string-length and number-of-calls per-frame."


This is how it will have been.
Since +1 is added to the length when reserving memory, there is an integer overflow and possibly 0xffffff becomes 0x00000000 again.
Thus, 0 bytes would be reserved for the string.
If one then writes into it, there is of course a memory error.

The correct if statement would rather be the following.

But I also wonder if a string of more than 2 terrabytes should be allowed.
That is just my opinion.
Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)

Login to post a reply

Server time is: 2024-11-23 08:27:00
Your offset time is: 2024-11-23 08:27:00