So I have been working on this game for a few months now, and it is an hybrid c++/blueprint project; I usually code the core stuff in c++ and pass it up to blueprint for graphic rendering and player interaction.
Recently I wrote the following C++ function as part of one of my classes (it says interface but it is actually not an interface, there is no pure virtual function in there) :
void AC_CivManagerInterface::PlaceNewCity(int32 position) {
CityDistricts[position]=playerID;
GameManager->CityDistricts[position]=playerID;
GameManager->PrimaryHexArray[position]->hasCityDistrictFromCiv=playerID;
GameManager->PrimaryHexArray[position]->cityIDfromCiv=CivCityList.Num();
if (GameManager->hasPositiveTwin[position]) {
GameManager->PositiveTwinHexArray[position]->hasCityDistrictFromCiv=playerID;
GameManager->PositiveTwinHexArray[position]->cityIDfromCiv=CivCityList.Num();
}
if (GameManager->hasNegativeTwin[position]) {
GameManager->NegativeTwinHexArray[position]->hasCityDistrictFromCiv=playerID;
GameManager->NegativeTwinHexArray[position]->cityIDfromCiv=CivCityList.Num();
}
FString NewString = FString::FromInt(GameManager->PrimaryHexArray[position]->cityIDfromCiv);
if (GEngine) {
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("HELLO WORLD " + NewString));
}
// UpdateHexFeats(position, 0, Resources[position], EImprovement::VE_None);
}
Up to here no problem, it compiles fine. Then I try to place a function call node in a blueprint, and when I hit play, the game freezes (note that sometimes it takes a few tries before it starts freezing, but it invariably will start freezing after a few times, both on mac and PC) The editor just freezes, so there is no callstack as I have to close the editor thru task manager/force quit applications. If I disconnect the node and “refresh visual studio/xcode project” it starts working again… so I’m pretty sure the problem comes from this function, but I can’t seem to see why?? More weird stuff : the place where the function is called in the blueprint is not even part of the initialization sequence! It’s actually linked to an OnClicked event of a button widget which is created but not added to an horizontal box present at start. Also not that the problem seems to be worse on mac, where it won’t always get better when you disconnect the problematic node.
I’ve joined all relevant .h and .cpp files in the file. If you guys need something else let me know!
I’ve been stuck on this for 2 days now… HELP xD
Hi CerynCaribou,
Could you provide me with the rest of the code files in this project? It would help a lot to be able to actually recreate the project and run this through the compiler so that I can make the blueprint and reproduce the crash. First step of finding out the problem is reproducing it 
Of course. How do I go about sending you these? I would rather not just put them up on here for anyone to pick up. And I would probably need to send you the blueprints too I suppose, since they are quite intricated with the code (some stuff is initialized in blueprints, other in c++, etc.)
If you would like to, you could upload them to dropbox and send the link to me in a private message on the forums. My forum username is . It would be easiest if you could send the entire project. To cut down on size you could delete the Binary, Saved, and Intermediate folders if you’d like.
Just sent you a link!
Edit : I just noticed that in the version that I sent you, the problematic node is not there. The node in question is a “PlaceNewCity” node from the C_CivManagerInterface c++ class, and should be placed at the very end of the “Found City” blueprint function of the “GameManager” blueprint. The 2 reroute nodes which are just next to it are what I plug into the node.
What version of the editor is your project in? I see that it is 4.6 from your post, but it would help to have the exact version. I’ve attempted to reproduce the issue with the latest 4.8 Preview 3 but it won’t freeze for me. I also attempted to launch in 4.6.1 but it says the version is older and thus failed to load the map.
Edit: Disregard that, my mistake. Accidentally copied over the one that had been converted to 4.8 and tried to run it in 4.6, of course it didn’t work.
The version is indeed 4.6.1. Did you manage to reproduce the problem?
(some of the code shown earlier might be commented in the version I sent)
I was sure to check the code and I also placed the node. I can reproduce the issue in 4.6 but can’t in 4.7.6. It does still freeze for a good 3 or 4 seconds but then it displays the game. I would recommend updating to 4.7.6 if that would work for you. If you do take this route, be sure to do it with a copy and not the original, in case it causes any other problems. With it freezing like this instead of actually crashing, it makes it much more difficult to find out what the problem is exactly but it may be something that was fixed as of 4.7.6.
Edit: And of course as soon as I post this after trying to get it to freeze 10 times in 4.7.6, I hit play and 11th time is the charm. I’ll continue looking into what the issue could be.
Now I’m freezing upon hitting play 100% of the time, and this is without adding the PlaceNewCity node.
Yep… I got that too after a fashion. It looks like the node somehow corrupts the whole blueprint (or possibly the project) after running it a few times, and afterwards it doesn’t even matter if the node is there or not.
At least I see you did manage to reproduce the error. I was hoping there might be some kind of special log file that we might use to see where the crash happens, but I never found it =/
I think I narrowed down the issue to one function. I went into the Map Generator blueprint and placed a breakpoint on every function in the event graph, so that I could step through all of the functions. It seems like the PlaceResources function is causing the freeze. I see that there is quite a bit of code in that function. I’ll be looking through it, but I figured I’d give you the heads up since you already know what it does.
Looking at the function, it seems to go through multiple elements trying to set values to them based off random chance and what type of elements they are.
I would suggest attempting to debug by reducing the map size to a small amount, see if that lowers the delay that comes from hitting play. If so, slowly work your way back up until you get the editor to freeze again.
If this does happen at some point, the issue is most likely that the function itself is using too much memory.
Let me know if you make any progress, and I’ll do the same
So I’ve been tinkering a bit on my side too, and I think I might have solved the problem, although how it would do that is kinda beyond me.
After you said there might be a problem with PlaceResources, I followed the whole path the “resource” array takes and what gets initialized by it, and it turns out there was a line missing in AC_CivManagerInterface::InitializeCivManagerMapArrays() to initialize the local resource array. If you add
Resources=TArray(GameManager->Resources);
to this function and attempt to play in editor, everything seems to be working, even when pushing the “Found” button. It also seems to be working if you uncomment the
// UpdateHexFeats(position, 0, Resources[position], EImprovement::VE_None);
last part of the problematic node function.
I’ve been testing it for maybe half an hour now and it appears to work… but it still does not explain the freeze, since the InitializeCivManagerMapArrays function is actually called AFTER the PlaceResources function. Some part of it does make sense, in that the “Found” button is created after InitializeCivManagerMapArrays is called; is it possible that, at creation, widgets would do some preliminary checking of all their functions? (in this case, the button checking if its onClicked function works?) If it is the case, that seems like it might be an important limitation to widgets.
Anyways, I’ll let you know if I run into any more trouble on this side!
I’m glad to hear that you’ve found the issue and solved it. I’m not sure if widgets do anything like that, but if that were causing it, it would’ve stopped freezing for me when I disconnected the Found button’s functionality (I did it as another part of the debugging measure), which it didn’t. I’m also unsure of how that actually fixed it.
For now, I’ll be marking this issue as resolved. If you need anymore assistance however, please feel free to comment and the question will reopen.
Have a nice day,
And of course, after further testing, the problem came back, and I’m once again freezing 100% of the time.
So I tried your suggestion of downsizing the map to a more manageable size, and it does appear to help, but it doesn’t solve the problem, since I did get some freezes then too (using 2015 instead of 5535 in the GameOverseer blueprint; you’ll need to crank down the number of very long/long/medium/small chains in GenerateAltitudeMap to something like 0/0/2/10 and pull down the number of rivers to something like 5 if you want to test it).
I’m getting the feeling this memory idea has something to do with the problem, but I think there’s more; when I try to run this smaller map, it rarely freezes on a first run, but it tends to freeze after 6-7 runs (sometimes more/less, it’s hard to be precise in this case).
From all I’ve tested in the previous days, I also noticed that modifying some part of the code or a blueprint to force a recompilation tends to solve the freeze problem for a few runs, as if the recompilation somehow “cleaned” the project… might there be a link between the two? Some kind of cache memory getting filled that a recompilation would empty maybe?
Looking at what is happening, it doesn’t seem like this is an issue with the editor.
I attempted to do what you suggested, compiling after starting the simulation once. This let me notice something else that seems wrong. After compiling I was told of a blueprint compilation error in the GameManager blueprint, for the PositiveTwin and NegativeTwin sections’ ‘Update Tile Features’ nodes. It was showing those nodes having variable names plugged into them, which is something that is unexpected by the programming. This could have something to do with the issue.
Otherwise, after looking through your code, I would suggest making your map out of an array of custom classes, something like a Tile class. This could allow you to store all of the information about a tile inside of itself, avoid a lot of unnecessary calculations and save a lot of memory.
Past that, I would suggest reaching out to other members of the community through the forums who may of run into a similar problem before. I believe attempting to handle all of this map generation at BeginPlay in general could be the issue.
Regarding the compilation error, It seems I had forgotten to correct this in the version I gave you (this error comes from some cleanup I was performing in the code, changing int variables to enums), and after correcting it, I can assure this is not the problem.
As for creating the map with a custom class, I am already doing something like that with the class HexTile, but I need the data duplication in the GameManager and CivManagers for ulterior game features (such as the fact that all players won’t always have the same information for each tile)… so for now I’ll keep it as it is, although I guess I’ll take a deeper look into what really needs to be duplicated.
I really do think this has something to do with memory usage and possibly a memory leak somewhere. Using a smaller map does not get rid of the problem, but I guess it DOES make it kinda usable, since I get 6-7 runs before I have to restart the editor. I still believe this has something to do with the editor though, since the packaged project never freezes…
Anyways, I guess this is a good enough solution for me to keep on working. Thank you very much for your help, and let me know if you ever find anything that might be related!