Author Topic: Problem With Outpost 2 Coding  (Read 1648 times)

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
Problem With Outpost 2 Coding
« on: September 05, 2005, 01:50:17 PM »
Can anyone see HOW this code could generate an exception (read of address) in RemoveUnit:
Code: [Select]
void RemoveAllUnits(ScGroup grp)
{
   Unit u;
   GroupEnumerator enum1(grp);

   while (enum1.GetNext(u))
     grp.RemoveUnit(u);
}
I've tried inserting IsLive .. but thats not the problem. I've debugged it - the unitIDs are existing - i can call things like u.DoMove(...) without it crashing. I'm lost here :blink:
Rule #1:  Eddy is always right
Rule #2: If you think he's wrong, see rule #1
--------------------

Outpost : Renegades - Eddy-B.com - Electronics Pit[/siz

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4955
Problem With Outpost 2 Coding
« Reply #1 on: September 05, 2005, 02:15:48 PM »
I have an idea. It's probably that you're enumerating over a non static group. I doubt the enumerator is designed to work if the group is changing contents while enumerating. So say there are 2 units the group, and you've deleted the first 1, and are now accessing index 1. That index might no longer be valid since it may repack the internal array, and there is only 1 element left (index 0).

Usually the solution to problems like this, is to iterate the group in reverse and remove things from the end. But, that doesn't seem to be much of an option here.

Or maybe this is just something else entirely. Well, good luck figuring it out.
 

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
Problem With Outpost 2 Coding
« Reply #2 on: September 05, 2005, 02:44:59 PM »
well thanx a lot - i'll try a simple solution to that: i'll enumerate first, putting all those units into an array, that way i know it's not going to be a dynamic list. The just use a loop to remove all array members one by one...

Also , im not sure, but i think this error came with the very first time the loop iterated..
Rule #1:  Eddy is always right
Rule #2: If you think he's wrong, see rule #1
--------------------

Outpost : Renegades - Eddy-B.com - Electronics Pit[/siz

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
Problem With Outpost 2 Coding
« Reply #3 on: September 15, 2005, 03:28:51 PM »
I believe the problem lies in the 127 ScStubs restriction.
This is the reason why i started my new project (see also http://forum.outpostuniverse.net/index.php?showtopic=2021). So for now, this thread can be closed.
Rule #1:  Eddy is always right
Rule #2: If you think he's wrong, see rule #1
--------------------

Outpost : Renegades - Eddy-B.com - Electronics Pit[/siz

Offline BlackBox

  • Administrator
  • Hero Member
  • *****
  • Posts: 3093
Problem With Outpost 2 Coding
« Reply #4 on: September 15, 2005, 05:02:50 PM »
Alright; topic closed.