Why isn't this working?

BlitzMax Forums/BlitzMax Beginners Area/Why isn't this working?

sswift(Posted 2006) [#1]
Local A:Int[10000]

StartTime = MilliSecs()

For Loop = 1 To 1000

	For Y = 1 To 100
		For X = 1 To 100
			A[Y*100 + X] = 10
		Next
	Next
Next

EndTime = MilliSecs()

Print "Totaltime = " + (StartTime-EndTime)

WaitKey()

I build and run the program, and it compiles sucessfully, but I see no output, and it does not wait for a key to finish.


/edit

Nevermind, I think I figured it out. I have to use the graphics command to enable polled input. It would have been nice if the WaitKey() help said that polled input had to be anabled to use it, but I guess they figure that I should have to look at the top of each help page when looking at the help for a command to be absolutely sure there's no little dependencies I should be aware of.

That said, why in the hell did Mark make 60 the default setting for Hz in the graphics command? Shouldn't it defualt to not screwing with the monitor's default refresh rate? Is Mark not aware that you have to set your monitor up for every reolsution and refresh rate, and that people will probably have weird vertically or horizontally squished screens when the game changes to a special refresh rate for a particular resolution, and it hasn't been set up on the PC yet? Also, some people don't have their PC configured properly, and windows might think their monitors are capable of 100hz at 1600x1200 and they're not, and the monitor goes boom. Bad form setting the refresh rate on people. Commercial games have been released that do that and I think the guy at Voodoo Extreme had one break his monitor.

/edit2

Aww man... And the IDE still has this stupid tendancy to copy the font settings when text is copied from the help file, so I can't copy and paste commands and then fill in the parameters still. Augh!

/edit3

Does the graphics command default to 0 for depth, or 16? The help says 0. The Wiki says 16. And neither says what a value of 0 will do. I'm hoping it will use the color depth of the desktop, but I suspect that it just does 16bit by default.

/edit4

Wtf? Even with the graphics command, while I do get it to print something, it still doesn't wait for a key. It just exits immediately!


sswift(Posted 2006) [#2]
So here's the current code that doesn't work:

Graphics(640, 480, 0, 0, 0)

Local A:Int[10000]

StartTime = MilliSecs()

For Loop = 1 To 1000

	For Y = 1 To 100
		For X = 1 To 100
			A[Y*100 + X] = 10
		Next
	Next
Next

EndTime = MilliSecs()

Print "Totaltime = " + (EndTime-StartTime)

WaitKey()


The problem is it does not halt program execution at WaitKey()


sswift(Posted 2006) [#3]
ARGGHHHHH!

This code works just fine and prints text to the output window:

Rem
Millisecs is useful for seeding the random number generator.
End Rem

SeedRnd(MilliSecs())

For i=1 To 10
	Print Rnd()
Next



This code does not:

Local A:Int[10000]

StartTime = MilliSecs()

For Loop = 1 To 1000

	For Y = 1 To 100
		For X = 1 To 100
			A[Y*100 + X] = 10
		Next
	Next
Next

EndTime = MilliSecs()

Print "Totaltime = " + (EndTime-StartTime)



Yan(Posted 2006) [#4]
The graphics command depth defaults to 0, which is windowed and therefore at whatever bit depth your desk top is set to.


sswift(Posted 2006) [#5]
I think I found the problem. I wasn't compiling in the debug build, and I was writing outside the bounds of the array because I accidentally started Y and X at 1 instead of 0.

But why Blitzmax did not throw an error message up saying that I was trying to access memory I wasn't suppposed to or something, I have no idea. It only does it when I run it in debug mode.

I don't expect it to do bounds checking when not in debug mode, but when other programs I run crash cause they try to access memory they're not supposed to, I get an error, that at the very least, tells me the program crashed.

Max just exits, so I don't know that it is exiting because I have screwed up, and not because it's not polling for keyboard input.


sswift(Posted 2006) [#6]
"The graphics command depth defaults to 0, which is windowed and therefore at whatever bit depth your desk top is set to."

Thanks. That seems like very important information that should be in either the help file or the Wiki!

I'd add it to the Wiki myself, but when I go to edit an entry, the text has all these '' things around it and I don't know what they do, so I didn't want to screw with it.


Yan(Posted 2006) [#7]
1) Run it with debug enabled. :o)

2) Arrays are zero indexed in BMax (as they should be!)...
Local A:Int[10000]

StartTime = MilliSecs()

For Loop = 1 To 1000

	For Y = 0 To 99
		For X = 0 To 99
			A[Y*100 + X] = 10
		Next
	Next
Next

EndTime = MilliSecs()

Print "Totaltime = " + (EndTime-StartTime)


[edit]
LOL...That's the second time you've done that! ;o)
[/edit]


assari(Posted 2006) [#8]
I ran your code and it worked first time (did not do waitkey though). Then turning on debug mode caught this error for me. Don't understand why it ran in non-debug mode


Yan(Posted 2006) [#9]
As for the graphics command refresh rate, it's changed a few times over the different versions and I'm a bit confused as to what's what now. :o/

I think 'Graphics width, height, depth, -1' should set the default refresh rate at that particular res (unless depth is 0, of course), with it falling back to 60Hz if it fails.

[edit]
I also believe that this behaviour is different between GL and DX (the APIs fault, not BRL's).
[/edit]


skidracer(Posted 2006) [#10]
I use Input instead of WaitKey when doing command line stuff.

In regards to the docs, it is helpful that you are pointing out areas that need work, so thanks for that and please try and understand the undertaking it has been for the two of us to get BlitzMax to where it is currently.


sswift(Posted 2006) [#11]
Bill:
"2) Arrays are zero indexed in BMax (as they should be!)..."

I totally agree. In fact, I made it a practice to always pretend arrays went from 0..Size-1 in other versions of Blitz because I didn't want to get sloppy and run into problems like this later. I can only chalk this error up to my being unfamiliar with the language, and making dumb mistakes as a result of having my mind on other aspects of what I was doing. :-)


sswift(Posted 2006) [#12]
Skid:
I know it is a lot of work, and you're running a small operation here. It's just frustrating. I'm just pointing out the problems so they can get fixed at some point, or so that some new user reading my posts will be able to learn the ropes along with me. :-)


Now... About that WaitKey(). It's still not working. I'm getting it to bring up the fullscreen graphics mode, but it still exits. Am I not allowed to use Print in fullscreen graphics mode? I wasn't in Blitzplus.

I had to reboot my PC once recently when I tried to print while in graphics mode in BP because it kept flipping back and forth between the desktop and fullscreen and I could not manage to see the process window so I could shut the process down, and I had not included a key check to make it exit.


skidracer(Posted 2006) [#13]
Print was causing the IDE output window to activate (causing full screen to lose focus) but this should have been fixed in a recent release.


tonyg(Posted 2006) [#14]

In regards to the docs, it is helpful that you are pointing out areas that need work, so thanks for that and please try and understand the undertaking it has been for the two of us to get BlitzMax to where it is currently.



Though it should hardly come as a shock as many people have said on many occasions that much of the documentation is lacking.
How about getting somebody else to revise the doc?
Run a competition selecting a few commands per week and the best definition and example gets put in the doc.


Dreamora(Posted 2006) [#15]
On the "why it ran in non-debug"

The array boundary checking is done through a module, not by the compiler or anything and this module is only linked in debug build!


sswift(Posted 2006) [#16]
Dreamora:
I know that. What I meant was, other windows apps will bring up a window saying the program has caused an exception error when they crash. But Max just exits with no explanation why it exited. Because of this, I can't tell if it exited because I wrote somewhere I shouldn't have, or because GetKey wasn't getting the key, or because it could not print without a graphics mode being set. A crash dialog would have provided that little bit of extra info that told me it wasn't GetKey which was the primary issue.


skidracer(Posted 2006) [#17]
I don't think memory exceptions are that simple, on my system this cauases a memory exception in release mode:
Local a[1]
a[50000000]=20

and this doesn't
Local a[1]
a[5000000]=20


hmmm, you might be right Sswift, having a quick look at appstub.win32.c it does look like we might be catching more than we should in release mode in regards to system memory exceptions.