Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

map.load() not getting any path #133

Open
MCS09 opened this issue Jul 16, 2023 · 10 comments
Open

map.load() not getting any path #133

MCS09 opened this issue Jul 16, 2023 · 10 comments

Comments

@MCS09
Copy link

MCS09 commented Jul 16, 2023

I've tried installing tmxlite into a project I've created (I'm using Visual Studio 2022) and all the includes seem to work fine, but every time I try to load a map this way:

tmx::Map map;
map.load("resources/test.tmx");


I get this in the console:

ERROR: Failed opening
ERROR: Reason: File was not found


If I try to do the same in the ParseTest project and load an unexisting map, I get this, which makes sense because the directory doesn't exist:

ERROR: Failed opening resources/test.tmx
ERROR: Reason: File was not found


It seems like the issue is that the file path goes missing at some point, but I can't keep track of where it happens since the Map.cpp file isn't in the include files and I don't know how to add a breaking point to an external file.

I was wondering if I messed up the installation or something, since had a hard time generating the .libs and .dlls of the library. I also tried using the .libs and .dlls of a project where tmxlite worked fine, but I still had the same issue, so I don't really know what's causing it.

@pedro-w
Copy link

pedro-w commented Jul 17, 2023

Are you debugging from within VS? Check the working directory (from memory it's Project Properties -> Debugging -> Working Directory) because your relative path resources/test.tmx will be found starting from there.

@MCS09
Copy link
Author

MCS09 commented Jul 17, 2023

Are you debugging from within VS? Check the working directory (from memory it's Project Properties -> Debugging -> Working Directory) because your relative path resources/test.tmx will be found starting from there.

My issue isn't that the path can't be found (I tried opening the file with fstream just to check and it loads correctly), it's that at some point when I call the load() method, the path ends up being an empty string, so the error in the console doesn't print any path, unlike in the ParseTest project.

@pedro-w
Copy link

pedro-w commented Jul 17, 2023

Sorry, I misunderstood what you meant by 'file path goes missing'. That is weird, on the face of it, it looks impossible *

bool Map::load(const std::string& path)
{
reset();
//open the doc
pugi::xml_document doc;
auto result = doc.load_file(path.c_str());
if (!result)
{
Logger::log("Failed opening " + path, Logger::Type::Error);
Logger::log("Reason: " + std::string(result.description()), Logger::Type::Error);
return false;
}

Can you set a breakpoint on the map.load("resources/test.tmx"); line and then 'step into'? Can you share a complete (minimal) project where this happens? Potentially it could be some header/implementation mismatch, I'm not sure and maybe better wait until the experts show up!

* I've said this many times before !

@fallahn
Copy link
Owner

fallahn commented Jul 17, 2023

Could possibly be a mismatch in debug/release builds? If you're not using any external libraries (zstd etc) you can easily add the source for tmxlite directly to your project, which will help setting break points (and remove any potential build config mismatching)

@MCS09
Copy link
Author

MCS09 commented Jul 17, 2023

Sorry, I misunderstood what you meant by 'file path goes missing'. That is weird, on the face of it, it looks impossible *

bool Map::load(const std::string& path)
{
reset();
//open the doc
pugi::xml_document doc;
auto result = doc.load_file(path.c_str());
if (!result)
{
Logger::log("Failed opening " + path, Logger::Type::Error);
Logger::log("Reason: " + std::string(result.description()), Logger::Type::Error);
return false;
}

Can you set a breakpoint on the map.load("resources/test.tmx"); line and then 'step into'? Can you share a complete (minimal) project where this happens? Potentially it could be some header/implementation mismatch, I'm not sure and maybe better wait until the experts show up!

  • I've said this many times before !

This is the project I'm working on. I can't set a breakpoint in Map.cpp because I'm using tmxlite as a dynamic library (at least I think that's what I did), so the .cpp is not in the same project.

\

Could possibly be a mismatch in debug/release builds? If you're not using any external libraries (zstd etc) you can easily add the source for tmxlite directly to your project, which will help setting break points (and remove any potential build config mismatching)

I could use the source files if I still can't get it to work, but since I've done it like that before (not me really, since it was a group project and I wasn't the one who installed the libraries), I thought I could do it the same way here.

@MCS09
Copy link
Author

MCS09 commented Jul 21, 2023

I could use the source files if I still can't get it to work, but since I've done it like that before (not me really, since it was a group project and I wasn't the one who installed the libraries), I thought I could do it the same way here.

Ok, I couldn't try it until now and turns out I actually don't know how to use the source files (I thought I only had to copy and paste the tmxlite/src files into my project folder). Care if I ask how should I do it?

On the other hand, I'm sill trying to figure out how to install tmxlite as a dynamic library. I've checked this, this and this posts just in case. Since I'm on Windows, I can't completely follow the last one, and as far as I know, I've done the few things on the second one, but since I can't compile the tmxlite project nor the project generated with CMakeLists.txt in the tmxlite folder, I'm not sure if those libraries are completely functional.

@fallahn
Copy link
Owner

fallahn commented Jul 21, 2023

The simplest way is to copy the src and include directories from the tmxlite folder to your project folder. Then (taking this random project I have as an example) right click Source Files and Add Existing -> then select all the *.cpp and *.c files:

Untitled-1

Untitled-2

Then update your project properties to add the new include path:
Untitled-3

Remember to update both Debug and Release builds, and remove any paths to the existing external library.

@MCS09
Copy link
Author

MCS09 commented Jul 21, 2023

Thanks for the explanation! It seems to work if I use the source files, so I'm guessing I did something wrong when installing tmxlite as an external library, probably when generating the dlls. Correct me if I'm wrong, but all I had to do was use CMake to generate the project in CMakeLists.txt and compile it, right? Because when I try to compile the ALL_BUILD and ZERO_CHECK projects, I get an error that says "Access denied", when I try to compile the INSTALL one I get "The system couldn't find the specified file" and when I try to compile the tmxlite project I ghet that "tmxlite.dll isn't a valid Win32 application". Any clues on why this is happening?

@fallahn
Copy link
Owner

fallahn commented Jul 22, 2023

OK, glad that works!
So the first couple of errors, I can't really help with - there may be a bug in the Visual Studio build with CMake - I usually only use CMake for linux/mac etc. The last error is that the debugger is trying to launch and run the resulting dll - although it's not an exe so it throws that error.

There is a Visual Studio solution included with the tmxlite repository, which is what I usually work with, so you ought to have more luck with that. There are a few build options which might need explaining though, to get you off on the right foot.

Firstly, make sure you have the correct architecture selected for your project. By default the solution uses x64 but you'll need to change this if you're creating a 32-bit project. (Although unless you have a specific need for 32-bit I personally always choose x64 for everything)

Untitled-1

You'll also need to build BOTH Debug and Release versions. This will create libtmxlite-d.lib/dll and libtmxlite.lib/dll respectively. You then also have to make sure to link the correct version to the correct build settings in your own project.

Untitled-2

If you don't do this there won't be a compile error, but you will get strange runtime behaviour - and I suspect this is the source of your original bug (the missing file path).

It is also possible, using the configuration settings, to create a static library.

Untitled-3

This will only compile to libtmxlite-s-d.lib/libtmxlite-s.lib (no dll) and linking this will mean the tmxlite code is compiled into your executable as if you had included the source directly - there's no need to include any dll files.

HTH! 😁

@MCS09
Copy link
Author

MCS09 commented Jul 22, 2023

Oh, yeah, I forgot to mention that I also tried with the solution in the repository. I got to generate the libraries (which I thought weren't the ones I needed because they were named libtmxlite.lib/dll and not just tmxlite.lib/dll as I had seen in other project). with no compilation errors, but I still got the "tmxlite.dll isn't a valid Win32 application" message for each of them.

If I try linking it to my existing project, I have the same issue and the file path ends up being an empty string. I also tried linking it to a new project just in case, but then I get an "Access violation reading location" compilation error from vcruntime140.dll

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants