smashthewindow Posted June 27, 2012 Share Posted June 27, 2012 In the attached file, there is a very simplified system of how I set up my entity system and abstraction. As you see, if you build the project I've provided and press 0 during in game, the game crashes at ResetFramework() (Whether in debug or release). Below is a small description of how I do things. Actor is a class that modifies an entity in some way. Bombs, traps, characters etc inherits from this class. CallbackRegistration class registers callbacks to the actors. For the base Actor class, FreeEntityCallbackRegistration is inherited as the Actor C++ object needs to be deleted when the entity is freed. Download & change VC dir & compile, and tell me what you think. I'm looking for some quick explanation on why the program crashes and some ways I could fix this. Thank you for all those who are trying to help me. EDIT: File attached. Forgot to press "Attach This File" button. (Why can't I attach 7z archive? Smaller size... ) Quote Blog & Portfolio Current project: moon.chase.star Link to comment Share on other sites More sharing options...
Rick Posted June 27, 2012 Share Posted June 27, 2012 This didn't crash for me. It worked fine when I pressed 0. 1 Quote Link to comment Share on other sites More sharing options...
smashthewindow Posted June 27, 2012 Author Share Posted June 27, 2012 That is very weird... I'll have to investigate further. Did you test on both debug and release? Quote Blog & Portfolio Current project: moon.chase.star Link to comment Share on other sites More sharing options...
Rick Posted June 27, 2012 Share Posted June 27, 2012 Both worked yeah Quote Link to comment Share on other sites More sharing options...
Benton Posted June 27, 2012 Share Posted June 27, 2012 Smash, maybe it's your computer... Quote Windows 7 Professional 64 bit, 16 gigs ram, 3.30GHz Quad Core, GeForce GTX 460 one gig, Leadwerks 2.5, Blender 2.62, Photoshop CS3, UU3D Link to comment Share on other sites More sharing options...
Roland Posted June 27, 2012 Share Posted June 27, 2012 No problem here either. No crash when I press 0, neither in Debug or Release mode. Sure you haven't some old LE DLL around somewhere that's loaded before the one in your directory Quote Roland Strålberg Website: https://rstralberg.com Link to comment Share on other sites More sharing options...
smashthewindow Posted June 27, 2012 Author Share Posted June 27, 2012 Ohh. Sorry guys, I made a small mistake in a line. In the main loop, if( LE::KeyHit( LE::KEY_0 ) ) { LE::FreeEntity( mesh ); //LE::ResetFramework(); } that should be if( LE::KeyHit( LE::KEY_0 ) ) { //LE::FreeEntity( mesh ); LE::ResetFramework(); } This throws an exception at LE::ResetFramework() when in debug mode. Could anyone check this again? This may seem trivial, but the crash tends to lead to more memory problems when I do stuff that are more complex in the game. Quote Blog & Portfolio Current project: moon.chase.star Link to comment Share on other sites More sharing options...
Rick Posted June 27, 2012 Share Posted June 27, 2012 Yeah, blew up for me. I've never used ResetFramework() but seems like it may have a bug to it. 1 Quote Link to comment Share on other sites More sharing options...
smashthewindow Posted June 27, 2012 Author Share Posted June 27, 2012 Yeah, blew up for me. I've never used ResetFramework() but seems like it may have a bug to it. So you keep track of all your LE::TEntity instances? Quote Blog & Portfolio Current project: moon.chase.star Link to comment Share on other sites More sharing options...
Road Kill Kenny Posted June 27, 2012 Share Posted June 27, 2012 Don't know about everyone else but I do keep track of all my LE::TEntity instances. Quote STS - Scarlet Thread Studios AKA: Engineer Ken Fact: Game Development is hard... very bloody hard.. If you are not prepared to accept that.. Please give up now! Link to comment Share on other sites More sharing options...
Rick Posted June 28, 2012 Share Posted June 28, 2012 I do in directly yeah. Like you when a scene is loaded TEntity variables are wrapped in my own classes (like your Actor) classes. Then I keep track of all Actors (or whatever else) and free those when a new scene is loaded. When they get freed they free the TEntity variable(s) that belong to the class. Quote Link to comment Share on other sites More sharing options...
smashthewindow Posted June 28, 2012 Author Share Posted June 28, 2012 I was looking for somewhat a semi-automatic way to manage memory utilizing the garbage collector but your method would be better if the ResetFramework is buggy. I hope there is better management in Le3D. Thanks for the replies. Quote Blog & Portfolio Current project: moon.chase.star Link to comment Share on other sites More sharing options...
Rick Posted June 28, 2012 Share Posted June 28, 2012 If you want to I think you could make a pivot and make it the parent to all entities you load. Then free the pivot and all other entities will be freed also, I think. Quote Link to comment Share on other sites More sharing options...
smashthewindow Posted June 28, 2012 Author Share Posted June 28, 2012 If you want to I think you could make a pivot and make it the parent to all entities you load. Then free the pivot and all other entities will be freed also, I think. That's what I've tried with the pivot returned from the LE::LoadScene command but that also causes memory problems (specifically a 1-byte memory shift if located under a debugger). I'm thinking that the garbage collection mechanism doesn't go well with C++, and is just better to free them myself. Quote Blog & Portfolio Current project: moon.chase.star Link to comment Share on other sites More sharing options...
Road Kill Kenny Posted June 28, 2012 Share Posted June 28, 2012 If you want to I think you could make a pivot and make it the parent to all entities you load. Then free the pivot and all other entities will be freed also, I think. It sounds like a bit of a dodgy work around to me. (sorry no offense) I think it's better if you just have a content factory class to keep tabs on all of your entities and free them and create them as needed. That way all the entities themselves are in one place and the other appropriate classes have access to the content factory. Quote STS - Scarlet Thread Studios AKA: Engineer Ken Fact: Game Development is hard... very bloody hard.. If you are not prepared to accept that.. Please give up now! Link to comment Share on other sites More sharing options...
smashthewindow Posted June 28, 2012 Author Share Posted June 28, 2012 It sounds like a bit of a dodgy work around to me. (sorry no offense) I think it's better if you just have a content factory class to keep tabs on all of your entities and free them and create them as needed. That way all the entities themselves are in one place and the other appropriate classes have access to the content factory. Yep, I've coded with templates for the fourth time now... Here's my factory . class ActorRegistrationBase { public: ActorRegistrationBase() { ActorFactory::getInstance()->registerBuilder(this); } virtual ~ActorRegistrationBase() { ActorFactory::getInstance()->deregisterBuilder(this); } virtual int getType() = 0; virtual Actor* createActor( LE::TEntity entity_ ) = 0; private: }; class ActorFactory : public Singleton< ActorFactory > { public: typedef std::map<int,ActorRegistrationBase*> Container; void registerBuilder(ActorRegistrationBase* item_) { items.insert(std::pair<int,ActorRegistrationBase*>(item_->getType(),item_)); } void deregisterBuilder(ActorRegistrationBase* item_) { Container::iterator iter_ = items.find(item_->getType()); items.erase( iter_ ); if(items.empty()) { destroyInstance(); } } Actor* createActor( LE::TEntity entity_, int actor_key_ = 0 ) { if( actor_key_ == 0 ) { actor_key_ = ctoi( LE::GetEntityKey(entity_,"actor_key","0" ) ); } Container::iterator iter_ = items.find( actor_key_ ); if( iter_ != items.end() ) { return iter_->second->createActor( entity_ ); } else { TRACE("ActorRegistrationBase for actor_key %i doesn't exists.", actor_key_ ); ASSERT(true); } } private: friend class Singleton<ActorFactory>; ActorFactory(void); ~ActorFactory(void); Container items; }; template<typename T> class ActorRegistration : public ActorRegistrationBase { public: ActorRegistration( int actor_key_ ) : ActorRegistrationBase(), key( actor_key_ ) { } virtual int getType() { return type; } virtual Actor* createActor( LE::TEntity entity_ ) { Actor* actor_ = new T( entity_ ); MemoryMgr::getInstance()->addActor( actor_ ); return actor_; } private: int key; }; Quote Blog & Portfolio Current project: moon.chase.star Link to comment Share on other sites More sharing options...
Road Kill Kenny Posted June 28, 2012 Share Posted June 28, 2012 Dang never realized how difficult it is to read code when there is no white spacing / tabing lol. I assume it copy pasted that way. Looks a lot different to my Content Factory but it looks fine to me. However, if you are loading from .sbx then I guess it makes it more difficult to register entities to the factory.. Unless you either make your own scene loader that parses the .sbx file (which is just a .txt file) and loads things as appropriate use databases.. hmm... just realised thats why mine seems so different... it's because my content factories have database functionality and handle the database reading and storing data as well. Makes sense now lol. Quote STS - Scarlet Thread Studios AKA: Engineer Ken Fact: Game Development is hard... very bloody hard.. If you are not prepared to accept that.. Please give up now! Link to comment Share on other sites More sharing options...
Rick Posted June 28, 2012 Share Posted June 28, 2012 It sounds like a bit of a dodgy work around to me. (sorry no offense) I think it's better if you just have a content factory class to keep tabs on all of your entities and free them and create them as needed. That way all the entities themselves are in one place and the other appropriate classes have access to the content factory. No offense taken as it was just 1 possible way to do it. It's actually the "default" way LE handles it in how the loading of the sandbox works. If you were to use LE's way of doing things you would use Sandbox, load your scene and keep every entity loaded the child of the scene pivot, and then use that pivot to free your scene. However you are correct in that most people won't go that route and will start loading their own stuff which isn't directly related to the sbx file, but it is one way to handle it. Quote Link to comment Share on other sites More sharing options...
smashthewindow Posted June 28, 2012 Author Share Posted June 28, 2012 (edited) Looks a lot different to my Content Factory but it looks fine to me. However, if you are loading from .sbx then I guess it makes it more difficult to register entities to the factory.. Unless you either make your own scene loader that parses the .sbx file (which is just a .txt file) and loads things as appropriate use databases.. ActorRegistration objects are created once globally at application initialization and it registers the appropriate constructor and the actor_type ID to the factory. I find this was a lot more easy to maintain than adding switch cases to call constructors. (I've actually got this idea from the book Game Engine Gems and Source Engine.) Edited June 29, 2012 by smashthewindow Quote Blog & Portfolio Current project: moon.chase.star Link to comment Share on other sites More sharing options...
Canardia Posted June 28, 2012 Share Posted June 28, 2012 Dang never realized how difficult it is to read code when there is no white spacing / tabing lol. I assume it copy pasted that way. Yeah, it's a bug in IP boards. I tested it also on their official support forum, and got the same bug with tabs getting stripped from code tags. They never even bothered to publish my test report, so I think their support is actually less than zero, like a negative number. I would hire someone to make a completely new board software with Apache+PHP+PostgreSQL, or maybe I should make one myself and sell it for free. Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.