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.

Dark GDK / Wierd integer glitch

Author
Message
Grenadiac111
14
Years of Service
User Offline
Joined: 23rd Dec 2009
Location:
Posted: 28th Jan 2010 16:06
this code is giving me a headache. for some reason the score integer keeps changing to 7002 even thuogh there is no code in the program that adds to the integer.

Attachments

Login to view attachments
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 28th Jan 2010 16:36
we need .cpp and .h files, not the .sln

Grenadiac111
14
Years of Service
User Offline
Joined: 23rd Dec 2009
Location:
Posted: 28th Jan 2010 16:52
soory bout that heres the cpp

Attachments

Login to view attachments
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 28th Jan 2010 17:11 Edited at: 28th Jan 2010 17:14
fixed:
add


before any other variable declaration

i dunno why this happens, its a bug in dark GDK, gets fixed by adding a dummy variable ( note that you can call it whatever you want, dgdk mess with the first variable always, for some reason )

also, you can make them global variables instead of locals ( by adding them before void DarkGDK ( void ) {...} )

Grenadiac111
14
Years of Service
User Offline
Joined: 23rd Dec 2009
Location:
Posted: 28th Jan 2010 17:21
the score is fixed now thanks i was starting to think my computer was the problem.
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 28th Jan 2010 22:16 Edited at: 28th Jan 2010 22:17
That's a very bad hack to 'fix' the issue, I noticed this happens when you try to load an image at a path that doesn't exist, for some reason it overwrites part of the stack which shows GDK lacks enough safety code. You should step through your whole program and watch the 'Score' variable until it changes, you'll then be able to see which function call triggered the alteration.

Also, don't use 'dbText (600,465,dbStr(Score));' ever, search this board for sprintf/stringstream, as there are a million threads on how to handle strings properly, such as HERE.

Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 28th Jan 2010 22:39
there are alot of functions that mess with that variable, i made a break point at every line, it seems to change after alot of functions such as dbLoadObject and dbPositionObject

dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 28th Jan 2010 22:44
I've only ever seen it occur when you pass incorrect values to a function, can you make a small runnable demo showing this happening during normal execution?

Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 28th Jan 2010 23:06 Edited at: 28th Jan 2010 23:19
http://filebeam.com/1dc5117bf54f266e12ddd0eb6d4b467b

source:


dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 28th Jan 2010 23:34
But those models don't exist, thus it's hardly normal execution. It works fine on my end when it actually loads something and under 7.4a it works regardless.

Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 29th Jan 2010 00:30
@dark coder - sorry about the off topic post but can you look at pauli's tri mesh thread, he needs to dynamicaly create a 2 dimensional array to hold his vertex data, we don't know how, or if its possible, just thought you might know, if not, no problem.
Thanks.

Grenadiac111
14
Years of Service
User Offline
Joined: 23rd Dec 2009
Location:
Posted: 29th Jan 2010 03:59
i moved the integer to the top and it has been working since plus after i moved it my proccessor started using less power and the frame rate went up dramatically as for the code itself the hole program is intended as practice code that is why some commands are scattered and others are "incorrect" according to o.o.p. i just want to make a simple game to hone my programming skills so that my next project won't be geuss work.
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 29th Jan 2010 04:38
Speed gains from changing that eh . The whole issue is derived from running code that isn't working properly(trying to load non-existent media) so you should fix that, in my current GDK library I check if the file exists then I check if the model exists after I load it and throw an assertion if either fails(note: this code won't work on its own because it requires my logging class):



You should do similar when loading any media with GDK because GDK itself doesn't throw exceptions, assertions, return false or anything on its own(though I think it sets some value in some magical place that's not documented as to whether or not something failed somewhere).

Quote: "that is why some commands are scattered and others are "incorrect" according to o.o.p."


It's not incorrect, in fact you used no global variables so it's slightly less 'incorrect' than a lot of code I see here. Besides, the exposed sections of GDK you're supposed to use aren't OO in the slightest so it's quite hard to show OOP code around here without major standardization issues.

Grenadiac111
14
Years of Service
User Offline
Joined: 23rd Dec 2009
Location:
Posted: 29th Jan 2010 20:34 Edited at: 29th Jan 2010 20:37
what do you mean by loading non existant media the media does exist but not in the link on this forum all the media loads fine on my end except a couple wierd things like one file called ppsh-41 takes almost a minute to load where as a smaller file Mg42 loads instantly and the smilely face is no where to be found but those are the only media files that dont work correctly every other media that the code attempts to load is in the same folder as the main cpp and does work. oh and disregard the change in fps it turns out my laptop was downloading an update wich it finished once i tried to run the revised code.
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 30th Jan 2010 02:13
I mean that from what I've seen, this memory overwriting bug only occurs when you attempt to load media that isn't there(or maybe if loading it fails?), if you look at Hassan's example above, it overwrites the value if you run it as-is(without media), but if you make it load valid models then it no longer overwrites stuff. So you need to validate that every single thing you load actually exists and does get correctly loaded.

Grenadiac111
14
Years of Service
User Offline
Joined: 23rd Dec 2009
Location:
Posted: 30th Jan 2010 05:42
well now that i think about it the smiley face i above mentioned hasnt benn appearing even when i lock it to the camera im not sure why it isnt appearing ive even copied the file name from the object to the load command to ensure there are no problems but it still isnt showing could this be one of the reasons why there are glitches occoring? also on one of your comments you said not to use the dbStr command why is this such an issue?
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 30th Jan 2010 06:27
Quote: "could this be one of the reasons why there are glitches occoring?"


Yes.


Quote: "also on one of your comments you said not to use the dbStr command why is this such an issue? "


Because it(like all GDK functions that return strings) dynamically allocates a char array and if you use it as an argument to dbText directly then you have no way of deallocating its memory, thus you will get a memory leak every time you use it in such a way. Using sprintf with a buffer on the stack or stringstream prevents this issue.

Grenadiac111
14
Years of Service
User Offline
Joined: 23rd Dec 2009
Location:
Posted: 30th Jan 2010 17:27
alright so could you please show me the proper way to display the Score integer at 600,465 on the screen without causing a memory leak.
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 30th Jan 2010 18:03
I did in the link I posted in my first post here.

Grenadiac111
14
Years of Service
User Offline
Joined: 23rd Dec 2009
Location:
Posted: 30th Jan 2010 18:24 Edited at: 30th Jan 2010 18:57
alright i looked at the link but since i have never used anything besides dbStr im not sure how to set it up this is the most i could figure out.

[code char string[200];
sprintf ( string, "score = %d", SCORE );
dbText ( 600, 465, string );

ive figured most of this out but i dont know what i need to replace SCORE with
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 30th Jan 2010 20:23
the integer where you store the score in

Grenadiac111
14
Years of Service
User Offline
Joined: 23rd Dec 2009
Location:
Posted: 31st Jan 2010 01:06 Edited at: 31st Jan 2010 01:15


this is what is in my cpp now but the only problem is that this is literally printing the word Score on the screen i know im asking alot of questions but could you please tell me what ive done wrong this time?

also the last time i debugged the program this error message occured

A buffer overrun has occurred in Mystery Box.exe which has corrupted the program's internal state. Press Break to debug the program or Continue to terminate the program.

For more details please see Help topic 'How to debug Buffer Overrun Issues'.


this is the first time this error has occured also this error occured after the above mentioned code was entered but this is the seccond time ive debugged the code and this error did not occur the first time.
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 31st Jan 2010 01:16
Should work, are you sure you're not looking at another text output? You could also replace 'Score' with some literal like 123456 to test it.

Grenadiac111
14
Years of Service
User Offline
Joined: 23rd Dec 2009
Location:
Posted: 31st Jan 2010 01:26
im sure this is the only text output in the lower right hand corner and ive already tried replacing score with a number anything between the parenthesis and before = %d" will print on the screen also forget the error that i got, that time that i ran the program the random number generated was a two wich caused the smily file to attempt to load i asume that is what generated the error since it has not occured agian after i removed that dbload command from the program.
Bran flakes91093
16
Years of Service
User Offline
Joined: 13th Sep 2008
Location: Crazy Land
Posted: 31st Jan 2010 03:21 Edited at: 31st Jan 2010 03:25
Move it left?
dbText(500, 465, string);

Or if you want the whole thing in the absolute corner:
dbText(dbScreenWidth() - dbTextWidth(string), 465, string);

and PS:
You may want to use something else other than 'string' as a variable because there is a container called 'string' in namespace std, and it might cause problems and just doesn't look too great. Maybe 'str'?

Your_Health = (My_Mood == HAPPY) ? 100 : NULL;
Grenadiac111
14
Years of Service
User Offline
Joined: 23rd Dec 2009
Location:
Posted: 31st Jan 2010 04:31
wait what the text is in the corner thats not the problem the code itself is printing the word score instead of what is in the score integer string is just a temporary place holder.
Bran flakes91093
16
Years of Service
User Offline
Joined: 13th Sep 2008
Location: Crazy Land
Posted: 31st Jan 2010 05:25 Edited at: 31st Jan 2010 05:35
It is the problem. The window is 640x480

What you're seeing is this part of the string (starting from the left):
"Score^ = %d"
(The caret being the cut off point)
So the actual score integer is printed off screen.

EDIT: Oh so you just want the number itself?

Well then just use
sprintf(string, "%d", Score);
http://www.cplusplus.com/reference/clibrary/cstdio/sprintf/
or
itoa(Score, string, 10);
http://www.cplusplus.com/reference/clibrary/cstdlib/itoa/

Your_Health = (My_Mood == HAPPY) ? 100 : NULL;
Grenadiac111
14
Years of Service
User Offline
Joined: 23rd Dec 2009
Location:
Posted: 31st Jan 2010 05:37
THANK you thats just what i needed ive been waiting forever to get an answer that works so to be clear it was displaying the score but it was shifted off of the screen by the word score?
Bran flakes91093
16
Years of Service
User Offline
Joined: 13th Sep 2008
Location: Crazy Land
Posted: 31st Jan 2010 17:30
Yes, I was expecting you to try this:
Quote: "dbText(dbScreenWidth() - dbTextWidth(string), 465, string);"


To show you that it was being displayed correctly.

The dbText function starts writing the text where you specify it to, and then simply continues writing, even if it goes off the screen.

Right now, unless you use the method in the quote above, if Score has too many digits, it will also end up running off of the screen (The sixth digit will never be shown).

Your_Health = (My_Mood == HAPPY) ? 100 : NULL;
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Grenadiac111
14
Years of Service
User Offline
Joined: 23rd Dec 2009
Location:
Posted: 31st Jan 2010 20:50
cool error detector, everything seems to be working in my code now so thanks to all the people that helped me sort out some bugs from my program. also ive put in the code that positions the text to fit all numbers and its working fine.
Grenadiac111
14
Years of Service
User Offline
Joined: 23rd Dec 2009
Location:
Posted: 1st Feb 2010 06:22 Edited at: 1st Feb 2010 06:46
alright i thought that the buffer overrun was done for but apparently its not. now if the program exits with the Score varriable changed the error occurs.

A buffer overrun has occurred in Mystery Box.exe which has corrupted the program's internal state. Press Break to debug the program or Continue to terminate the program.

For more details please see Help topic 'How to debug Buffer Overrun Issues'.

can someone tell me how to fix this i was told that it was from the sprintf and i should replace sprintf with sprintf_s but this causes the problem too can someone please help.

this is the code that i suspect is causing this, note that the Score integer is an int type and starts with 1000 when it is created.


dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 1st Feb 2010 06:52 Edited at: 1st Feb 2010 06:53
sprintf_s takes an extra argument, you could have look this up HERE.

[edit] why do the forums still fail at parsing links?

Grenadiac111
14
Years of Service
User Offline
Joined: 23rd Dec 2009
Location:
Posted: 1st Feb 2010 07:02
i realize that but the same thing happens with sprintf too and ive checked, its definately the sprintf command causing the error when it is replaced with dbStr the error no longer occurs but i dont know if my code is missing something or if there is a glitch. The help file said to avoid using sprintf because it was known for causing BO errors.
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 1st Feb 2010 07:07
If you really did fix that line then there's no issue with that code alone, try posting your current source code.

Grenadiac111
14
Years of Service
User Offline
Joined: 23rd Dec 2009
Location:
Posted: 1st Feb 2010 07:10 Edited at: 2nd Feb 2010 09:14
alright heres the most recent main cpp




acctualy nevermind ill just fiddle with the code and if i cant figure this out ill post a new question just concerning this new problem.

Login to post a reply

Server time is: 2024-10-01 23:26:57
Your offset time is: 2024-10-01 23:26:57