Skip to content

Commit 5b3d7a1

Browse files
committed
Fixed certain Fonts crashing
1 parent 836aad0 commit 5b3d7a1

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

Examples/Tetris.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Tetris : ConsoleGame {
2727
bool gameover = false;
2828

2929
private static void Main(string[] args) {
30-
new Tetris().Construct(fieldWidth+2, fieldHeight + 4, 8, 8, FramerateMode.MaxFps);
30+
new Tetris().Construct(fieldWidth + 2, fieldHeight + 4, 8, 8, FramerateMode.MaxFps);
3131
}
3232
public override void Create() {
3333
Engine.SetPalette(Palettes.Pico8);

Source/ConsoleEngine.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,31 +36,31 @@ public class ConsoleEngine {
3636
/// <param name="fontH">Target font height.</param>
3737
public ConsoleEngine(int width, int height, int fontW, int fontH) {
3838
if (width < 1 || height < 1) throw new ArgumentOutOfRangeException();
39-
if (fontW < 2 || fontH < 2) throw new ArgumentOutOfRangeException();
39+
if (fontW < 1 || fontH < 1) throw new ArgumentOutOfRangeException();
4040

41-
Console.Title = "Untitled application";
41+
Console.Title = "Untitled console application";
4242
Console.CursorVisible = false;
43+
Console.SetBufferSize(width, height);
4344

4445
ConsoleBuffer = new ConsoleBuffer(width, height);
4546

4647
WindowSize = new Point(width, height);
4748
FontSize = new Point(fontW, fontH);
4849

49-
// Stänger av alla standard ConsoleInput metoder (Quick-edit etc)
50-
NativeMethods.SetConsoleMode(stdInputHandle, 0x0080);
51-
// Sätter fontstorlek och tvingar Consolas
52-
ConsoleFont.SetFont(stdOutputHandle, (short)fontW, (short)fontH);
53-
54-
Console.SetWindowSize(width, height);
55-
Console.SetBufferSize(width, height);
56-
5750
CharBuffer = new char[width, height];
5851
ColorBuffer = new int[width, height];
5952

6053
SetBackground(0);
6154
SetPalette(Palettes.Default);
6255

63-
// sätter igen, idk men det behövs
56+
// Stänger av alla standard ConsoleInput metoder (Quick-edit etc)
57+
NativeMethods.SetConsoleMode(stdInputHandle, 0x0080);
58+
59+
// Sätter fontstorlek och tvingar Raster (Terminal)
60+
// Detta måste göras efter SetBufferSize, annars ger den en IOException
61+
ConsoleFont.SetFont(stdOutputHandle, (short)fontW, (short)fontH);
62+
// sätter storleken på fönstret, måste ske efter SetBufferSize för annars
63+
// blir fönstret 1 px större (?)
6464
Console.SetWindowSize(width, height);
6565
}
6666

Source/ConsoleFont.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
using System;
33
using System.Runtime.InteropServices;
44

5-
using System.Drawing;
6-
75
class ConsoleFont {
86

97

@@ -20,10 +18,10 @@ internal static int SetFont(IntPtr h, short sizeX, short sizeY) {
2018
cfi.dwFontSize.X = sizeX;
2119
cfi.dwFontSize.Y = sizeY;
2220

23-
// forcerar font till Terminal (Raster)
21+
// sätter font till Terminal (Raster)
2422
cfi.FaceName = "Terminal";
2523

26-
NativeMethods.SetCurrentConsoleFontEx(h, true, ref cfi);
24+
NativeMethods.SetCurrentConsoleFontEx(h, false, ref cfi);
2725
return 0;
2826
}
2927
}

0 commit comments

Comments
 (0)