Fix crash on app exit

This commit is contained in:
Joey Yakimowich-Payne 2018-07-05 11:53:55 +09:00
commit 41ccfa39df
5 changed files with 44 additions and 6 deletions

View file

@ -1,7 +1,6 @@
import sets, strutils import sets, strutils
import libnx/graphics import libnx/graphics
import libnx/wrapper/hid import libnx/wrapper/con
import libnx/wrapper/console
import libnx/ext/integer128 import libnx/ext/integer128
import libnx/account import libnx/account
import libnx/input import libnx/input
@ -38,7 +37,6 @@ proc main() =
echo msg echo msg
mainLoop: mainLoop:
let keysDown = keysDown(Controller.P1_AUTO) let keysDown = keysDown(Controller.P1_AUTO)

View file

@ -1,10 +1,11 @@
import sets import sets
import libnx/graphics import libnx/graphics
import libnx/wrapper/console import libnx/wrapper/con
import libnx/wrapper/hid import libnx/wrapper/hid
import libnx/app import libnx/app
import libnx/input import libnx/input
proc main() = proc main() =
initDefault() initDefault()
discard consoleInit(nil) discard consoleInit(nil)

View file

@ -1,6 +1,6 @@
# Package # Package
version = "0.1.2" version = "0.1.3"
author = "Joey Payne" author = "Joey Payne"
description = "Nintendo Switch library libnx for Nim." description = "Nintendo Switch library libnx for Nim."
license = "The Unlicense" license = "The Unlicense"

View file

@ -22,6 +22,10 @@ filter=lock
"${output}/nim.cfg" "${output}/nim.cfg"
"${output}/config.nims" "${output}/config.nims"
[n.wildcard]
wildcard = "console.h"
rename = "$replace(console=con)"
[n.prepare] [n.prepare]
git = "https://github.com/switchbrew/libnx" git = "https://github.com/switchbrew/libnx"
execute = """ execute = """
@ -323,3 +327,32 @@ search.o = "import libnx"
prepend.o = """ prepend.o = """
import libnx/ext/integer128 import libnx/ext/integer128
""" """
[con.nim]
search.o = "type\n"
prepend.o = """
template CONSOLE_ESC*(x: string): string = "\x1b[" & $x
# Colors
template CONSOLE_RESET*: string = CONSOLE_ESC("0m")
template CONSOLE_BLACK*: string = CONSOLE_ESC("30m")
template CONSOLE_RED*: string = CONSOLE_ESC("31;1m")
template CONSOLE_GREEN*: string = CONSOLE_ESC("32;1m")
template CONSOLE_YELLOW*: string = CONSOLE_ESC("33;1m")
template CONSOLE_BLUE*: string = CONSOLE_ESC("34;1m")
template CONSOLE_MAGENTA*: string = CONSOLE_ESC("35;1m")
template CONSOLE_CYAN*: string = CONSOLE_ESC("36;1m")
template CONSOLE_WHITE*: string = CONSOLE_ESC("37;1m")
# Styles
template CONSOLE_COLOR_BOLD*: int = (1 shl 0)
template CONSOLE_COLOR_FAINT*: int = (1 shl 1)
template CONSOLE_ITALIC*: int = (1 shl 2)
template CONSOLE_UNDERLINE*: int = (1 shl 3)
template CONSOLE_BLINK_SLOW*: int =(1 shl 4)
template CONSOLE_BLINK_FAST*: int = (1 shl 5)
template CONSOLE_COLOR_REVERSE*: int = (1 shl 6)
template CONSOLE_CONCEAL*: int = (1 shl 7)
template CONSOLE_CROSSED_OUT*: int = (1 shl 8)
"""

View file

@ -54,14 +54,20 @@ var enabled = false
proc initDefault*() = proc initDefault*() =
if not enabled: if not enabled:
gfxInitDefault() gfxInitDefault()
enabled = true enabled = true
## * ## *
## @brief Uninitializes the graphics subsystem. ## @brief Uninitializes the graphics subsystem.
## @warning Do not use \ref viExit when using this function. ## @warning Do not use \ref viExit when using this function.
## ##
proc exit*() = proc exit*() =
# XXX Important!!! This deallocHeap call must be here
# in order for the switch not to crash. It must be run right
# before gfxExit() to leave a clean slate in the OS. This call
# will disable any further allocations and free all consumed
# memory on the heap.
if enabled: if enabled:
deallocHeap(runFinalizers = true, allowGcAfterwards = false)
gfxExit() gfxExit()
enabled = false enabled = false