Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Crashing irregularly with "Array out of bounds" error

Author
Message
Cagedrei
15
Years of Service
User Offline
Joined: 18th Mar 2009
Location:
Posted: 17th Apr 2009 08:19
I've adapted this from a Blender Python script. It's largely working correctly, but every so often it crashes with the "Array does not exist or array subscript out of bounds" message. I've tried everything I can think of to try to prevent this, but I can't seem to figure it out.

Can someone more knowledgeable, or at least with a fresh eye, glance at this and see if anything stands out as the problem?

Requires the Matrix1 and Community Functions plugins.

KISTech
16
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 17th Apr 2009 18:15
I didn't go fully through the code, but have a look at

for i = 1 to length
for j = 1 to width
pixels(i, j)

However, your DIM statement has

dim pixels(width, length)

Cagedrei
15
Years of Service
User Offline
Joined: 18th Mar 2009
Location:
Posted: 17th Apr 2009 20:44 Edited at: 18th Apr 2009 07:30
Thanks, KISTech. I thought I'd fixed the looping in that section, but apparently I did it incompletely.

That shouldn't generate the error, though, if width and length are set to the same value, should it? Hmm.

The program also periodically just crashes when run. Windows tells me it isn't responding and shuts it down. As far as I can tell, that can be traced to the carveRoom() function (I split the function off into a separate test program to track the returned values, and was surprised when it crashed as I'm describing). I'm wondering if there may be some conflict between the different randomization functions used simultaneously. Could the Matrix1 and Community Funcs plugins be in conflict somehow? Baffling.

What does DBP do when a for loop is run in which the min value is greater than the max value and it runs as for i=min to max? I tested and found that such a loop seemed to be ignored, but I'm not really sure what happens.

Any programming language seems to have its own undisclosed quirks and limitations. I guess I need to work on learning about all of DBP's.
Cagedrei
15
Years of Service
User Offline
Joined: 18th Mar 2009
Location:
Posted: 17th Apr 2009 23:25
My out of bounds error looks like it was due to adding one to the results returned, which could put us out of range for the array. I was doing that because I got confused, trying to switch from array indexing to bitmap indexing. LOL -roll eyes- I also confuse my left and right. Sigh.

Well, one thing. Hmm. The Community Funcs rand min max isn't helping me much. Presumably I'd need to re-seed it regularly. It returns max values equal to or greater than min values with some regularity.

I wrote this to track the results. This test program crashes periodically when using rnd min max. If I substitute the RNG functions from the Matrix1 plugin, I get no crashes and no max values of the incorrect range.

Change the randtype variable to zero to run this (if you're inclined to run it) using Matrix1 RNG. By default it uses rnd min max.

I'll try plugging this altered function into the dungeon generator and see if my problems cease.

Cagedrei
15
Years of Service
User Offline
Joined: 18th Mar 2009
Location:
Posted: 18th Apr 2009 04:59 Edited at: 18th Apr 2009 07:20
Okay. I got it working. I had to replace rnd min max with my own homemade version of the process. Hmm.

Thanks for the help.

BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 18th Apr 2009 05:20 Edited at: 18th Apr 2009 05:20
Quote: "What does DBP do when a for loop is run in which the min value is greater than the max value and it runs as for i=min to max? I tested and found that such a loop seemed to be ignored, but I'm not really sure what happens."


I believe it does ignore these sorts of loops, but you can make it run them by doing this:

for c=100 to 1 step -1

The step -1 tells it to go backwards in numbers.

Quote: "Any programming language seems to have its own undisclosed quirks and limitations. I guess I need to work on learning about all of DBP's. "


Very true, that



Cagedrei
15
Years of Service
User Offline
Joined: 18th Mar 2009
Location:
Posted: 18th Apr 2009 07:26 Edited at: 18th Apr 2009 07:27
Oh, good! The loops can run backwards. I'll bet that's in the help docs and I scanned past it. Hmm. Thanks for the info!

Quote: "Very true, that "


Oh, aye. But which part? LOL I really do need to work on learning DBP's quirks. I'm mainly familiar with GML and Python, which can be plenty confusing. Dark Basic has me confused all the more because its conventions differ so frequently from those of the languages mentioned above. For instance, I'm used to being able to write my own line breaks in a text file, using backslash-n. DBP just treats that as more text and handles line breaks on its own. Hmm.

Login to post a reply

Server time is: 2024-09-28 04:24:46
Your offset time is: 2024-09-28 04:24:46