• Our friends from AlphaCentauri2.info are in need of technical assistance. If you have experience with the LAMP stack and some hours to spare, please help them out and post here.

Adding new Resource Yields to Future Techs

Launch your mod, using the debug DLL. Then go to VS2008 and select DEBUG->ATTACH TO PROCESS, it will pop up a list of all processes running, with Civ4 typically being quite prominent among the list (has more information and shows in the first screen).

Once you are attached, you can place breakpoints and it'll pause the Civ program and take you to the breakpoint you placed when the code reaches that area. Or if an error happens, the code will stop running and offer to show you where it broke at. Also all of those FAssert() statements will start to work, they show up as an announcement that an assert happened, and an option to stop the program and look at the code, ignore it once, ignore it forever, or simply abort the entire operation.


You can set up VS so that when you hit F5 it will automatically compile your Debug DLL and launch the program with debugging attached immediately. This is REALLY nice in that you can return to VS and hit SHIFT+F5 at any time to immediately stop the program from running (great for getting out of lockups). Plus this attaches you immediately so you can see any issues which happen during loading (also, you should edit your makefile to copy the DLL automatically from where you compile it to where you use it, so that you know for certain you are using your latest source)
 
umm...:run:

You're really scaring the bejeezus outta me xienwolf... I didn't understand most of what you just said...

OK, first, I musta missed something, cause I can't find anything specific in Refar's PDF about how to make a Debug DLL. He just says to use Build -> Build Solution to do everything at once. But I don't see anything called "Debug CvGameCoreDLL" anywhere...

Second, although I think I follow the instructions on how to activate the debugging tool within VS2008 once CivIV is running (it'll make more sense to me when I do it), I don't know how to "attach breakpoints", or how to effectively use them.

Raw noobie here, I just like to think I know what I'm doing. :crazyeye:

Thirdly, how would I edit the Makefile to copy my CvGameCoreDLL from its output location to where Civ loads it from? Can I just tack a DOS-style Copy command at the end of the Makefile? I didn't see anything in there that looked like it was safe to muck around with...

Thanks again xienwolf. Your patience is amazing, and appreciated.
 
You can get a copy of my personal makefile here. It is for Fall Further, so this almost certainly won't work with normal BtS, but it at least shows you some of the differences.

You can edit a makefile with notepad (or Notepad++, etc), and any build target you make (Refar's guide walked you through making Final_Release... can't remember if it also walked you through Debug) needs to be mentioned in the Makefile. For mine I have added a normal "Release" version so that I can enable profiling for myself.

So, open your makefile, search for "Debug," if you get quite a few results, then you should be set to make a debug DLL. If not, you'll have to go through and copy a bunch of things unfortunately.

To auto-copy your finished DLL to your game directory, search in my Makefile for "copy," and you'll want to do similar.



To make a breakpoint in VS, just click on the blank bar next to the line number and a red dot appears. That is a breakpoint and won't do anything but give you a pretty red dot unless you are running a debug DLL and have attached yourself to it :)
 
Sorry for the long delay xienwolf. Kinda lost my motivation for a while... :cry: But, I'm ready to take another stab at this.

So, clicking in the grey column on the left gives me a pretty little red dot that will be used as a breakpoint if I compile a Debug DLL & attach myself to it when I run CivIV. But, where should I attach one of these breakpoints? Should I just go through my code one change at a time with a breakpoint on each one until I come across something sketchy?

I haven't figured out how to automate that compile->run->attach process like you uggested yet, BTW. Is that done through the makefile too? OH, and I did figure out how to make a Debug DLL. Up at the top of a VS2008 window there's section called "Solution Configuration", with drop-down options of Debug or Final_Release. So, got that sorted, at least.
 
Put a breakpoint wherever you want the game to pause so you can inspect what's going on. Once a breakpoint has been hit, VS should come to the foreground and show you where in the code you are. Here you can

  • Inspect values of variables/parameters. You use this to figure out what's wrong.
  • Step line-by-line through your code.
  • Continue execution (un-pause).
Note that there are multiple forms of stepping:

  • Over: completely executes the current statement including any function calls/loops it contains.
  • Into: executes into the next function call in the current statement.
  • Out: Continues executing until the end of the current function. It might pause at the return or it might jump to the caller of the function.
 
Any that you aren't sure are working. It often pays to start with the one you think is the most likely to be failing. Also, you can add/remove breakpoints while the program is running/paused.
 
Been a while so I can't remember if you had a crash, or just numbers not working. If it is a crash that makes life easy as crashing while a debugger is attached will jump you to the most recent code (unless it is a graphical crash usually). Then you breakpoint shortly before that.


If it is a value, go to where your value should be read for any random reason, and set a breakpoint there, then do something which ought to make it be read (like gaining the new tech, or doing a mouseover on it) and if the breakpoint DOESN'T trigger, then you aren't hitting it and need to back up further to check why.



To automatically attach, you ought to modify the makefile to copy your fresh compiled DLL to your working directory. To do that you want to find the first line here, and add the second (with proper path for your computer)
Code:
Debug-after:
	-@if exist "Debug\CvGameCoreDLL.dll" copy "Debug\CvGameCoreDLL.dll" "C:\Program Files\Firaxis Games\Sid Meier's Civilization 4\Beyond the Sword\Mods\Fall Further\Assets"

To set things up so you can automatically run the program by hitting F5 while in VS, hit ALT+F7 (Or go to Project, then choose the last option, CvGameCoreDLL Properties)

Expand Configuration Properties, select Debugging In the first line "Command", enter

C:\Program Files\Firaxis Games\Sid Meier's Civilization 4\Beyond the Sword\Civ4BeyondSword.exe

Using the correct path for your own BtS exe location of course.

In the second line "Command Arguments", enter

mod=\Fall Further

Using the name of your own mod (so between these two, it should construct the target line of a shortcut to immediately launch your mod)


I don't think I actually changed any of the following lines. Working Directory is blank, Attach is "No" (this is asking if it should attach to something which is already running, not to what it is currently launching), "Debugger Type" is Auto, "Environment" is blank, "Merge Environment" is Yes.


Relatively certain that setting this piece up was all that was required to have auto-launching of the debugger attached setup possible. You can manually copy your DLL after compiling it, THEN do this of course, but the auto-copy is just plain useful :)
 
OK, so, three things:
  1. I'm an idiot. Turns out I've been copying the new compiles of the DLL into the BtS\Assets directory, instead of into BtS\Mods\RichMod\Assets. Yeesh...
  2. The DLL as compiled now has an effect! Unfortunately, it's a very bad one. The entire page for both Buildings & Wonders is blank in the 'Pedia. So, I did something! Yay!!! Just not what I wanted...
  3. I will try Debugging next, hopefully I can figure that out, which will help point me where I went wrong.
 
Is this normal, and/or acceptable, when using Visual C++ 2008?

Creating library Final_Release\CvGameCoreDLL.lib and object Final_Release\CvGameCoreDLL.exp
LINK : warning LNK4089: all references to 'KERNEL32.dll' discarded by /OPT:REF
Build log was saved at "file://c:\Documents and Settings\Richard Langlois\Desktop\Civ IV Mods\CvGameCoreDLL\Final_Release\BuildLog.htm"
CvGameCoreDLL - 0 error(s), 1 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
 
That happens any time that you do a non-Debug build. It is just telling you that all of the information in the DLL which only applies to debugging is being dumped to save size/speed. You can set it to ignore that error if you really want to.


Pedia is totally blank, or stops after a certain entry?
 
Do you see all the UI elements on the page with no data, or are those pages just not drawn? Do you get a Python error when clicking on a Building or Wonder in the list? They use the same page even though they are in different lists. Check PythonErr.log.
 
No, there is NO UI on those two pages. When you click on the link on the right for "Techs" (for example), the Tech page comes up, as expected. All other pages work as expected too, except for Buildings & Wonders. When you click on either of those links, the link changes to the "selected" colour, but, nothing comes up on viewing pane. It remains perfectly blank, as such:

PediaScreenShot0001.JPG

Oh, and the PythonErr.log is stuffed, which I kinda expected.
Spoiler :
Traceback (most recent call last):

File "CvScreensInterface", line 393, in pediaMain

File "CvPediaMain", line 873, in pediaJump

File "CvPediaMain", line 244, in showScreen

File "CvPediaMain", line 342, in placeBuildings

RuntimeError: unidentifiable C++ exception
ERR: Python function pediaMain failed, module CvScreensInterface
Traceback (most recent call last):

File "CvScreensInterface", line 393, in pediaMain

File "CvPediaMain", line 873, in pediaJump

File "CvPediaMain", line 244, in showScreen

File "CvPediaMain", line 370, in placeWonders

RuntimeError: unidentifiable C++ exception
ERR: Python function pediaMain failed, module CvScreensInterface
Traceback (most recent call last):

File "CvScreensInterface", line 393, in pediaMain

File "CvPediaMain", line 873, in pediaJump

File "CvPediaMain", line 244, in showScreen

File "CvPediaMain", line 370, in placeWonders

RuntimeError: unidentifiable C++ exception
ERR: Python function pediaMain failed, module CvScreensInterface
Traceback (most recent call last):

File "CvScreensInterface", line 393, in pediaMain

File "CvPediaMain", line 873, in pediaJump

File "CvPediaMain", line 244, in showScreen

File "CvPediaMain", line 342, in placeBuildings

RuntimeError: unidentifiable C++ exception
ERR: Python function pediaMain failed, module CvScreensInterface
Traceback (most recent call last):

File "CvScreensInterface", line 393, in pediaMain

File "CvPediaMain", line 873, in pediaJump

File "CvPediaMain", line 244, in showScreen

File "CvPediaMain", line 342, in placeBuildings

RuntimeError: unidentifiable C++ exception
ERR: Python function pediaMain failed, module CvScreensInterface
Traceback (most recent call last):

File "CvScreensInterface", line 393, in pediaMain

File "CvPediaMain", line 873, in pediaJump

File "CvPediaMain", line 244, in showScreen

File "CvPediaMain", line 370, in placeWonders

RuntimeError: unidentifiable C++ exception
ERR: Python function pediaMain failed, module CvScreensInterface


Thanks guys!
 
Alright, and I'm totally confused by the Python Err.log...

The three lines in CvPediaMain have not been edited, and although the first two do (I think) reference the problem pages in the Pedia, I don't see why it's causing a problem. The error from line 393 of CvScreensInterface also makes no sense to me, as I haven't ever gone into that file either.

I should point out, I am not using the Sevopedia.

As of now, I'm going to go with the assumption that the Python errors are effects, not causes, the root being my inadequate writing of C++.
 
I should point out, I am not using the Sevopedia.

Yes, I see that from the screenshot. I had assumed Sevo, but now I see that simply placing the list of buildings is what is causing the problem.

Alright, and I'm totally confused by the Python Err.log...

Each error shows the code that lead up to the error. This is called an exception stack trace. The stack is merely what the Python interpreter uses to keep track of functions that call each other. If you call A() which calls B() which calls C(), the stack will have A, B, C on it. If C causes an exception, you can track how it got there. It doesn't mean that A and B caused it, but they may have been the source, so they are useful.

Code:
Traceback (most recent call last):

This just means that an exception stack trace is about to be printed. "most recent call last" means that pediaMain() called pediaJump() which called showScreen() which called placeBuildings() which called a C++ function that threw an "unidentifiable exception."

Code:
  File "CvScreensInterface", line 393, in pediaMain
  File "CvPediaMain", line 873, in pediaJump
  File "CvPediaMain", line 244, in showScreen
  [B]File "CvPediaMain", line 342, in placeBuildings[/B]
RuntimeError: unidentifiable C++ exception

This is the best place to start. That line must be calling a Python API function which calls to C++. What does that line (and the 3 lines above and below it for context) contain?

Code:
ERR: Python function pediaMain failed, module CvScreensInterface

This is the starting point. Clicking on the "Buildings" widget on the right side of the screen caused the DLL to call pediaMain() in CvScreensInterface. This is just telling you entry into the Python code.

As of now, I'm going to go with the assumption that the Python errors are effects, not causes, the root being my inadequate writing of C++.

I would agree with this assumption. The C++ code is encountering an error and throwing an exception which the Python layer doesn't try to interpret.
 
Your problem is almost definitely in CvGameTextMgr.cpp

If the game can load without issue, settle a city and see if the production popup will appear and have buildings on it. I am pretty sure it will show up just fine, but most likely as soon as you attempt to do a mouseover it will crash. If so, then you messed up something generic. If not, then find a building which should display one of your new functions and see if a mouseover of that one will cause a crash, or garbled text output. If that happens, then you made a mistake which isn't quite applying globally (but if that WERE the case, I would expect all buildings up until the one using the new tag to display just fine in the pedia).


Also, go to the Technologies tab and try to see if you can click on a hyperlink to a building and get any results at all. Would expect much the same to happen in that case, but it is possible you might be allowed to follow the link and get a partial pedia page.
 
Back
Top Bottom