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 / dbMakeObjectXXXX() not creating an object... Why?

Author
Message
WLGfx
16
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 2nd Dec 2010 21:54
Would some one be able to help me out here.

"objectclass.h"

I have changed the debug setting to /MT (not the default MTd). The program builds fine and runs. The dbMakeObjectxxx() commands are called with the correct variables but no object is created.

Help...

Warning! May contain Nuts!
WLGfx
16
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 3rd Dec 2010 03:14
I got it working in the end by removing the destructor ~myObj() from the class. I'm assuming the 'list' commands would call a destructor after creation was complete although my list stays intact. By using breakpoints and watch variables I found that the object was created but then deleted on returning from the constructor. So moving the temporary return value to the list would call the destructor. If anyone has any ideas of how to keep the destructor in place, please let me know.

Warning! May contain Nuts!
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 3rd Dec 2010 13:16
Try this:


You were creating objects that immediately went out of scope and therefore the destructor was called.

WLGfx
16
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 3rd Dec 2010 13:43
Hi Matty,
Thanks for the reply. Ideally I don't want to keep the object ID's in the main code that's why I built a class to hold the ID's (OO style). Basically to create and forget. The class constructor creates the object and stores its ID.Once the class has finished with the object it will delete it then delete the link in the list. But as you've said it goes out of scope. I am going to rewrite this piece of code to use a linked list of pointers instead because I'm pulling out my hair. I'm trying to set up a library of routines that will handle particles, object animation, movement, etc, without the use of manually setting up each one individually. I'll be building up the linked list using a base class and derivatives of various type of objects. ie. add a particle emitter and let the class update handle the rest by its self. I'll get there Matty... Thanks again...

Warning! May contain Nuts!
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 3rd Dec 2010 14:51 Edited at: 3rd Dec 2010 14:53
There are lots of different solutions to achieve what you are trying to do.
I understand that you want to create and forget, here is a possible solution that I have seen alot of times and it works well.

You do not create the objects(myObj) at all in your main code, whether inside the list push_back parameter or otherwise.
You have a class that oversees the handling(creation/deletion) of your objects, ObjFactory in this case.
Here is what it may look like in use:

The 'of' object handles the creation storage and deletion of your objects, when it creates the object it returns a pointer to the object should you need it, if not, then don't store the return value in a variable.

Thats just one possible design you might want to consider.

WLGfx
16
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 4th Dec 2010 00:33 Edited at: 4th Dec 2010 05:13
I've made a lot of headway...

Although I've not made a start yet on particle generation, nor even movement, it's looking okay. The creation of objects and setting up rotation, movement, etc. I'll transfer those into simpler setting up commands.

If there's a way of altering the code so that I don't have to use a temporary myObj inside the main code I'm sure I'll find it soon.

Is ObjFactory another library that's out there?



"objectclass.h"


"mycam.h"


Warning! May contain Nuts!
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 4th Dec 2010 11:15
Quote: "Is ObjFactory another library that's out there?"


No sorry, I was not very clear.
ObjFactory is a class you could write to handle all your objects, its job would be to do what you are now doing in main.cpp.


ObjFactory.h


main.cpp


This is how classes build on each other, if you find that what you are writing in main.cpp can be wrapped in a class then its usually a good idea to do just that, it also gets rid of your global lists.

Not saying you should do it like this, just clarifying what I meant

WLGfx
16
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 6th Dec 2010 00:17
I've now got a lot more working with it and now restarted my project. Now using multiple lists and auto handling of loading objects into the class lists. When I have something working I'll post it up so it might be of help to others... I'm planning on building it up into a WinAPI and GDK editor because recently I got the WinAPI stuff working.

Cheers mate...

Warning! May contain Nuts!
WLGfx
16
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 7th Dec 2010 02:17
Oh Matty, just clicked what you meant by ObjFactory. My re-write has just gone back to my original problem so I'm gonna try and wrap it up into another class as you've suggested.

Warning! May contain Nuts!

Login to post a reply

Server time is: 2024-09-28 14:12:21
Your offset time is: 2024-09-28 14:12:21