Game Development Community

TGE Crashes with CreateCanvas()

by Johnathon · in Technical Issues · 11/07/2007 (5:19 pm) · 1 replies

When I use the following code.

main.cs
//Enable detailed logging
trace(true);

//Force the console to be displayed since we don't have a canvas yet.
enableWinConsole(true);

$gameName = "MyGame";

// Help won't be displayed unless the command line
// switch (-h) is used.
$showHelp = false;

$logModeEnabled = true; //Track the logging state we set in the lext line.
SetLogMode(2); //Create a new log file

//Any last gasp exit code we want executed can be performed here.
function OnExit()
{
}

function OnStart()
{
}

function ParseArgs()
{
	//Loop through all the command line arguments.
	for ($i = 1; $i < $Game::argc; $i++)
	{
		$currentarg = $Game::argv[$i];
		$nextArgument = $Game::argc[$i+1];
		$nextArgExists = $Game::argc-$i > 1; //returns true if there is another argument in the list.
		
		switch$($currentarg)
		{
			case "-?":
				$showHelp = true;
				$argumentFlag[$i] = true;
			case "-h":
				$showHelp = true;
				$argumentFlag[$i] = true;
		}
	}
}

function ShowHelp()
{
	echo("\n\n"@ $gameName @ " command line options:\n\n  -h, -?\ndisplay this message.\n");
}

ParseArgs();

// If we are wanting to show the help, enable the console
// display the help message, disable the console and exit.
if ($showHelp)
{
	enableWinConsole(true); //Send logging output to a Windows console window
	ShowHelp();
	enableWinConsole(false);
	quit();
}
else
{
	for ($i = 1; $i < $gameName::argc; $i++)
	{
		if (!$argumentFlag[$i])
			error("ERROR: Unknown command line argument: " @ $gameName::argv[$i]);
	}
	
	if (!$logModeEnabled)
		setLogMode(2);
	
	echo("Engine Initialization completed.");
	
	exec("Base/Init.cs");
	OnStart();
}

base/init.cs

package Base
{
	function OnStart()
	{
		Parent::OnStart();
		echo("------ Initializing Base ------");
		echo("Display Devices: " @ getDisplayDeviceList());
		echo("Video Driver Information: " @ getVideoDriverInfo());
		//setDisplayDevice(getDisplayDeviceList(), 640, 480, 16, false);
		//createCanvas($gameName);
	}
	
	function OnExit()
	{
		Parent::OnExit();
	}
};
activatePackage(Base);

everything works great. I get a console and the engine is running in a console. However, when I uncomment the "CreateCanvas" command, the engine starts to load and then crashes. Anyone know why this occurs? Do I need to setup anything prior to making this call?

#1
11/07/2007 (5:48 pm)
I found the problem, I had not set a video driver yet. Using the following code fixed my problem.

$pref::Video::allowOpenGL = true;
$pref::Video::displayDevice = "OpenGL";
createCanvas($gameName);