Main Menu

CRPL Map Won't Load

Started by Argonwolf, November 15, 2018, 01:49:18 PM

Previous topic - Next topic

Argonwolf

I have a map with quite a lot of scripted objects in it that I took a break from, and recently have come back to discover the map won't load. When the loading bar screen appears, it never fills. Has anyone else had this issue? Is there any log I can look at that might show me what's going on? I'm just really confused and don't want to rebuild the map in another save file, especially since it's super time consuming to import the nearly 100 images and it might just break again.

Builder17

Log file locations are here: https://knucklecracker.com/forums/index.php?topic=16476.0

If you want, try placing save file to new project and then move scripts to see if it fixes anything?

Argonwolf

Here's the log file, I didn't see anything unusual, but maybe someone more experienced will notice something gone amiss. I also tried what you suggested, I duplicated the entire save file and emptied the scripts folder, they just reappear whenever I start the game.


Karsten75

Upload the save file to a thread in support. I'll ask Virgil to take a look at it, but what with the time, it may be a few days or even > a week

Argonwolf

The attached map file has a significant amount of CRPL code in it, and for some reason when I try to play it the game stays on the loading screen, with the load bar never filling up. The log file, which I posted in the coder corner, didn't seem to show any issues, so they told me to post the save game here. Any help is much appreciated, as I don't personally know what to do from this point.

Karsten75

This is what causes your load to hang:

Unloading 1 Unused Serialized files (Serialized files now loaded: 0)
NullReferenceException: Object reference not set to an instance of an object
  at TerrainImageMaker+<GenerateImage>c__Iterator26.MoveNext () [0x00000] in <filename unknown>:0
UnityEngine.MonoBehaviour:StartCoroutine_Auto(IEnumerator)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
Terrain:RenderTerrain(Int32, Int32, Int32, Boolean, Boolean)
Terrain:RenderTerrain(Int32, Int32, Int32, Boolean)
Terrain:CreatePad(Int32, Int32)
CRPLTowerManager:DestroyUnit(Boolean, Single, Boolean)
CrplCore:DestroyUnit(UnitManager, Int32)
CrplCore:DestroyUnit(Int32, Int32)
CrplCore:ProcessCommands(Boolean, Boolean, Boolean, Boolean)
CrplCore:PreGameUpdate()
UnitManager:Start()
CRPLTowerManager:Start()

(Filename:  Line: -1)


Why is another question. 

Maybe you can find a clue in the last few lines:

Unfortunately right now neither Virgil nor I can dig any deeper into this and it may be a week or more before that changes. :(


Argonwolf

#6
Quote from: Karsten75 on November 15, 2018, 07:25:53 PM
This is what causes your load to hang:

Unloading 1 Unused Serialized files (Serialized files now loaded: 0)
NullReferenceException: Object reference not set to an instance of an object
  at TerrainImageMaker+<GenerateImage>c__Iterator26.MoveNext () [0x00000] in <filename unknown>:0
UnityEngine.MonoBehaviour:StartCoroutine_Auto(IEnumerator)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
Terrain:RenderTerrain(Int32, Int32, Int32, Boolean, Boolean)
Terrain:RenderTerrain(Int32, Int32, Int32, Boolean)
Terrain:CreatePad(Int32, Int32)
CRPLTowerManager:DestroyUnit(Boolean, Single, Boolean)
CrplCore:DestroyUnit(UnitManager, Int32)
CrplCore:DestroyUnit(Int32, Int32)
CrplCore:ProcessCommands(Boolean, Boolean, Boolean, Boolean)
CrplCore:PreGameUpdate()
UnitManager:Start()
CRPLTowerManager:Start()

(Filename:  Line: -1)


Why is another question. 

Maybe you can find a clue in the last few lines:

Unfortunately right now neither Virgil nor I can dig any deeper into this and it may be a week or more before that changes. :(





So the exception occurs when a unit is destroyed, and the terrain, while attempting to redraw itself, encounters a problem. I don't know what CreatePad is, maybe it's the code that flattens terrain automatically under a destroyed Creeper-aligned unit so the power zone can be used? I wouldn't think destroying a CRPL Core that isn't currently on the terrain itself should produce much of an issue, I've been doing it hundreds of times with no problem. Very confusing indeed, I guess I'll just have to wait until either someone more familiar with the code can help me, because I don't want to rebuild my map not knowing the problem and cause it again (I have all my scripts safe and backed up, but it takes ages to get those images in).

Edit: Luckily, frequent backups have saved me, and putting the new code in only required 3 images to be replaced. New copy hasn't broken down yet, but still looking for reasons/fixes if anyone has experienced similar things.

Karsten75

Try hitting up Grabz in the Discord. He encountered a number of CRPL related issues. You may also want to look through this forum, since I believe he logged some of them.

Grabz

#8
Quote from: Argonwolf on November 15, 2018, 09:01:39 PM
Edit: Luckily, frequent backups have saved me, and putting the new code in only required 3 images to be replaced. New copy hasn't broken down yet, but still looking for reasons/fixes if anyone has experienced similar things.
The error you've run into was caused because you modified terrain through SetTerrain inside the Awake function. This is a fatal operation which causes the game to hang on load. To fix this, you simply want to change all of your scripts such that they no longer call SetTerrain inside Awake, and the map should load again.

Awake is a function that is called when an object is created, and each time the game is loaded, including loading from a save file. If you need to modify terrain each time the game loads, you can use GameLoaded. If you want to modify terrain when a unit spawns through said unit's script, you should do it in an once/endonce block.

___

EDIT: Cornucanis and I have done some digging through your scripts (I did not notice you attached a save file) and we found the exact problem causing your crash. The main cause of your error is that your CONTROLPANE.crpl script does not set CONST_CREATEPZ to FALSE. The unfortunate side-effect of this cascades down through your script.

At UISTUFF.crpl line 810 you destroy your ControlPaneUID and rebuild it. The problem is that your ControlPaneUID spawns a PZ. This triggers CreatePad, which flattens the terrain around the unit in order to ensure you can place a unit on the newly created power zone. Because all of this happens in Awake, the game crashes as it tries to modify terrain. The fix here is to ensure anything you destroy in Awake does not spawn a Power Zone.

You have to be more careful about the settings of your UI elements. A good practice is to drop this line of code into any script that is meant to be attached to a "ghost" CRPL Core, i.e. a Core that acts as a manager and does not partake in gameplay:


:awake
   Self CONST_TAKEMAPSPACE         FALSE SetUnitAttribute
   Self CONST_CREATEPZ             FALSE SetUnitAttribute
   Self CONST_SUPPORTSDIGITALIS    FALSE SetUnitAttribute
   Self CONST_COUNTSFORVICTORY     FALSE SetUnitAttribute
   Self CONST_NULLIFIERDAMAGES     FALSE SetUnitAttribute
   Self CONST_DESTROYMODE 0 SetUnitAttribute
   
   Self CONST_COORDX -2 SetUnitAttribute
   Self CONST_COORDY -2 SetUnitAttribute

   Self "main" "NONE" SetImage

Image and position changes are optional, and the rest you should change as you see fit. This is the baseline for disabling all of the default CRPL Core toggles.

___
EDIT2: This is an awesome map BTW. Some really nice work all around. You should definitely hit us up on Discord at https://discord.gg/knucklecracker, we're happy to assist you live with any errors you might encounter.

cornucanis

Quote from: Grabz on November 16, 2018, 04:52:14 AM
EDIT: Cornucanis and I have done some digging through your scripts (I did not notice you attached a save file) and we found the exact problem causing your crash. The main cause of your error is that your CONTROLPANE.crpl script does not set CONST_CREATEPZ to FALSE. The unfortunate side-effect of this cascades down through your script.

I can confirm that the map loads with this issue being fixed, and I just wanted to add that your UI and the effects on your custom units are absolutely amazing! I really hope you end up making maps with these scripts! And we'd really love to have you in the Discord too, we discuss various CRPL related things in there pretty often.

Argonwolf

Quote from: Grabz on November 16, 2018, 04:52:14 AM
Quote from: Argonwolf on November 15, 2018, 09:01:39 PM
Edit: Luckily, frequent backups have saved me, and putting the new code in only required 3 images to be replaced. New copy hasn't broken down yet, but still looking for reasons/fixes if anyone has experienced similar things.
The error you've run into was caused because you modified terrain through SetTerrain inside the Awake function. This is a fatal operation which causes the game to hang on load. To fix this, you simply want to change all of your scripts such that they no longer call SetTerrain inside Awake, and the map should load again.

Awake is a function that is called when an object is created, and each time the game is loaded, including loading from a save file. If you need to modify terrain each time the game loads, you can use GameLoaded. If you want to modify terrain when a unit spawns through said unit's script, you should do it in an once/endonce block.

___

EDIT: Cornucanis and I have done some digging through your scripts (I did not notice you attached a save file) and we found the exact problem causing your crash. The main cause of your error is that your CONTROLPANE.crpl script does not set CONST_CREATEPZ to FALSE. The unfortunate side-effect of this cascades down through your script.

At UISTUFF.crpl line 810 you destroy your ControlPaneUID and rebuild it. The problem is that your ControlPaneUID spawns a PZ. This triggers CreatePad, which flattens the terrain around the unit in order to ensure you can place a unit on the newly created power zone. Because all of this happens in Awake, the game crashes as it tries to modify terrain. The fix here is to ensure anything you destroy in Awake does not spawn a Power Zone.

You have to be more careful about the settings of your UI elements. A good practice is to drop this line of code into any script that is meant to be attached to a "ghost" CRPL Core, i.e. a Core that acts as a manager and does not partake in gameplay:


:awake
   Self CONST_TAKEMAPSPACE         FALSE SetUnitAttribute
   Self CONST_CREATEPZ             FALSE SetUnitAttribute
   Self CONST_SUPPORTSDIGITALIS    FALSE SetUnitAttribute
   Self CONST_COUNTSFORVICTORY     FALSE SetUnitAttribute
   Self CONST_NULLIFIERDAMAGES     FALSE SetUnitAttribute
   Self CONST_DESTROYMODE 0 SetUnitAttribute
   
   Self CONST_COORDX -2 SetUnitAttribute
   Self CONST_COORDY -2 SetUnitAttribute

   Self "main" "NONE" SetImage

Image and position changes are optional, and the rest you should change as you see fit. This is the baseline for disabling all of the default CRPL Core toggles.

___
EDIT2: This is an awesome map BTW. Some really nice work all around. You should definitely hit us up on Discord at https://discord.gg/knucklecracker, we're happy to assist you live with any errors you might encounter.


Quote from: cornucanis on November 16, 2018, 05:34:29 AM
Quote from: Grabz on November 16, 2018, 04:52:14 AM
EDIT: Cornucanis and I have done some digging through your scripts (I did not notice you attached a save file) and we found the exact problem causing your crash. The main cause of your error is that your CONTROLPANE.crpl script does not set CONST_CREATEPZ to FALSE. The unfortunate side-effect of this cascades down through your script.

I can confirm that the map loads with this issue being fixed, and I just wanted to add that your UI and the effects on your custom units are absolutely amazing! I really hope you end up making maps with these scripts! And we'd really love to have you in the Discord too, we discuss various CRPL related things in there pretty often.



Ah, that bloody Control Pane! The little devil's caused me some headache before, since I intended it to be created and destroyed every time the UI is activated/deactivated, so I didn't consider giving it the attribute business. Which is funny, because even on objects that may not explicitly need it, I try to define attributes on account of that weird attribute inheritance quirk.

Thank you, THANK YOU for finding that, I would seriously have no idea it was that which would have caused an exception (I still don't know why, but at least I know how). I'm going to keep that Discord in mind as well, for future major issues (fingers crossed there won't be many).

And lastly thank you for your kind words! I really wanted to make a custom map that felt as close to an expansion pack as possible, which is why I went with replicating the existing UI as much as possible (lots of print screen and Paint.NET pixel by pixel editing), and the words on the buttons came from creating dummy maps with those words as titles, then copying from the top of the screen. However, all imported images were hand-drawn with the intent of imitating CW3's art style as much as possible.

Once I have 8 structures, 8 weapons, 3 titans and 4 custom orbital weapons, I'll move on to a load of custom creeper units, then I intend to both create a short story campaign to introduce them gradually and simultaneously release a simple map creation kit because, if I'm being honest, I'm a terrible map maker. Working title for the mod is Keeper of the Arc, and I'm surprised I got as far as I did as fast as I did, so fingers crossed it'll see fruition soon. If I ever stall out too hard and don't reckon I'll be able to finish it all, I'll package what's already done for people to play with/salvage for their own maps.

Thank you again for the help, I'm not super experienced in CRPL and it's nice to get help from people who've charted some of these issues already.

cornucanis

Quote from: Argonwolf on November 16, 2018, 04:50:34 PM
I would seriously have no idea it was that which would have caused an exception (I still don't know why, but at least I know how)

Take this with a grain of salt since this is just our educated guess based on the error log and knowledge from working with Unity/C#, but it seems like the issue boils down to CRPLTowerManager coming before TerrainImageMaker in the script execution order. This seems like reasonable behavior for most situations, since you want your terrain image to update after the CRPL cores perform their actions.

The problem arises when the Awake() methods are called. Since the Awake() method for CRPLTowerManager is called first, the TerrainImageMaker hasn't had a chance to initialize the terrain image list (or dictionary, or array, or whatever it's needing to initialize with these references to images) when your CRPL cores perform their awake functions. Thus anything that causes changes to the terrain during a CRPL core's awake function will then try to call a method on TerrainImageMaker to update the map terrain image in response to the new terrain change. But since TerrainImageMaker has not yet called its Awake() method the references are not yet initialized.

Again, this is just an educated guess but that's what seems to be happening if you trace the exception backwards.

Quote from: Argonwolf on November 16, 2018, 04:50:34 PM
And lastly thank you for your kind words! I really wanted to make a custom map that felt as close to an expansion pack as possible, which is why I went with replicating the existing UI as much as possible (lots of print screen and Paint.NET pixel by pixel editing), and the words on the buttons came from creating dummy maps with those words as titles, then copying from the top of the screen. However, all imported images were hand-drawn with the intent of imitating CW3's art style as much as possible.

Once I have 8 structures, 8 weapons, 3 titans and 4 custom orbital weapons, I'll move on to a load of custom creeper units, then I intend to both create a short story campaign to introduce them gradually and simultaneously release a simple map creation kit because, if I'm being honest, I'm a terrible map maker. Working title for the mod is Keeper of the Arc, and I'm surprised I got as far as I did as fast as I did, so fingers crossed it'll see fruition soon. If I ever stall out too hard and don't reckon I'll be able to finish it all, I'll package what's already done for people to play with/salvage for their own maps.

This amount of effort is just incredible for something not even shown in a public prototype yet, huge props to you for this sort of commitment. I hope we haven't blown the lid off of it too much by mentioning it in this thread, but I don't think a lot of people check random support threads  ;)

I honestly can't wait to try some maps made with this expansion, it seems very well executed from what we've seen so far.

Quote from: Argonwolf on November 16, 2018, 04:50:34 PM
I'm going to keep that Discord in mind as well, for future major issues (fingers crossed there won't be many).

You really should join, even if you don't have any issues yet! We love chatting about random CRPL stuff to pass the time. Grabz noticed that you used the alternate control mode, which he has used for his scripts in the past so he may have some insight on how to handle certain things in that mode  ;D