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 / Something is serously wrong here :(

Author
Message
Plystire
21
Years of Service
User Offline
Joined: 18th Feb 2003
Location: Staring into the digital ether
Posted: 30th Jan 2009 03:18
Alright, since I couldn't get to the bottom of the random image bug in my game, I decided to continue developing anyway.

Didn't change much, just slowed down the speed at which things moved and sat down and played it for about 20-25 minutes.


Here's what's happening:
I have some constant variables declared at the beginning of my program to retain ratios for the display.
During the game, I had so many things going at once that the framerate was just grinding horribly. Around this point the bug I mentioned earlier came into play, but since the framerate was so low, I could see it plain as day, and it kind of slid to the right before disappearing.
Here's where I'm stumped.... immediately after the image disappears the entire screen just screws up! My ship isn't locked in the center anymore, images are inverted, etc.
I Alt+Tabbed out to see what was going on and it turns out that somehow, some junk information got thrown into my constant variable holding the screen ratio!!!


How does this happen?!? It's a constant, it's not supposed to be able to change!


Has anyone else had this happen before?


The one and only,


SunDawg
19
Years of Service
User Offline
Joined: 21st Dec 2004
Location: Massachusetts
Posted: 30th Jan 2009 04:19
I've had variables, especially when using typedef and struct, decide to spontaneously reassign themselves, or not set to what I set them to. I don't know why, but it's a serious handicap. I got around it by using classes, but I shouldn't have needed to do so.


My site, for various stuff that I make.
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 30th Jan 2009 06:53
Posting some code would help us find the issue with your code?

Michael P
18
Years of Service
User Offline
Joined: 6th Mar 2006
Location: London (UK)
Posted: 30th Jan 2009 11:10
This could happen if you are doing silly things with memory, like deallocating memory and then trying to change its contents. Normally though your debugger would pick this up.

It could be that part of your computer is dieing e.g. graphics card, perhaps if you post an exe we can test it for you and see if its your code or your system.
Plystire
21
Years of Service
User Offline
Joined: 18th Feb 2003
Location: Staring into the digital ether
Posted: 30th Jan 2009 11:47
Well... I just let myfriend play it and he says he never encounters either bug, so I'm worried that it may be something with my computer.

Though, nothing else on my computer acts up.


But like I said, it took like 20-25 minutes for it to do that, and I know it doesn't always do that as I've played it many times that long.

Thanks for the responses. I just wanted to know what may cause this, if anyone knew.



The one and only,


Michael P
18
Years of Service
User Offline
Joined: 6th Mar 2006
Location: London (UK)
Posted: 30th Jan 2009 11:54 Edited at: 30th Jan 2009 11:55
Could there be a memory leak? Look in windows task manager and see if memory usage steadily increases for your application. Eventually it will exhaust all memory and crash. You could be allocating memory without deallocating it, that would explain why it only crashes after so long.
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 30th Jan 2009 12:46
Sometimes I've met strange issues. For example, once I defined one bool as true, and I discovered that it could not be changed to false during the execution, really strange. I changed it to false in the definition and it behaved normally, uh.

Apart from the cosmic rays, magnetic fields, and other external interactions, I'd revise all the code as suggested. Make sure all variable initializations are done explicitly, and revise that all array index are into the array scope, etc.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 30th Jan 2009 22:06 Edited at: 30th Jan 2009 22:07
You can probably put all the problems you've all described down to bad memory handling.

Here's what I advise:
1. Avoid memory allocation.

Use the STL structures provided if you need dynamic allocation - That's what they are there for. If what you want isn't provided by the STL, check out boost.

2. When you can't avoid memory allocation, wrap it in a class.

Make sure the class is either non-copyable (boost: see below), or make sure that it can be copied properly (ie, give it copy constructor, assignment operator and a destructor, and make sure they work correctly).

3. When a class is too 'heavy', use a smart pointer.

... such as provided in the boost libraries.


http://www.boost.org/
Most of the boost libraries are header-only and don't need you to build any anything ahead of time to use them.

boost::noncopyable - inherit from this class privately and you can't accidentally copy your class.

boost::shared_ptr for shared pointers where you want to pass them around, but don't want to determine for yourself when the object pointed to should be deleted.

boost::scoped_ptr for local allocation of objects - only one copy of the pointer is available and it automatically cleans up when it goes out of scope.

boost::ptr_vector and others - store pointers in vectors, maps, linked lists etc but access them as if they were not pointers.

Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 30th Jan 2009 22:11
You might have an char array stored close to where your constants are stored and if you're not careful and go out of bounds it might impact the constant. That's at a guess, though. Storage might automatically group similar data types together.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Plystire
21
Years of Service
User Offline
Joined: 18th Feb 2003
Location: Staring into the digital ether
Posted: 30th Jan 2009 23:20
Thanks, guys. I'll try those out and see how it goes!


The one and only,


jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 31st Jan 2009 05:23
Quote: "Avoid memory allocation."
Boo

Quote: "Use the STL structures provided if you need dynamic allocation "
Boo

Quote: "When a class is too 'heavy', use a smart pointer"
YAY!

All awesome suggestions - and to avoid mem issues - IanM is right - though - I'm of the Black Arts Coding Variety - and most of my decent optimization code tricks do all sorts of "RAW" stuff - but you definately need to have a handle on things - memory handles included LOL - to do them!

--Jason

Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 31st Jan 2009 05:42
Ick! I understand what smart pointers do but I've never been able to wrap my mind around the concept. To some extent I think I see this concept in C# using the object class as a base but haven't really had to do anything with it yet.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 31st Jan 2009 15:23
@jason,
My advice was to Plystire, and was of the 'beginner' variety.

However, despite that, it's how the majority of my own code is written - if it's something that can be done without any explicit memory allocation, I do it that way simply because (with a little care) it's generally no slower, but is many times safer.

That said, I'm also not afraid to get down and dirty with pointers and multi indirections of pointers, and I'll do so when needed, but even then I'll generally wrap it all up in a class to ensure I use it correctly and don't make any mistakes with it. And as I said, done the right way, it will have no impact on performance.

jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 31st Jan 2009 18:46
I know - was feeling punchy - thats all Plystire has actually come a long ways since he's been coming here from what I've read anyways - I think when he gets these possible mem leak issues straightened out - we will start to see some very cool things from him!

Plystire
21
Years of Service
User Offline
Joined: 18th Feb 2003
Location: Staring into the digital ether
Posted: 31st Jan 2009 19:55
Thanks, jason, not sure I want to jump into using smart pointers if at all avoidable, though.


Good news is... it's not a memory leak. Leaving the task manager open to view how much memory my program uses shows that even in a stessful point of gameplay, when the framerate hits the floor, memory used for the game remains around 24.5MB
(Phew, glad it wasn't that)


I am, however, unsure of whether or not my code is calling an array out of bounds and causing these weird things to happen. I've looked over all of my code dealing with the arrays, and no where do I spot a possible out of bounds issue (But many have eluded my gaze before )

If I do convert my structs into classes, would this in any way help prevent out of bound calls?


The one and only,


jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 31st Jan 2009 20:16
Quote: "
If I do convert my structs into classes, would this in any way help prevent out of bound calls?
"


Unlikely. Technically, STRUCTS are CLASSES and CLASSES are STRUCTS! Seriously! There will always be a few who Say NOT-Aahh, no way dude... but its true. A Class is a Structure a structure is a class - in CPP - they are made of the same proverbial cloth.

With a class you can override and inherit the constructor/destructors... and I forget if protection and functions are both supported - in short though - It won't help you... especially if you're having overrun issues - each time you modify a line of code and compile the app the "problem symptom" can change... one minute you have tweaked images - the next GPF/HALTs... or sprites are odd... who knows.

Welcome to the coding doldrums - these kind of errors take meticulous analysis of your code and often debugging measures like log files and messages on screen to alert you to symptoms or potential problems - and a skilled eye to understand what weird stuff might mean - hang in there!
--Jason

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 31st Jan 2009 20:56
IIRC, the only differences between structs and classes is that a classes members are private by default and they inherit privately by default, and a structs members are public by default and they inherit publicly by default - in both cases the access can be modified by using the access modifiers (public, protected, private).

@Plystire,
Not only should you check for overruns, but also check for dangling pointers - pointers that point to memory that was valid at one point, but that you later freed.

That's one of the places that smart pointers can help you - the shared_ptr will keep the memory allocated until all pointers that point to it are gone.

Note that simply zeroing out the pointer when you free its memory is not the same thing at all, but it may help a little.

Plystire
21
Years of Service
User Offline
Joined: 18th Feb 2003
Location: Staring into the digital ether
Posted: 31st Jan 2009 21:08
I guess now would be a good time to mention that I have no pointers at all in my program. I haven't yet found a point to use them.

I also don't deallocate memory mid-program either.
That's why I think one of the arrays is being called out of bounds somewhere, I can't think of it to be anyhing else.... unless there's a bug in DGDK that I happened to find, which is unlikely.


The one and only,


prasoc
15
Years of Service
User Offline
Joined: 8th Oct 2008
Location:
Posted: 1st Feb 2009 00:15
Setting a variable to minus 32 bit integer (like -214768....) will mess up alot of your variables for some reason even if they have nothing to do with it.
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 1st Feb 2009 00:21
could you elaborate prasoc?

I ask for more detail because one thing is certain. If you have a 32 bit integer and set it beyond the range that a 32 bit integer can do for a negative value, then it literally rolls to a positive number whose value is the difference you typically overshot less one. (I could be off here and its one more versus less).

This however should not interfere with other variables, infact - this rule of "staying in your space" ... like forcing a rollever this way (not so much) but for unsigned integers (no sign, all positive) is often useful for various things ... but you have to include the "ROLLOVER" in your plans natually.

Unexpected varible value flips CAN cause a ton of unsuspecting code to cascade problems all over - but its not the actual rtoll over that causes the problem - its the code not expecting such a crazy disparity to occur.

--Jason

prasoc
15
Years of Service
User Offline
Joined: 8th Oct 2008
Location:
Posted: 1st Feb 2009 01:01 Edited at: 1st Feb 2009 01:01
I had a variable once (I think it was the "tracer" for where bullets go), and it went too far and as soon as it hit a −2,147,483,648 it then moved my character around a bit, which it had nothing to do with the tracer position or anything, and the game locked up
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 1st Feb 2009 02:31
Thanx for the reply.

That is weird. hmm..thinking... nothing comes to mind on what might of caused that under the hood... hmm...

Login to post a reply

Server time is: 2024-09-30 17:20:50
Your offset time is: 2024-09-30 17:20:50