Hi,
I've got a really strange problem. In a program of mine, this function is being executed:
function img_init()
global img_Count as integer = 0
dim img_Image(0) as img_ImageType
global img_DrawProgress as boolean = 1
global img_w as integer = 0
global img_h as integer = 0
rem Array to store stuff without having to create it everytime
dim img_temp(255) as dword
rem Permutations for Perlin Noise
dim Img_Perm(IMG_PERMCOUNT-1)
for i = 0 to IMG_PERMCOUNT-1
Img_Perm(i) = i
next i
for i = 1 to IMG_PERMCOUNT-1
j = rnd(i-1)
tmp = Img_Perm(j)
Img_Perm(j) = Img_Perm(i)
Img_Perm(i) = tmp
next i
message "1"
message "2"
temp1 = 1
message "3"
dim temp(1)
message "4"
dim Img_Gradient(IMG_PERMCOUNT-1,1)
message "5"
Img_Gradient(0,0) = 1 : Img_Gradient(0,1) = 1
Img_Gradient(1,0) = 1 : Img_Gradient(1,1) =-1
Img_Gradient(2,0) =-1 : Img_Gradient(2,1) = 1
Img_Gradient(3,0) =-1 : Img_Gradient(3,1) =-1
for i = 4 to IMG_PERMCOUNT-1 : Img_Gradient(i,0) = Img_Gradient(i mod 4,0) : Img_Gradient(i,1) = Img_Gradient(i mod 4, 1) : next i
endfunction
The messages are there for debugging purposes - and as it turns out, message "1", "2" and "3" pop up and then the program crashes (windows error).
I had the same problem like an hour ago. After 20 minutes of attempted debugging and my head nearly exploding due to the lack of logic in all this, the error vanished and everything worked just fine. But now it is back - without any changes being made to the code above in the meantime.
I know I haven't really got much information to provide you with, but does *anybdoy* here have an idea under which circumstances the line 'dim test(1)' could cause such a crash?
Your help is greatly appreciated.
greetings,
MrK
Edit: I just found out something rather interesting.
In the program that crashes, the first thing to be executed is this:
set display mode 640, 480, 32 : set window on : sync on : sync rate 0
img_init()
And img_init() is the function that causes the crash. However img_init() is not located in the main file but included. If I compile and run the file containing img_init() with the exact same beginning (display being set and img_init() called afterwards), it works fine. So, the way I see it, the problem has something to do with the rest of the code although it has not even been executed... the mere existence of certain code parts that would come later affects the existence of this crash. What a mess.
Edit 2: It doesn't get better.
I found a work around, by simply creating the arrays before the for loops instead of afterwards. For some reason that works. But I'm getting a different illogical error.
function img_save(mem, f$, ext$)
message "saving"
i = 0
message "a"
print get dir$() : sync : wait 2000
message "b"
tempS as string = "a"
message "c"
tempS = get dir$()
message "4: " + tempS
message "5"
repeat
cls : print i : sync
inc i
file$ = f$ + str$(i) + ext$
until file exist(file$)=0
message "File found: " + file$ + " - " + get dir$()
img = img_GetImage(mem)
message "Saving..."
save image file$, img
delete image img
endfunction
The first 4 messages (saving, a, b, c) pop up, then a windows error in the next line "tempS = get dir$()". The function itself seems to work, as I used get dir$() 4 lines above, and assigning values to the tempS variable seems to work as well. But combining those two leads to a crash. Seriously... what the hell is going on here? I've worked with DBP without any problems throughout the last few days, and now that.
Edit 3:
As it turns out, there really is not a problem with get dir$(). In the function above, when I insert this code:
message temp1$ + temp2$
file$ = temp1$ + temp2$
message "done"
The first message appears, but the second one doesn't due to the usual crash. I have no idea whether this bug is related to the array-crash I had in the beginning.
And once again, usually this code works fine, but in the context of the program I'm working on it crashes for some reason.