question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[module] Unsure how to properly use ChangeDirectory()

See original GitHub issue

So, I’m using Raylib-CS on macos, so that might be pertinent. Right now, for loading assets I am using a solution I picked up from using Monogame. It goes something like this: Check “copy to output directory” on all assets (images etc). Then I use this function whenever I’m loading a file:

static string getFullPath(string relativePath)
{
	string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
	return System.IO.Path.Combine(baseDirectory, relativePath);
}

Font ALAGARD = LoadFont(getFullPath("Assets/fonts/alagard.png"));
Image cursorImage = LoadImage(getFullPath("Assets/cursor.png"));

This works for me, but I’ve been made aware that another solution would be to call ChangeDirectory(GetApplicationDirectory());

The issue is, I don’t know how to use this function properly with C#. I get the following errors: Screen Shot 2023-06-08 at 12 03 34 PM Screen Shot 2023-06-08 at 12 03 39 PM

Again, what I was already doing works, but I’m curious how to use these functions properly. It doesn’t seem like using “unsafe” should be required. I feel that I am missing something obvious here, any help would be appreciated!

Issue Analytics

  • State:closed
  • Created 3 months ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
JupiterRidercommented, Jun 11, 2023

@differenceclouds Oh, the ref keyword is common in C#: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/ref

When you use void ImageRotateCW(ref Image image) for example, the with and height of the image change and in order to update the fields, you have to provide a reference.

That’s because Image is a struct and not a class.

1reaction
9ParsonsBcommented, Jun 9, 2023

Have a look at Utf8StringUtils it allows you to convert pointers to strings and back.

As for the current directory, try and prefer the built-in C# methods, e.g. System.Numerics over RayMath, AppDomain.CurrentDomain.BaseDirectory or Assembly.GetExecutingAssembly().Location over raylib.GetApplicationDirectory, etc.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I change directory back to my original working ...
The best solution is to use the subprocess module instead (Python 2.4 onwards) and the run or popen methods with the cwd argument....
Read more >
The Module Search Path
In this lesson, you'll learn about the module search path. Continuing with the example from the previous lesson, take a look at what...
Read more >
Changing Directory based on user input - Python Forum
Hi there, I'm trying to create a program whereby a user can resize images in their own, inputted directory. As you can see...
Read more >
How to set up working directory in PyCharm and package ...
I want 2 questions: 1) I want to import the file lr_utils.py as a package, it's in my current directory. PyCharm refuse to...
Read more >
Moving Into and Out of Directories with the "cd" Command
The second way to list files in a directory, is to first move into the directory using the "cd" command (which stands for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found