Apolyton Archive  |  Preserved copy of the Apolyton Civilization Site and its forums as they stood in September 2005. Read-only; nothing here can be posted to or replied to.  |  Forum index |  About this archive |  The 1998–2001 UBB forums
Today on Apolyton WARDELL INTERVIEW PROMO A.C.S. HISTORY CHAPTER 4 GET CIV4 /w FREE PLUS! A.C.S. PHOTO GALLERY GET A.O.M. V1.1
Apolyton Civilization Forums
main| civ2| civ3| civ4| smac| ctp2| ron| moo3| galciv| galciv2| alt| about|
ApolytonPLUS | register | search | faq | new posts | pm (-/-) | upload | members
hall of fame new! | civgroups | civgroups news | interviews | the column | radio | chat | directory | news | store | PLUS
Apolyton Civilization Forums : Powered by vBulletin version 2.0.3 Apolyton Civilization Forums > Call To Power II > CtP2-Source Code Project > DEBUG: Odd behaviour of Assertions
Show a Printable Version | Email This Page to Someone! | Receive updates to this thread | Report this to Apolyton news!
CivGroups
CTP2 Source Code Project (59): Not a Member - Join

bottom of page
  
Author
Thread    < Last Thread     Next Thread > Post New Thread     Post A Reply
Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:31
Post  Old Post 08-11-2003 04:18 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#1 Report this post to a moderator
DEBUG: Odd behaviour of Assertions Support Apolyton buy from Amazon

While I was readding some of the slic functions of the patch I noticed that this code gives more debug assertions regarding Diplomacy personalities strings:

code:
SFN_ERROR Slic_TileHasImprovement::Call(SlicArgList *args) { if(args->m_numArgs != 2) return SFN_ERROR_NUM_ARGS; MapPoint pos; if(!args->GetPos(0, pos)) return SFN_ERROR_TYPE_ARGS; sint32 imp; if(!args->GetInt(1, imp)) return SFN_ERROR_TYPE_ARGS; m_result.m_int = 0; Cell *cell = g_theWorld->GetCell(pos); for(sint32 i = 0; i < cell->GetNumDBImprovements(); i++) { if(imp == cell->GetDBImprovement(i)){ m_result.m_int = 1; return SFN_ERROR_OK; } } m_result.m_int = 0; return SFN_ERROR_OK; }


But this code is fine:

code:
SFN_ERROR Slic_TileHasImprovement::Call(SlicArgList *args) { if(args->m_numArgs != 2) return SFN_ERROR_NUM_ARGS; MapPoint pos; if(!args->GetPos(0, pos)) return SFN_ERROR_TYPE_ARGS; sint32 imp; if(!args->GetInt(1, imp)) return SFN_ERROR_TYPE_ARGS; m_result.m_int = 0; Cell *cell = g_theWorld->GetCell(pos); for(sint32 i = 0; i < cell->GetNumDBImprovements(); i++) { if(imp == cell->GetDBImprovement(i)){ m_result.m_int = 1; return SFN_ERROR_OK; } } return SFN_ERROR_OK; }


The only difference Between these two pieces of code is that the line m_result.m_int = 0; is placed before the for loop in the second piece of code instead afterwards.

-Martin

Locutus is offline Locutus
ACS CTP1/2 Manager & Civ4 Co-Manager
Hengelo, The Netherlands
Nov 1999
time: 06:31
  Old Post 08-11-2003 04:36 Visit Locutus<br><img src=/forums/images/staff-icon.gif>'s homepage!
Edit/Delete Message Reply w/Quote
#2 Report this post to a moderator
Support Apolyton, buy Civilization 2

Well, what kind of asserts is it giving you?

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:31
Post  Old Post 08-11-2003 04:42 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#3 Report this post to a moderator
Support Apolyton, buy Call to Power 2

It is in diplomat.cpp located line 661:

code:
void Diplomat::SetPersonalityName(const char *personality_name) { m_personalityName = string(personality_name); sint32 index; bool found = g_thePersonalityDB->GetNamedItem(personality_name, index); Assert(found); if (found) m_personality = g_thePersonalityDB->Get(index); }


Assert(found); fails but only if I put the line:
m_result.m_int = 0;
after the for loop. Otherwise no problem and that is what I don't understand, why the order of a piece of code does matter even if it is not called.

-Martin

J Bytheway is offline J Bytheway
Emperor
England
Jul 2001
time: 05:31
  Old Post 08-11-2003 14:08 Visit J Bytheway's homepage!
Edit/Delete Message Reply w/Quote
#4 Report this post to a moderator
Support Apolyton, buy Galactic Civilizations: Deluxe Edition

That is indeed very strange... The only explanation I can think of is that the memory which did hold the integer is now being used for something else which is not correctly initialized, but that seems far fetched.

LDiCesare is offline LDiCesare
King
La Ferté sous Jouarre France
Jan 2001
time: 05:31
  Old Post 08-11-2003 14:53
Edit/Delete Message Reply w/Quote
#5 Report this post to a moderator
Got spare money?

The assignment is not made after in the assert case, but both before and after. Is there some provision for putting the same value back in? What if you put twice m_result.m_int = 0; before the loop?
(You know that putting it after is useless anyway I bet)

Leland is offline Leland
Prince

Jan 2000
time: 07:31
  Old Post 08-11-2003 18:04
Edit/Delete Message Reply w/Quote
#6 Report this post to a moderator
Browse Apolyton AD-FREE

I haven't seen the actual code (apart from what was posted in this thread), but I'm wondering how you knew to fix it like this? What's the connection between Slic_TileHasImprovement::Call and Diplomat::SetPersonalityName?

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:31
Post  Old Post 08-11-2003 19:36 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#7 Report this post to a moderator
Support Apolyton, pre-order Civilization IV

quote:
Origianlly posted by Leland
I haven't seen the actual code (apart from what was posted in this thread), but I'm wondering how you knew to fix it like this? What's the connection between Slic_TileHasImprovement::Call and Diplomat::SetPersonalityName?


I have no idea what the connection between Slic_TileHasImprovement::Call and Diplomat::SetPersonalityName is, especial if I consider that I added the Slic_TileHasImprovement::Call on my own. So the only connection are the additional asserts.

Getting to know to fix like this is easy, just take a look on the other slic functions and you see that the m_result.m_int = 0; comes before all the other code in those slic functions.

quote:
Origianlly posted by LDiCesare
The assignment is not made after in the assert case, but both before and after. Is there some provision for putting the same value back in? What if you put twice m_result.m_int = 0; before the loop?
(You know that putting it after is useless anyway I bet)


I don't see any sense in putting it twice before the loop as once is enough. And it is not useless to put it afterwards the loop as it returns the right value, it just gives me an additional assert.

quote:
Origianlly posted by J Bytheway
That is indeed very strange... The only explanation I can think of is that the memory which did hold the integer is now being used for something else which is not correctly initialized, but that seems far fetched.


I think it is not too far fetched, actual the only explanation I can come up now. In my Java course we did something with threads. Threads are a way to simulate parallel computation on a single processor, every window program is full of threads. For instance the program must be react on mouse clicks while it is computing something else in the background. Basicly one thread is active while the other threads are passive, in the active thread values of objects can be changed or objects can be deleted/created. So if you delete an objet somewhere that is needed in another thread or don't create it than you have a problem.

OK to make it short, threads are necessary in complex programs, but there are some problems like death lock and live lock and instability. Death lock is when all your theads are waiting from stuff from each other to continue their computation. And a live lock is when the threads are waiting for more processor capacity to compute more expensive stuff but do easy stuff while they are waiting. In a live lock you see the program hang but the processor load goes to the limit, while at a death lock the processor does nothing. About instability is to mention that your program can run on the one computer very stable and on the other computer very instable, or a very random crashing behaviour that for instance depends on the internal state of the computer e.g. random number generator. I know not a very good example, because it looks very random and it is indeed very random.

Well that text became longer than I thought, but that is so far all I know about, we got not know more about it as it would have been to much for a Java course, especially if you consider that there is a whole lecture about this topic.

-Martin

  < Last Thread     Next Thread > Post New Thread     Post A Reply
All times are GMT. The time now is 05:31.
Apolyton Time is 00:31.
    top of page
Rate This Thread:
Forum Jump:
Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is ON
vB code is ON
Smilies are ON
[IMG] code is ON
 




Contact Us - Apolyton Civilization Site - Support Us!

Building a better Apolyton through better information. Click here and take our poll!
Non-US visitors, click here!

Powered by: vBulletin Version 2.0.3
Copyright ©2000, 2001, Jelsoft Enterprises Limited.

Page generated in 0.0338 seconds (89.02% PHP - 10.98% MySQL) with 36 queries
Page Loading Time:

Support Apolyton: Amazon USA | Amazon UK | Amazon DE | Amazon FR |
Support Apolyton and get FREE PLUS, Buy from Chips&Bits: Galactic Civilizations | Galactic Civilizations: Deluxe Edition | Call to Power 2 | Civilization: The Boardgame | GURPS/ Alpha Centauri | Alpha Centauri | Civilization IV | Civilization III: Complete |


Front Page | Civilization IV | Civilization III | Civilization II | Call to Power II | Alpha Centauri | Master of Orion III
Rise of Nations | Galactic Civilizations | Galactic Civilizations II | Misc
Alt.Civs | Civ I | C:CtP I | About | News | Directory | Apolyton Store | Forums | Chat | Columns | Interviews | Newsletter
Scenario League | CSC | Clash of Civs | Spanish Site | CtP Maps | Cradle of Civ | WesW's Ctp1/2 Site | Civ3 Haven

apolyton.net | apolyton.com | civilization2.net | civilization3.net | civilization4.net | civilizationiv.info | calltopower.net | galciv.net | galciv2.net | moo3.net