Some simple? problems, any help appreciated

BlitzMax Forums/BlitzMax Beginners Area/Some simple? problems, any help appreciated

Arabia(Posted 2010) [#1]
Can anyone tell me why this code doesn't work?

SuperStrict

Graphics 640,480,0
Cls

Local x:Byte
Local y:Byte

For x = 0 To 255
	For y = 0 To 255
		Cls
		DrawText x , 10 , 10
		DrawText y , 10 , 30
		Flip		
	Next
Next


1. If I change x & y to Int then all works fine. The range of Byte = 0 to 255 is it not? This just loops around from 0 to 255 on Y and never enters the x loop section.

2. If I run this code in full screen in Blide (Graphics 640,480,1) then it will hang to the point where I have to turn off my laptop. In the default MaxIDE I can end the process at least. Is there a way to build in a hotkey combination which will end the program regardless of where execution is currently at?

3. If I run in Windowed mode, including other stuff I've done with graphics - If I move the window around, partially off the screen etc. then the graphics become corrupt. Is this the crappy onboard video causing this on my laptop? I am away from home and can't try my desktop PC atm. Surely I don't need to check for the window being moved and redrawing it's contents.

4. Lastly, the reason for the loop structure is to initialise an array of Byte[255,255]. Do I actually need to do this? or would such an array be initialised to 0 for all elements upon creation?

Thanks for any answsers.


Dreamora(Posted 2010) [#2]
1. Problem is that 255+1 = 0 so its again within the valid range and it will just loop forever. This is known. Either you restrict it to 0 - 254 or use a larger datatype

2. process manager helps you, just kill the bmk (ctrl-shift-esc opens the process manager directly)

3. while you move the window, it will become corrupt but should be fine afterwards when you stop dragging it.

4. numerics are default initialized at 0, strings at "" and objects at null


Arabia(Posted 2010) [#3]
Thanks Dreamora.

1. So this is an issue/bug? I don't think i've encounted this in other languages I've used, but it's been a long time. I guess saving a byte of memeory by using a byte instead of an int is neither here nor there really.

2. I couldn't even get process manager going when in Blide, but could in MaxIDE.

3. Yep, works fine now. Am positive it wasn't working before. Maybe an issue with free memory maybe? Had lots of stuff open at the time, and not reset the laptop for a while. Could have also caused the issue I was having in point 2 maybe.

4. Thanks, thought this was the case. I had memories of a programming course I did nearly 20 years ago where the lecturer told us to always initialise variables.


ziggy(Posted 2010) [#4]
1 Using Ints instead of bytes is faster on modern CPUs, and usually minimum data allocation is 16 or 32 bytes, so you are not really using less resources.

2 When a graphics context is created fullscreen on windows. The OS sometimes lets you switch to the task manager but sometimes it does not. This has nothing to do with being running BLIde, MaxIDE, Internet explorer or any other application. They're separated processes. In the other hand, BLIde, as oposite to the default MaxIDE, will try automatic recovering after some seconds (usually between 15-20) or any unhandled exception in the game being debugged. Anyway, it is not recommended (in any ide) to debug using a fullscreen graphics context, unless you have several monitors. Anyway, when BLIde detects a crash, it'll play a sound and wait 15 seconds before stopping the application and displaying any available debug information.

3.- What Dreamora said. Making the window redraw while you drag it is not a trivial task (it envolves Events or threads). Modern windows versions with AEREO on do not produce this issue (Vista and Win7 default desktop).

4.- What Dreamora said.


Dreamora(Posted 2010) [#5]
1. No not a bug, just how it works. The loop variable is raised and then checked if it is valid basically. As it will always remain valid, you will never get out there again.

2. Thats not possible technically at all, assuming you are on XP or Vista / Win7. What though can happen is that it takes 10s+ depending on your hardware. (if you flood the cpu it will first have to dig out that flood to see the process manager request basically).
I normally have it minimized open while developing, then you can alt-tab into it that will normally ensure that it will work as it has the highest process priority.

3. screen corruption sounds more like an issue with Vista / Win 7 + your driver and having too little VRAM. Especially in case you have an intel onboard, you will be facing such things as Intels are the only ones to create even worse drivers than ATI

4. hehe C / C++ are still like that, so not much about 20 years ago ;) But modern languages do default inits simply because they have no "hunt in the wild" pointers anymore at all, they need something to point to and just use that step to have a defined state.


Arabia(Posted 2010) [#6]
Thanks ziggy.

The problem wasn't an unhaddled exception, Blide has handled these perfectly for me. It was being caught in an infinite loop during full screen, though I'm not entirely sure why I put into full screen anyway :)

Back to one of my other questions, can you somehow have an event (like the old DOS TSR programs used) to capture a defined hotkey and end the program regardless? I'm sure I read something about this somewhere, like how events work in GUI modules.


ziggy(Posted 2010) [#7]
Well, it won't be very automatic, but you can always check for a KeyHit(Key_Escape) in your main loop. A way to 'stop' program execution from MaxIDE (or BLIde) has been requested several times to Mark but it has not happened (yet?) It would be great to have a PAUSE button in the IDEs to handle this scenarios...


Arabia(Posted 2010) [#8]
Cheers for the added info Dreamora.

My laptop is the cheapest, nastiest one I could get my hands on. It is not for playing games on, just really for when I don't have access to my PC - it wouldn't surpise me if it is driver/onboard vid issues - and yes it is an Intel chipset onboard. I am using XP on this by the way.


Arabia(Posted 2010) [#9]
Yep, well aware of the keyhit, keydown functions ziggy. The original problem came about from something that as a) unnecessary and b) not in the main loop.

Thanks for the help guys, I'll keep going with what I'm doing - hopefully I'll have some screen shots or maybe a vid to show later in the week.

Not doing anything too special, just seeing if I can make a simple remake/variation of an old 8bit game called Tornado Low Level. Working on a map editor at the momemnt (I know some exist already), but I'm learning heaps and stuff that I'll need later on in the game


Arabia(Posted 2010) [#10]
p.s. If I can find the energy to keep programming when I am back at work, I'll definately look at purchasing BLIde. Very nice ziggy :)


Taron(Posted 2010) [#11]
I can highly recommend it, too! It's next to impossible to work without BLide. :}

Events won't protect you from infinite loops, I'm afraid. At least not that I know of. But using hooks can let your app react to window events like moving and resizing, for example, if you use them properly.

Besides, write: for x = 0 until 255



Arabia(Posted 2010) [#12]
Thanks Taron, hooks were what I was thinking of, but I haven't got around to seeing how they work/what they do just yet.

I will try and remember the "Until" keyword, but I think I'm too old to remember it - been using For..To...Next for too long :D


Taron(Posted 2010) [#13]
HAHAHA, you're funny! I like that a lot! ;}

UNTIL is pretty useful at times. I'm generating my own images in the code very often and it's somehow cleaner to set a size and then loop UNTIL the size and not TO size-1. But that's just one example.

Hooks are super easy, really... just takes a moment to recognize it, hihihi. Here:


Besides, take you time getting into the syntax, really. Piece by piece and fully relaxed. It's a very good idea to learn about EVENTS. They are very easy to deal with, but become your control center and stay with you for a long time. Here and there I do things without them, but it's really too good a way to stay organized and also interact with the rest of the desktop. The BlitzMax Help is documenting them well. Here and there I print the event IDs to find out what's REALLY going on and what the OS gives you back. Can be very interesting. But that's probably not the best of crossplatform development.


Arabia(Posted 2010) [#14]
Okay, that hook stuff is a little confusing at the moment, but thanks - will come back to this and have a look.