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 / Array of Bullets

Author
Message
Moops
14
Years of Service
User Offline
Joined: 19th Apr 2010
Location:
Posted: 25th May 2010 19:06
Hiya Guys, as suggested by you guys ive had a go at some object oriented programming, albeit early attempts. but ive come across a problem with my array of bullets.

It would appear that when ive come to the end of my bullet loop, when it gets reset back to 0 in the array, it all goes potty. i've tried everything to the best of my knowledge but im just not grasping it, perhaps I should just scrap it and start again. But I simple just do not want to give up.

My loop cycle




My createProjectile from an instance of my projectile class


Ive also attach the full VC++ project, when run, you will see a counter top left which indicates the amount of bullets shot, when this reaches 100 it resets and this is when I get the problems

Any help would be appreciated as this is driving me crazy.

PS 5th week into C++ so please bare this in mind when examining the code.

Attachments

Login to view attachments
Matty H
16
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 25th May 2010 20:56 Edited at: 25th May 2010 21:01
Sorry moops, I'm getting an unhandled exception in your Cenemy constructor:



If I comment that out then I get a similar exception in the projectiles constructor and so on.

I can't find the part of the program that creates these objects with calls to these constructors, where is it?

Why does your CgameEngine class have Clevel and Cplayer class variables, but then in CgameEngine::startEngine() you do this:

Declaring them again, when you keep class variables they need to be initialised, not re-declared. So the above code should be:

Unless I'm missing something, anyway I can run the program up to the above code then I start getting the exceptions.


EDIT: By the way, the exception does not happen the first time the constructor is called, or the second, or the third lol. But it does eventually, thats why I was trying to find where it was being called.

Moops
14
Years of Service
User Offline
Joined: 19th Apr 2010
Location:
Posted: 25th May 2010 22:06
Hiya Matty, first of all, many thanks for even taking the time to open that project and help. It is appreciated!!!

I've just cleaned the build and removed those legacy class variables you talked about, that's just old legacy code as ive been playing around trying to get stuff to work.

I don't seem to get any except handles, could you try again with this clean build?

Attachments

Login to view attachments
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 25th May 2010 22:22
I haven't looked at the code yet but from my viewpoint, the exceptions could be coming from running out of IDs when creating the objects. I see the creation calls but no delete commands...

Are they in there somewhere I've not seen yet?

JTK
Moops
14
Years of Service
User Offline
Joined: 19th Apr 2010
Location:
Posted: 25th May 2010 22:28
Hey JTK, under my level I have a small method


this basicaly is my collision detection and for now all it's doing is deleting the objects.

it calls a method from each class.
projectile method



Enemy method


JTK, many thanks for taking the time to respond, it is appreciated.

Cheers Moops
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 26th May 2010 02:24
I'm looking at it now, but let me just say that you've come a long way with this... looks good! Give me a few to see how I can help you along, ok? I'm not sure why you're having this issue - from what I can see (playing/perusing) it shouldn't be happening; however, there's apparently something going on *somewhere* else that would be causing these issues... I'll get back to you soon with my findings!

Nice Work!


JTK
Moops
14
Years of Service
User Offline
Joined: 19th Apr 2010
Location:
Posted: 26th May 2010 10:43
Many thanks JTK,

It's a massive learning curve but one of which I am really enjoying. Having been a massive gaming fan, since way back in the 80's (cough age cough) learning C++ is like one massive RPG in it's self

I have literally spent hours upon hours trying to fix the problem to the point ive had to come seeking help, it's not my normal way but sometimes, you just have to accept your limits.

many thanks guys, eager Moops awaits.
Matty H
16
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 26th May 2010 12:49 Edited at: 26th May 2010 12:50
Sorry moops, I get this windows message:

Quote: "Microsoft Visual Studio C Runtime Library has detected a fatal error in shooter.exe.

Press Break to debug the program or Continue to terminate the program."


This happens here:

And anywhere you use dbText, I commented them out and it ran for me but it hung up on me when I kept it running for a while. I am on my laptop at the moment so I will need to check your new version on my desktop to be sure the other issue I was having has gone away.

Something I noticed which is a bit strange, you are creating lots of objects in your constructors which all have the same ID number:


This gets called lots of times and all the sphere objects are given an ID of 4000, this can't be right. I think you do this in other classes also, I can see this causing you issues if the objects are not getting deleted before a new one with same ID is created.

Moops
14
Years of Service
User Offline
Joined: 19th Apr 2010
Location:
Posted: 26th May 2010 13:11
Hey Matty,

rather odd it's hanging, although the hanging may be connected, did you actually see the problem I'm having with the bullet array when it reaches the end of it's loop?

Don't worry about the createdObject in the constructor it doesn't seem to harm the code, GDK just ignores this. However it was place their for testing purposes and can be removed from both the projectile and enemy constructors without any effect to the code.

it was me just trying things to see if I could fix my problem.

spent all morning on it as well and can I hellers fix the bullet code,something is rather odd, the enemy code is almost identical to the projectile code, yet the enemy array loop seems to go around just fine and continues to spawn enemies after 100.

i'll keep on trying.
Matty H
16
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 26th May 2010 13:45
I noticed that the bullets don't work for a while, then they come back sometimes. I still can't exit the program, does escape work for you, or the red X?

I will try to take another look if I get some time.

Moops
14
Years of Service
User Offline
Joined: 19th Apr 2010
Location:
Posted: 26th May 2010 14:45
hey Matty,

Q = Quit

and the problem you are experiencing is what I need help on, it should start to get messed up when the number of bullets = 100 and the loop starts again.

cheers Moops
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 27th May 2010 05:14
Well Moops, I've been looking and still haven't found the source of your dilema. I have been looking for a couple hours now. But don't fret, I'll look some more tomorrow night (about this time) and will get back to you on my findings...

My suggestion for the time being - move on to the next feature - if you can (please stay away from the projectiles though since that appears to be where the problem lies - lol)...

JTK
Moops
14
Years of Service
User Offline
Joined: 19th Apr 2010
Location:
Posted: 27th May 2010 11:02 Edited at: 27th May 2010 11:02
Thanks JTK,

I took your advice and moved onto the level bonus section and a small skeletal score/lives section.

by doing this I may have resolved the problem, I say may because it still doesn't feel right.

just before


I added


since the while loop was counting up looking for a free objectID it was never resetting back to "PROJECTILEOBJECTS" the start of the bullet ID's.

This may have been the problem.

for now JTK, leave the code alone, im sure you have better things to do with your time, what you and matty have done is above and beyond what I asked for and it's appreciated.

I plod on for now and I am sure im going need your help in the future, this I can guarantee

Cheers

Guys

Moops
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 27th May 2010 15:48
That doesn't work (was first thing I tried). Also tried moving th make object/particle to constructor; delete object/particle to destructor and replacing with show/hide. This should be done anyway for memory reasons... But alas, no go!

My experience with a bug like this is that its something simple... A misplaced comma, semi colon or some such... Not a syntax error but an error that makes the code take an unexpected code path...

Look for (for example) a comma in a for...loop expression, a semi colon immediately after a while loop such as while(exp);

My guess is that its something like that that's causing the problem...

Good luck, let us know your findings...


JTK
Matty H
16
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 27th May 2010 17:19
Quote: "Sorry moops, I get this windows message:


Quote: "Microsoft Visual Studio C Runtime Library has detected a fatal error in shooter.exe.

Press Break to debug the program or Continue to terminate the program."

This happens here:

dbText (10,120,dbStr (CurrentBullet));

And anywhere you use dbText, I commented them out and it ran for me but it hung up on me when I kept it running for a while. I am on my laptop at the moment so I will need to check your new version on my desktop to be sure the other issue I was having has gone away."


I tried the newer version on my desktop and had same issue as above(from my laptop), are you guys not getting these errors?

Commented them out and it ran, I could move around, things coming in toward me and vanishing, as they should. I pressed left mouse button and kaboom, my computer shut down.
I got a blue screen telling me that windows had to close to stop my computer getting corrupted. I have never had this happen and I'm guessing its a memory issue as my laptop never done this.

From my position, I would have to disagree with JTK and say that something is very wrong with your code, you may be getting strange results with your projectiles and it may seem trivial but I would say my desktop computer is showing this up to be something serious.

The fact that both of my computers wont let you use the dbText() or more likely the dbStr() command is also alarming as I have never seen this error before.

Sorry to be the bringer of bad news all the time but I would maybe have a re-think if I was you and maybe start again.
I'll give you my opinion of where I think you may be able to improve.


Design and make your classes so they are as independent and self contained as possible, you are having an issue with creating and deleting projectiles, perhaps have a projectile class which has less responsibilities. As it stands now, the projectiles are responsible for their own ID numbers and even keeping track of how many there should be(maxProjectiles), they also deal with collision which means they need to know about other objects.

What do projectiles really need to do as a bare minimum:
start() // make/create etc
update() // just keep going in your current direction at your current speed
stop() // die/destroy etc maybe send a message to create an explosion(not projectiles problem after it sends the message)

It may need a tracking system:
setDirection(x, y, z)

This new projectile class does not care how many projectiles exist or are allowed to exist because its not its problem, it also does not care who its following, it just gets the instruction to go in a certain direction. This can all be tested without other classes being involved.


How does this help, you then create a small projectile handler/manager class that may have a responsiblity to make sure only so many projectiles exist at any one time, it will create them, update them and when they get destroyed it will sort your array out for you.
Lets say this only has three functions: makeProjectile(), updateProjectile(), destroyProjectile().
You can then test the making and the destroying of projectiles from your main.cpp without other classes being involved.

I have gone on a bit there but I just wanted to illustrate the point that smaller self contained classes that can be tested easily, what you have now is really impressive but you may gradually see that giving each class a small, well defined set of responsiblities will make your life easier. The challenge then is designing your classes and how they will interact, this is chalenging but can be rewarding.

The real irony is that most of the time you don't know what classes you need until you have done it wrong a few times, I go through many iterations when programming anything, as long as the next one is an improvement on the last then you know you are going in the right direction, good luck.

JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 27th May 2010 19:41
Quote: "are you guys not getting these error?"


No I'm not...

What you're suggesting are points that I was gonna bring up - with class structure / responsibilities...

One point in particular that I was going to bring up was about the dbStr() function calls... The way you're using it now, Moops, is causing some serious memory leaks... Search the forums for dbStr to gain some insight into other alternatives... Maybe those leaks are causing the problems.

JTK
Moops
14
Years of Service
User Offline
Joined: 19th Apr 2010
Location:
Posted: 28th May 2010 11:58 Edited at: 28th May 2010 12:34
Quote: ""are you guys not getting these error?""


Nope not getting this error at all, however both of you seem to be pointing towards dbStr, ill look at a better way of displaying the info I need.

Cheers guys.

I've attached the latest Exe compiled with the extra code I created yesterday whilst trying to resolve the projectile routine, whatever I did seems to have fixed my problem and maybe just maybe that extra ; may have been deleted somewhere along the process.

Attachments

Login to view attachments
Moops
14
Years of Service
User Offline
Joined: 19th Apr 2010
Location:
Posted: 28th May 2010 12:30
Hey guys, ive found this solution for a replacement to the way in which I was using dbStr$

char sco [ 20 ];
sprintf_s( sco, 20, "Your Score: %d", score);
dbText (300,0,sco);

I saw method being used used for displaying the FPS, ive implemented this and it's working fine.

cheers guys.

Login to post a reply

Server time is: 2024-11-19 23:06:36
Your offset time is: 2024-11-19 23:06:36