Vulcan Posted July 31, 2014 Share Posted July 31, 2014 I ran into a problem with loading map as I use a state machine to switch in and out between main menu and game level. First I didn't notice that the map wasn't unloaded as I thought it was unloaded when that state exited. But when I try to go back second time from menu it crashes and debugger points at Map::Load(..). But how do I unload the map (when unloading state) so it could load another map later? I have tryied with world->Clear() and world->Release() but without luck. How can I overcome this problem? Quote Link to comment Share on other sites More sharing options...
Rick Posted July 31, 2014 Share Posted July 31, 2014 Can we see some sections of code? I'm pretty sure you should be able to call Map::Load() any number of times. If it's failing maybe what you are passing it is invalid? Are you passing it a variable? Is that variable correctly set within your states when you go back into it? Quote Link to comment Share on other sites More sharing options...
Vulcan Posted August 1, 2014 Author Share Posted August 1, 2014 I have a created a sample project to replicate the error at Map::Load(). I noticed that different map files gave different results so I decided to include two map files (one that works and one that don't). Also noted that the skybox wasn't showing on one of them. Look in Game.cpp at Game::Start() where Map::Load error occurs. If someone spots something bad/odd/weird code I would like to know so I could improve my code. I have uploaded it here (look at the top of page to get download link): http://speedy.sh/bCaPE/CrashMapLoad.zip Quote Link to comment Share on other sites More sharing options...
Vulcan Posted August 1, 2014 Author Share Posted August 1, 2014 After peppering the code to figure what it does I realized that Game::Exit() never was called. I did fix that but now I got an error after using _world->Clear() and then crashes on next _camera statement (when starting the map second time). _camera->Move(strafe, 0, move); EDIT: How can I reset camera? Quote Link to comment Share on other sites More sharing options...
Rick Posted August 1, 2014 Share Posted August 1, 2014 Is _camera valid? Cameras are entities that are in the world so clearing the world should clear the camera so make sure after you clear the world and load the map that either the map has a camera in it and you get it and assign it to _camera, or recreate your _camera variable after clearing the world. Quote Link to comment Share on other sites More sharing options...
Vulcan Posted August 1, 2014 Author Share Posted August 1, 2014 Duuuhh!! I forgot to assign camera, now it runs the map normally. Thanks Rick. Map::Load("Maps/level2.map"); _camera = Camera::Create(); _camera->Move(0, 2, -5); 1 Quote 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.