Skip to content
Robert Konrad edited this page Apr 9, 2020 · 13 revisions

Supported defaults:

When creating a new project if you use the Kha: Init Project in vscode or kodestudio, a launch.json will be created to enable debugging on two targets:

  • HTML5
  • Krom

When using the default debugging created by the command, the HTML5 target will use vscode-electron-debug. This entails that the debugging is done with electron.

For Krom, it will use the version of Krom defined by the Krom setting in Kode Studio or vscode. It defaults to a built-in version.

Debugging with native targets:

Kha directly supports numerous C/C++ IDEs (Visual Studio, Xcode, Clion, Code::Blocks,...) depending on the target system. A project file is created in the build/{target} subdirectory which can be opened and used for debugging directly.

Custom setups:

As of the time of writing this, the most supported default debugging scheme is using HTML5. But you can debug on other targets more easily when configuring things by yourself. These are the ways people from the community have been able to setup debug setup's for different targets. If ever you found a better way to do it we invite you to share for others.

A note on your launch configs:

Since khamake auto generates launch tasks, the way it does it is by parsing the launch.json file and overwrites these launch config's. For custom setups this means you can't name your launch task with the name Kha: at the start of it's name field because it will be removed from your launch.json file by khamake.

Debugging with Chrome:

If your end target is browsers and you would like to see how your game runs in the browser these steps can help you to setup this debug environment in vscode.

First, we need to install Debugger for Chrome extension from the vcsode extension's marketplace.

You will need a way to have a local server, any should do. For this example we used the http-server package on npm. To install it do npm install http-server -g.

After setting this up we now need to create a tasks.json file in our .vscode folder to start our server:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558 
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Start Server",
            "type": "shell",
            "command": "npx",
            "args": [
                "http-server",
                "${workspaceFolder}/build/html5"
            ],
        }
    ]
}

In your launch.json add a config like so:

{
            "type": "chrome",
            "request": "launch",
            "name": "HTML5 - Chrome",
            "windows": {
                "runtimeExecutable": "path\\to\\chrome.exe"
            },
            "linux": {
                "runtimeExecutable": "/path/to/chrome"
            },
            "runtimeArgs": [
                "--disable-web-security",
                "--allow-insecure-localhost"
            ],
            "url": "http://localhost:8080",
            "webRoot": "${workspaceFolder}/build/html5",
            "preLaunchTask": "Kha: Build for HTML5"
        }

Since we are using "preLaunchTask": "Kha: Build for HTML5" as our preLaunchTask the source map to debug our code won't be generated. To enable the source map generation add this line project.addParameter("-debug") to your khafile.js.

When you are ready to debug your app you can press F5(make sure you selected the right run task in the debug view). Chrome will open.

If your server wasn't started prior, go to the Terminal->Run Task option in vscode and choose the Start Server task's. If the browser doesn't automatically reload just reload the local host page and you should be fine. The server will close itself when you quit vscode or you manually exit it by pressing Ctrl-c in it's terminal view in vscode.

Debugging with Krom - Attach:

Explanations coming soon....

tasks.json:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558 
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Krom Build&Launch",
            "type": "shell",
            "command": "/home/jsnadeau/Kromx/Deployment/Krom",
            "args": ["${workspaceRoot}/build/krom/","${workspaceRoot}/build/krom-resources/","--debug","--watch"],
            "dependsOrder": "sequence",
            "dependsOn":[
                "Kha: Build for Krom",
                "setpath"
            ]

        },
        {
            "label": "setpath",
            "type": "shell",
            "command": "cd",
            "args": ["${workspaceRoot}/build/"],
        }
    ]
}

launch.json config:

      {
            "type": "krom",
            "request": "attach",
            "name": "Krom - Attach",
            "preLaunchTask": "Krom Build&Launch",
            "port": 0
        },