Jump to content

Leadwerks Using Wrong Working Directory


Recommended Posts

I have the following code:

#include "Leadwerks.h"

using namespace Leadwerks;

int main(int argc, const char *argv[])
{
	Leadwerks::Window* window = Leadwerks::Window::Create();
	Context* context = Context::Create(window);
	Font* font = context->GetFont();

	while(true)
	{
		if(window->Closed() || window->KeyHit(Key::Escape)) break;

		context->SetColor(0.0, 0.0, 1.0);
		context->Clear();

		//  Print argument to console
		if(argc>1) printf("%s\n",argv[1]);

		context->SetBlendMode(Blend::Alpha);
		context->SetColor(1.0, 1.0, 1.0);
		context->DrawText("Hello", 10, 10);
		context->SetBlendMode(Blend::Solid);
		context->Sync();
	}
	return 0;
}

If you run the EXE by itself (or from Visual Studio) or if you drag a file from the same folder as the EXE, it runs as expected.  However, if you drag a file from any other folder, the program fails to load drawtext.shader because it tries to find it in the wrong place.

For example, dragging a file from C:\ says Error: Failed to load shader "C://Shaders/Drawing/drawtext.shader"
Dragging a file from D:\Test folder says Error: Failed to load shader "D:/Test/Shaders/Drawing/drawtext.shader"
etc.
even though the project is in the C:\Users...Documents\Projects\ProjectName folder

Seems like dragging a file onto the EXE shouldn't mess up anything loading.  I could be doing something wrong but this seems like a bug.  I'm on release version.

 

Link to comment
Share on other sites

argv[0] doesn't seem to change and shows the correct working folder+filename.

I also just dragged a file onto another project EXE I had and it couldn't load a font (the first thing I tried to load in the project) where it works fine otherwise.

Link to comment
Share on other sites

Admittedly I'm doing an odder side project more involving Steam than Leadwerks.  I'll see if resetting the working folder will help.

Edit: here's the code to help Leadwerks find the correct paths again:

char buffer[MAX_PATH];

//  Get full path and filename
GetModuleFileName(NULL, buffer, MAX_PATH);

std::string ourpath = buffer;

//  Remove filename from the end of the path
ourpath = ourpath.substr(0, ourpath.find_last_of( "\\/" ));

SetCurrentDirectory(ourpath.c_str());

 

Link to comment
Share on other sites

  • 9 months later...
  • Josh locked this topic
Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...