Author Topic: Nextelement crash  (Read 10751 times)

Offline PurpleYouko

  • Bot God
  • *****
  • Posts: 2556
    • View Profile
Nextelement crash
« on: October 31, 2005, 08:58:51 AM »
Here is another one.

Over the weekend, I got a crash in "Nextelement" subroutine in the "mutations" module
Code: [Select]
Public Function NextElement(ByRef DNA() As block, beginning As Integer, tipo As Integer, value As Integer) As Integer
  'takes the input for the first value in a gene and returns the position of the next statement
  'as defined by tipo and value
  Dim k As Integer
  Dim uboundarray As Long
  
  uboundarray = UBound(DNA())
  If DNA(uboundarray).tipo <> 4 And DNA(uboundarray).value <> 4 Then
    ReDim Preserve DNA(uboundarray + 1)
    DNA(uboundarray + 1).tipo = 4
    DNA(uboundarray + 1).value = 4
  End If
  k = beginning
  
  If beginning > 0 And beginning < uboundarray Then
    While Not (DNA(k).tipo = 4 And DNA(k).value = 4) And Not (DNA(k).tipo = tipo And DNA(k).value = value)
      k = k + 1
          Wend
    If Not (DNA(k).tipo = tipo And DNA(k).value = value) Then k = -1
  Else 'beginning wasn't valid
    k = -1
  End If
  
  NextElement = k
End Function

for some reason 'k' was getting bigger than the maximum array size (defined in 'uboundarray')

Below is the fix for it.

By adding a conditional to exit the while loop if 'k' exceeds the allowed value, we can prevent the crash. Not sure if this will cause other problems further down the line by the function returning the wrong value. Shouldn't though because the conditional outside the while loop should set 'nextelement' to -1 anyway.
on jumping out of the while loop, 'k' has to first be set to a usable value so I set it to the maximum possible value of 'uboundarray'.

Code: [Select]
Public Function NextElement(ByRef DNA() As block, beginning As Integer, tipo As Integer, value As Integer) As Integer
  'takes the input for the first value in a gene and returns the position of the next statement
  'as defined by tipo and value
  Dim k As Integer
  Dim uboundarray As Long
  
  uboundarray = UBound(DNA())
  If DNA(uboundarray).tipo <> 4 And DNA(uboundarray).value <> 4 Then
    ReDim Preserve DNA(uboundarray + 1)
    DNA(uboundarray + 1).tipo = 4
    DNA(uboundarray + 1).value = 4
  End If
  k = beginning
  
  If beginning > 0 And beginning < uboundarray Then
    While Not (DNA(k).tipo = 4 And DNA(k).value = 4) And Not (DNA(k).tipo = tipo And DNA(k).value = value)
      k = k + 1
      If k > uboundarray Then k=uboundarray GoTo jumpout
    Wend
jumpout:
    If Not (DNA(k).tipo = tipo And DNA(k).value = value) Then k = -1
  Else 'beginning wasn't valid
    k = -1
  End If
  
  NextElement = k
End Function
There are 10 kinds of people in the world
Those who understand binary.
and those who don't

:D PY :D

Offline Testlund

  • Bot God
  • *****
  • Posts: 1574
    • View Profile
Nextelement crash
« Reply #1 on: November 02, 2005, 08:24:29 PM »
I think I got this crash; run-time error 9: out of bonds something, I don't remember.

This line of code was marked with yellow in debug mode:

While Not (DNA(k).tipo = 4 And DNA(k).value = 4) And Not (DNA(k).tipo = tipo And DNA(k).value = value)

I added your fix but there seem to be something wrong with it. This line of code is displayed in red text:

If k > uboundarray Then k=uboundarray GoTo jumpout

I also get a 'Compile error: Expected: End of statement'

The word 'Goto' gets marked.
The internet is corrupt and controlled by criminally minded people.

Offline Testlund

  • Bot God
  • *****
  • Posts: 1574
    • View Profile
Nextelement crash
« Reply #2 on: November 03, 2005, 02:42:17 AM »
See for yourself then:
The internet is corrupt and controlled by criminally minded people.

Offline PurpleYouko

  • Bot God
  • *****
  • Posts: 2556
    • View Profile
Nextelement crash
« Reply #3 on: November 03, 2005, 09:29:44 AM »
for some reason when I put that code up in a "code" window, it didn't show the colon in the middle of the line.

This is what it should be.

If k > uboundarray Then k=uboundarray: GoTo jumpout

The colon indicates the end of one action and the start of the next.
There are 10 kinds of people in the world
Those who understand binary.
and those who don't

:D PY :D

Offline Testlund

  • Bot God
  • *****
  • Posts: 1574
    • View Profile
Nextelement crash
« Reply #4 on: November 03, 2005, 09:35:35 AM »
That didn't fix it either, PY! Did you even try to run it yourself??  :pokey:
« Last Edit: November 03, 2005, 03:59:40 PM by Testlund »
The internet is corrupt and controlled by criminally minded people.

Offline Testlund

  • Bot God
  • *****
  • Posts: 1574
    • View Profile
Nextelement crash
« Reply #5 on: November 05, 2005, 06:10:08 AM »
HELLO???

Could someone please give me the RIGHT CODE to put in! The above fix doesn't work!
The internet is corrupt and controlled by criminally minded people.

Offline PurpleYouko

  • Bot God
  • *****
  • Posts: 2556
    • View Profile
Nextelement crash
« Reply #6 on: November 07, 2005, 07:28:43 PM »
Quote
That didn't fix it either, PY! Did you even try to run it yourself??  :pokey:
Yes I did. It has been running faultlessly for days now.
There are 10 kinds of people in the world
Those who understand binary.
and those who don't

:D PY :D

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Nextelement crash
« Reply #7 on: November 07, 2005, 07:33:19 PM »
That's my problem.  I can run sims for months if I wanted, and as soon as I release it people find ways to crash the program in a matter of hours...

Offline PurpleYouko

  • Bot God
  • *****
  • Posts: 2556
    • View Profile
Nextelement crash
« Reply #8 on: November 07, 2005, 07:35:19 PM »
Tell me about it.

the modded 2.37.4 code has been running non-stop on my computer at work for about a week now. It hasn't crashed since last Tuesday.  <_<
There are 10 kinds of people in the world
Those who understand binary.
and those who don't

:D PY :D

Offline shvarz

  • Bot God
  • *****
  • Posts: 1341
    • View Profile
Nextelement crash
« Reply #9 on: November 07, 2005, 08:05:46 PM »
Yeah, something got broken.  I have not run DB for a long time, but now I re-downloaded everything and fresh-installed and now I can't run 2.37.4.  Weird.  It crashes in like 5 minutes.

How come?  I used to run sims for weeks.  I think I had 2.37.4, but I am not sure.
"Never underestimate the power of stupid things in big numbers" - Serious Sam

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Nextelement crash
« Reply #10 on: November 08, 2005, 05:41:55 PM »
There's nothing in the sysvars files that's not backwards compatible. There's nothign in them that even can be non-backwards compatible.

I've also had no problems-- ever-- running older versions with newer sysvars.

This sounds suspiciously like the same sorts of superstitions that pro athletes have.  If it makes you happy to use older sysvars files, go ahead.  It doesn't hurt anything...
« Last Edit: November 08, 2005, 05:42:30 PM by Numsgil »

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Nextelement crash
« Reply #11 on: November 09, 2005, 11:56:37 AM »
DB works for me on my computer.  Versions you've had problems with shvarz has managed to run simulations in that accumulated millions of cycles.

so perhaps you should modify it to:

"bottom line: I can't figure out how to get DB to run for me." --or --

"bottom line: DB doesn't work for me on my settings."

You seem to have a knack for running settings that break the sim.  Congratulations, you are truly a magnificent bug tester.  I know that's not what you wanted to hear, but it seems to be fact.

2.4.9 has had it's hard drive routines totally revamped, so you should be able to set up autosaves.  (older versions were saving and loading the bots, but screwing up the settings)  If it crashes, you can just load the last autosave.
« Last Edit: November 09, 2005, 11:57:05 AM by Numsgil »

Offline PurpleYouko

  • Bot God
  • *****
  • Posts: 2556
    • View Profile
Nextelement crash
« Reply #12 on: November 09, 2005, 02:28:57 PM »
I have just spent the last week and a half fixing V2.37.4.

I have thrown everything at it and managed to reproduce and fix every bug that has been reported to me and a few that weren't.

The bottom line is that the 2.37.5 source code ran for over a week without a crash and the executable has now clocked up over 5 million cycles without a hitch.

I have tested it on my 1.8 gig, win 2000 system at work, my 700meg win ME system at home and my daughter's 3 gig Win XP version.

I can't break it!!!! As far as I can tell we have a version that now works. If you know otherwise then please tell me how I am supposed to fix it.
There are 10 kinds of people in the world
Those who understand binary.
and those who don't

:D PY :D

Offline shvarz

  • Bot God
  • *****
  • Posts: 1341
    • View Profile
Nextelement crash
« Reply #13 on: November 09, 2005, 02:33:24 PM »
Griz, you are the one being immature here.  

1. The version that you say is broken works for me.  Period.  No tweaking done, just d/l, install, click start.  It runs.  It runs for a very long time and does not crash.  If you found something that reproducibly breaks the program - please test and report.  It will get fixed.

2. Your constant whining "this is going in the wrong direction" is really annoying.  The reason for it being REALLY annoying is that you don't actually say what part is going in the wrong direction.  And you don't propose any modifications that would help it move in the right direction.  You don't.  There is no substance in your posts.  Just complains and accusations.

Really. If you don't change your attitude, then please do leave and please don't come back.  It's just not constructive to have people like this on the project.  :angry:
"Never underestimate the power of stupid things in big numbers" - Serious Sam

Offline shvarz

  • Bot God
  • *****
  • Posts: 1341
    • View Profile
Nextelement crash
« Reply #14 on: November 09, 2005, 06:12:34 PM »
well, that just means that you have a bad install.  
it certainly does not mean that we don't have a stable version

solution: do a fresh install.  Easy.
"Never underestimate the power of stupid things in big numbers" - Serious Sam