Always diplay sad face on errors; use nullCheck() function; see https://github.com/Microsoft/pxt/issues/302
This commit is contained in:
		@@ -13,6 +13,25 @@ namespace pxsim {
 | 
				
			|||||||
        U.assert(!runtime.board);
 | 
					        U.assert(!runtime.board);
 | 
				
			||||||
        let b = new DalBoard();
 | 
					        let b = new DalBoard();
 | 
				
			||||||
        runtime.board = b;
 | 
					        runtime.board = b;
 | 
				
			||||||
 | 
					        runtime.postError = (e) => {
 | 
				
			||||||
 | 
					            led.setBrightness(255);
 | 
				
			||||||
 | 
					            let img = board().ledMatrixState.image;
 | 
				
			||||||
 | 
					            img.clear();
 | 
				
			||||||
 | 
					            img.set(0, 4, 255);
 | 
				
			||||||
 | 
					            img.set(1, 3, 255);
 | 
				
			||||||
 | 
					            img.set(2, 3, 255);
 | 
				
			||||||
 | 
					            img.set(3, 3, 255);
 | 
				
			||||||
 | 
					            img.set(4, 4, 255);
 | 
				
			||||||
 | 
					            img.set(0, 0, 255);
 | 
				
			||||||
 | 
					            img.set(1, 0, 255);
 | 
				
			||||||
 | 
					            img.set(0, 1, 255);
 | 
				
			||||||
 | 
					            img.set(1, 1, 255);
 | 
				
			||||||
 | 
					            img.set(3, 0, 255);
 | 
				
			||||||
 | 
					            img.set(4, 0, 255);
 | 
				
			||||||
 | 
					            img.set(3, 1, 255);
 | 
				
			||||||
 | 
					            img.set(4, 1, 255);
 | 
				
			||||||
 | 
					            runtime.updateDisplay();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (!pxsim.initCurrentRuntime) {
 | 
					    if (!pxsim.initCurrentRuntime) {
 | 
				
			||||||
        pxsim.initCurrentRuntime = initRuntimeWithDalBoard;
 | 
					        pxsim.initCurrentRuntime = initRuntimeWithDalBoard;
 | 
				
			||||||
@@ -195,8 +214,10 @@ namespace pxsim.visuals {
 | 
				
			|||||||
        txtYOffFactor = txtYOffFactor || 0.3;
 | 
					        txtYOffFactor = txtYOffFactor || 0.3;
 | 
				
			||||||
        const xOff = txtXOffFactor * size * txt.length;
 | 
					        const xOff = txtXOffFactor * size * txt.length;
 | 
				
			||||||
        const yOff = txtYOffFactor * size;
 | 
					        const yOff = txtYOffFactor * size;
 | 
				
			||||||
        svg.hydrate(el, {style: `font-size:${size}px;`,
 | 
					        svg.hydrate(el, {
 | 
				
			||||||
            transform: `translate(${cx} ${cy}) rotate(${rot}) translate(${xOff} ${yOff})` });
 | 
					            style: `font-size:${size}px;`,
 | 
				
			||||||
 | 
					            transform: `translate(${cx} ${cy}) rotate(${rot}) translate(${xOff} ${yOff})`
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
        svg.addClass(el, "noselect");
 | 
					        svg.addClass(el, "noselect");
 | 
				
			||||||
        el.textContent = txt;
 | 
					        el.textContent = txt;
 | 
				
			||||||
        return el;
 | 
					        return el;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -195,26 +195,24 @@ namespace pxsim.images {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace pxsim.ImageMethods {
 | 
					namespace pxsim.ImageMethods {
 | 
				
			||||||
    export function showImage(leds: Image, offset: number) {
 | 
					    export function showImage(leds: Image, offset: number) {
 | 
				
			||||||
        if (!leds) panic(PanicCode.MICROBIT_NULL_DEREFERENCE);
 | 
					        pxtrt.nullCheck(leds)
 | 
				
			||||||
 | 
					 | 
				
			||||||
        leds.copyTo(offset, 5, board().ledMatrixState.image, 0)
 | 
					        leds.copyTo(offset, 5, board().ledMatrixState.image, 0)
 | 
				
			||||||
        runtime.queueDisplayUpdate()
 | 
					        runtime.queueDisplayUpdate()
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    export function plotImage(leds: Image, offset: number): void {
 | 
					    export function plotImage(leds: Image, offset: number): void {
 | 
				
			||||||
        if (!leds) panic(PanicCode.MICROBIT_NULL_DEREFERENCE);
 | 
					        pxtrt.nullCheck(leds)
 | 
				
			||||||
 | 
					 | 
				
			||||||
        leds.copyTo(offset, 5, board().ledMatrixState.image, 0)
 | 
					        leds.copyTo(offset, 5, board().ledMatrixState.image, 0)
 | 
				
			||||||
        runtime.queueDisplayUpdate()
 | 
					        runtime.queueDisplayUpdate()
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    export function height(leds: Image): number {
 | 
					    export function height(leds: Image): number {
 | 
				
			||||||
        if (!leds) panic(PanicCode.MICROBIT_NULL_DEREFERENCE);
 | 
					        pxtrt.nullCheck(leds)
 | 
				
			||||||
        return Image.height;
 | 
					        return Image.height;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    export function width(leds: Image): number {
 | 
					    export function width(leds: Image): number {
 | 
				
			||||||
        if (!leds) panic(PanicCode.MICROBIT_NULL_DEREFERENCE);
 | 
					        pxtrt.nullCheck(leds)
 | 
				
			||||||
        return leds.width;
 | 
					        return leds.width;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -227,35 +225,32 @@ namespace pxsim.ImageMethods {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    export function pixel(leds: Image, x: number, y: number): number {
 | 
					    export function pixel(leds: Image, x: number, y: number): number {
 | 
				
			||||||
        if (!leds) panic(PanicCode.MICROBIT_NULL_DEREFERENCE);
 | 
					        pxtrt.nullCheck(leds)
 | 
				
			||||||
        return leds.get(x, y);
 | 
					        return leds.get(x, y);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    export function setPixel(leds: Image, x: number, y: number, v: number) {
 | 
					    export function setPixel(leds: Image, x: number, y: number, v: number) {
 | 
				
			||||||
        if (!leds) panic(PanicCode.MICROBIT_NULL_DEREFERENCE);
 | 
					        pxtrt.nullCheck(leds)
 | 
				
			||||||
        leds.set(x, y, v);
 | 
					        leds.set(x, y, v);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    export function clear(leds: Image) {
 | 
					    export function clear(leds: Image) {
 | 
				
			||||||
        if (!leds) panic(PanicCode.MICROBIT_NULL_DEREFERENCE);
 | 
					        pxtrt.nullCheck(leds)
 | 
				
			||||||
 | 
					 | 
				
			||||||
        leds.clear();
 | 
					        leds.clear();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    export function setPixelBrightness(i: Image, x: number, y: number, b: number) {
 | 
					    export function setPixelBrightness(i: Image, x: number, y: number, b: number) {
 | 
				
			||||||
        if (!i) panic(PanicCode.MICROBIT_NULL_DEREFERENCE);
 | 
					        pxtrt.nullCheck(i)
 | 
				
			||||||
 | 
					 | 
				
			||||||
        i.set(x, y, b);
 | 
					        i.set(x, y, b);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    export function pixelBrightness(i: Image, x: number, y: number): number {
 | 
					    export function pixelBrightness(i: Image, x: number, y: number): number {
 | 
				
			||||||
        if (!i) panic(PanicCode.MICROBIT_NULL_DEREFERENCE);
 | 
					        pxtrt.nullCheck(i)
 | 
				
			||||||
 | 
					 | 
				
			||||||
        return i.get(x, y);
 | 
					        return i.get(x, y);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    export function scrollImage(leds: Image, stride: number, interval: number): void {
 | 
					    export function scrollImage(leds: Image, stride: number, interval: number): void {
 | 
				
			||||||
        if (!leds) panic(PanicCode.MICROBIT_NULL_DEREFERENCE);
 | 
					        pxtrt.nullCheck(leds)
 | 
				
			||||||
        if (stride == 0) stride = 1;
 | 
					        if (stride == 0) stride = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let cb = getResume();
 | 
					        let cb = getResume();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,24 +19,6 @@ namespace pxsim {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    export function panic(code: number) {
 | 
					    export function panic(code: number) {
 | 
				
			||||||
        console.log("PANIC:", code)
 | 
					        console.log("PANIC:", code)
 | 
				
			||||||
        led.setBrightness(255);
 | 
					 | 
				
			||||||
        let img = board().ledMatrixState.image;
 | 
					 | 
				
			||||||
        img.clear();
 | 
					 | 
				
			||||||
        img.set(0, 4, 255);
 | 
					 | 
				
			||||||
        img.set(1, 3, 255);
 | 
					 | 
				
			||||||
        img.set(2, 3, 255);
 | 
					 | 
				
			||||||
        img.set(3, 3, 255);
 | 
					 | 
				
			||||||
        img.set(4, 4, 255);
 | 
					 | 
				
			||||||
        img.set(0, 0, 255);
 | 
					 | 
				
			||||||
        img.set(1, 0, 255);
 | 
					 | 
				
			||||||
        img.set(0, 1, 255);
 | 
					 | 
				
			||||||
        img.set(1, 1, 255);
 | 
					 | 
				
			||||||
        img.set(3, 0, 255);
 | 
					 | 
				
			||||||
        img.set(4, 0, 255);
 | 
					 | 
				
			||||||
        img.set(3, 1, 255);
 | 
					 | 
				
			||||||
        img.set(4, 1, 255);
 | 
					 | 
				
			||||||
        runtime.updateDisplay();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        throw new Error("PANIC " + code)
 | 
					        throw new Error("PANIC " + code)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user