Fatal Exception

Started by Calin Leafshade, Wed 10/12/2014 20:36:34

Previous topic - Next topic

Calin Leafshade

I'm getting this error:

---------------------------
Illegal exception
---------------------------
An exception 0xC0000005 occurred in ACWIN.EXE at EIP = 0x004DC2AC ; program pointer is -42, ACI version 3.4.0.2, gtags (73,24)

AGS cannot continue, this exception was fatal. Please note down the numbers above, remember what you were doing at the time and post the details on the AGS Technical Forum.

in "Utilties.asc", line 50
from "Utilties.asc", line 96


Most versions of Windows allow you to press Ctrl+C now to copy this entire message to the clipboard for easy reporting.

An error file CrashInfo.dmp has been created. You may be asked to upload this file when reporting this problem on the AGS Forums. (code 0)
---------------------------
OK   
---------------------------

Looks like it might be some scoping issue with nested for loops.

It happens in this function: (I will mark line 50)

Code: ags

function writeSpriteFont(int fontNum) {
	String fontstring = "";
    int i = 32;
	for(i=32;i <= 126; i++){
		fontstring = fontstring.Append(String.Format("%c", i));
	}
	int w = GetTextWidth(fontstring, fontNum) + 5;
	int h = GetTextHeight(fontstring, fontNum, w) + 2;
	DynamicSprite *s = DynamicSprite.Create(w * 2,h);
	DrawingSurface *ds = s.GetDrawingSurface();
	Rectangle* rects[] = new Rectangle[127];
	String metrics = "";
	ds.Clear();
	ds.DrawingColor = 15;
	int x = 0;
	for(i=32; i<=126; i++) {
		ds.DrawString(x,0,fontNum,String.Char(i));
		int ww = GetTextWidth(String.Char(i), fontNum);
		rects[i] = Rectangle.Create(x,0,ww,h);
		x += ww;
	}
	
	int top = -1;
    int y = 0;
    
	for(y = 0; y <= h - 1; y++)
    {
		for(x = 0; x <= w-1; x++) {
			int p = ds.GetPixel(x,y);
			if (p != COLOR_TRANSPARENT) {
				top = y;
				break;
            }
		}
		if(top > -1) {
			break;
		}
    }
	
	int bottom = -1;
    int start = 3;
    if (top > -1) {
        start = top;
    }
	for(y = start; y < h; y++) {
		bool found = false;
		for(x = 0; x < w; x++) {
                        Display("%d %d %d %d", x,  y,  ds.Width,  ds.Height); // <-- THIS LINE WILL ALSO CRASH IT.       
			int p = ds.GetPixel(x,y); // <-- THIS WAS THE OFFENDING LINE
			if(p != COLOR_TRANSPARENT) {
				found = true;
				break;
			}
		}
		if (!found) {
			bottom = y;
			break;
		}
	}
	
	ds.Release();
	
	if (top > 0) {
		s.Crop(0,top,w,h);
		for(i = 0; i < 127; i++) {
            if (rects[i] != null) {
                rects[i].y = top;
            }
		}
	}
	
	if (bottom > 0) {
		s.Crop(0,0,w,bottom - top);
		for(i = 0; i < 127; i++) {
            if (rects[i] != null) {
                rects[i].height = s.Height;
            }
		}
	}
	
    s.SaveToFile("spritefont.bmp");
    
	//now build metrics
    File *f = File.Open("metrics.txt",eFileWrite);
    for(i = 0; i < 127; i++) {
        if (rects[i] != null) {
            f.WriteRawLine(String.Format("SetGlyph(%d, %d, %d, %d, %d, %d);[", fontNum, i,  rects[i].x, rects[i].y,rects[i].width,rects[i].height));
        }
    }
	f.Close();
	
}


EDIT: Ok no, it's a compiler issue. If i define "p" earlier in the script then it works. Seems that the compiler allows int p to be defined twice (I thought it would be allowed because they are different scopes (in other languages))

SMF spam blocked by CleanTalk