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.

DarkBASIC Professional Discussion / Delete bitmap causing crash.

Author
Message
KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 22nd Mar 2010 23:02
A little while ago I added the following code to my program to preload colors for players to choose from.


The FreeImg() function just returns the next available image number.

So this code runs fine and all, but after I added it, there's another section of code that creates a new bitmap 4, uses it, then deletes bitmap 4 again.

Through hours of debugging (in step through mode) I finally tracked the crash to the line "delete bitmap 4". This section of code worked perfectly before I inserted the above code, and if I remove the above code it still works perfect.

So, any ideas what would be causing this line to crash the program?

It crashes to the "Your program has caused an error and must be shutdown...blah, blah, blah.." error with the Send / Don't Send buttons. So there's no meaningful data to indicate what might be happening.

I thought it might be memory, as I was working with nearly 200 images in memory at once, and almost 250 objects right before the crash. So I reduced the size of all my textures by half, but that didn't stop this either.

JLMoondog
Moderator
17
Years of Service
User Offline
Joined: 18th Jan 2009
Location: Paradox
Posted: 22nd Mar 2010 23:30
What exactly does the FreeImg() function do to check availability? Right now it's hard tell with just that bit of code and your description.

Looking at this your using the FreeImg() function 27 times a loop with that code, so it seems you'd get 27 different image numbers...did you want to do this?


KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 22nd Mar 2010 23:33 Edited at: 23rd Mar 2010 00:28
Yes, that's the function of the FreeImg() function.



[edit]

Ok, I don't think it's related to the delete bitmap command. I went through all the code that uses separate bitmaps, created just one, and switched to it when needed and back to bitmap 0 when I didn't, and it crashed again at about the same place. So I'm headed back into step through mode in the debugger to find out whats going on.

JLMoondog
Moderator
17
Years of Service
User Offline
Joined: 18th Jan 2009
Location: Paradox
Posted: 22nd Mar 2010 23:59
Hmm...I actually tested your function and it gives a value of zero everytime...looking into this.


JLMoondog
Moderator
17
Years of Service
User Offline
Joined: 18th Jan 2009
Location: Paradox
Posted: 23rd Mar 2010 00:05 Edited at: 23rd Mar 2010 00:17
Alright so I changed your code a bit, but i'm sure this will work.

First here is the function:


Here's the variables you must declare before the start of your program:


When using the function, you must do this before you add the image number to a command, example:


This works, for some reason yours doesn't, and I think it's because your function variables are local to the function and can't be used outside of it...not exactly sure, might be wrong.

Edit: sorry, last edit, must have edited the post 20 times

edit2: just realized, is MAX_IMAGES variable a global variable? that would do it.


KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 23rd Mar 2010 00:27 Edited at: 23rd Mar 2010 00:31
Um, it would return a 1 every time, unless you actually use the result to load an image.



But like I said, the FreeImg() function isn't the issue.

At this point, neither is the delete bitmap command. I think there may be something fundamentally wrong with loading a bunch of images at once, or there's a problem in the get image command or there's really something seriously wrong with my code. Which would be VERY weird because the addition of the code in my initial message is the only difference.

JLMoondog
Moderator
17
Years of Service
User Offline
Joined: 18th Jan 2009
Location: Paradox
Posted: 23rd Mar 2010 00:31
Seriously, I tested your function and I receive a zero every-time, even with all variables declared properly.

I had a similar problem like this when checking for object numbers, it would only work if I set it up a certain way, like it is above.

Like I said, I could be wrong. It's the only thing I can see that could be wrong with the code, other then that I'm not sure.


KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 23rd Mar 2010 00:45 Edited at: 23rd Mar 2010 00:47
Ok, I must be tired. I coded that mess above without testing.

Here's a simplified version, but I've already looked into the FreeImg() function with the debugger watching the variables, and it's working as expected.



Which outputs the result of FreeImg() as

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Done.

Aside from all of that, if the FreeImg() function were the problem, I'd have about 6 other functions misbehaving the same way, and none of the textures would show up the way they're supposed to.

KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 23rd Mar 2010 05:10
Finally narrowed it down to (sadly) one of IanM's Matrix1Utils commands.

Hex to Decimal was doing something, not sure what, and it seems to have corrupted the return pointer for the subroutine it was in. Every time I commented those commands out, the problem went away.

I wrote a function of my own to handle the conversion and it's all working now.

JLMoondog
Moderator
17
Years of Service
User Offline
Joined: 18th Jan 2009
Location: Paradox
Posted: 23rd Mar 2010 08:39
Glad to hear you figured it out.


tiresius
23
Years of Service
User Offline
Joined: 13th Nov 2002
Location: MA USA
Posted: 23rd Mar 2010 16:26
So was it really crashing on the delete bitmap 4 command or did you trap it out to find out it was crashing while exiting a completely different routine? I'm interested in these hard to diagnose bugs so I'd like to know what exactly you did to find it out.


A 3D marble platformer using Newton physics.
KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 23rd Mar 2010 18:48
The last line that executed in the debugger was the delete bitmap 4, but the very next line was the Return from that subroutine. The only conclusion I can come up with is the Hex to Decimal command was somehow corrupting the return pointer, and the return went somewhere it shouldn't, so it crashed. That's my best guess anyway...

tiresius
23
Years of Service
User Offline
Joined: 13th Nov 2002
Location: MA USA
Posted: 23rd Mar 2010 20:31
I guess putting a Print "Hello" command after the bitmap would prove that it is the return command? Thanks for sharing, those types of bugs are very difficult to find.


A 3D marble platformer using Newton physics.
KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 24th Mar 2010 04:37
I had originally put,

print (a variable I was watching)
sync
wait kay

After the Delete Bitmap, and right before the Return. That's how I eventually found it.

Login to post a reply

Server time is: 2026-07-26 21:10:36
Your offset time is: 2026-07-26 21:10:36