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

Handle UTF encoded scene description files #136

Closed
FilipeXavierGama opened this issue May 31, 2021 · 5 comments
Closed

Handle UTF encoded scene description files #136

FilipeXavierGama opened this issue May 31, 2021 · 5 comments

Comments

@FilipeXavierGama
Copy link

Hi,

I have an odd (systematic nevertheless) problem after converting pbrt-v3 to pbrt-v4 files.
First of all, I have used the following command for conversion:
$ pbrt --upgrade old.pbrt > new.pbrt

Then, if I try to use "new.pbrt" as the input argument to "pbrt", $ pbrt new.pbrt, I obtain the following errors:
End of files before "WorldBegin"

Apparently, the pointer to the input file is not working as it should for some unknown reason, returning "end-of-file" when there is error-free data to read inside the input file.

However, if I copy the data manually from "new.pbrt" to another new empty file (for example "new_v2.pbrt"), pbrt works just fine using $ pbrt new_v2.pbrt

-> My guess is that there is some issue while creating and converting a pbrt-v3 file to a pbrt-v4 file.

Test case scenario:

  • Create a "pbrt-v3" input file (named "Scene_pbrt3.pbrt" in the attachment) with the default scene described in https://www.pbrt.org/fileformat-v3 under Example of a pbrt file

  • Convert the "pbrt-v3" file to a "pbrt-v4" file (named "Scene_pbrt4.pbrt" in the attachment) using $ pbrt --upgrade Scene_pbrt3.pbrt > Scene_pbrt4.pbrt

  • Create a new empty file called "Scene_pbrt4_2.pbrt" (attached) and copy manually the content from "Scene_pbrt4.pbrt" to "Scene_pbrt4_2.pbrt".

-> From the test case scenario above, $ pbrt Scene_pbrt4.pbrt fails and $ pbrt Scene_pbrt4_2.pbrt works fine.

I'm running PBRT-v4 with GPU support on Windows 10, RTX 2080 Super Mobile, Cuda Toolkit 11.2.0, Optix SDF 7.3.0.

TestCaseScenario.zip

@pbrt4bounty
Copy link
Contributor

Hi.. After a couple of checks, seems that the problem is the text codification format in the generated pbrt4.pbrt file. I forced to change this format to ASCII, and the file is now properly rendered with pbrt 4.
bad_text_codification
This are the warning..
git_warn

@pbrt4bounty
Copy link
Contributor

I think the problem maybe is the default encoding text files from your OS. Here, under Windows, the --upgrade parameter generated a right file format and is rendered Ok.

..\pbrt4bounty\bin>pbrt --upgrade pbrt3.pbrt >my_pbrt4.pbrt

..\pbrt4bounty\bin>pbrt my_pbrt4.pbrt
pbrt version 4 (built May 29 2021 at 21:28:28)
Copyright (c)1998-2021 Matt Pharr, Wenzel Jakob, and Greg Humphreys.
The source code to pbrt (but *not* the book contents) is covered by the Apache 2.0 License.
See the file LICENSE.txt for the conditions of the license.
Rendering: [+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++]  (50.9s)

What do you think @mmp ??
Cheers..

@FilipeXavierGama
Copy link
Author

FilipeXavierGama commented May 31, 2021

I think the problem maybe is the default encoding text files from your OS. Here, under Windows, the --upgrade parameter generated a right file format and is rendered Ok.

..\pbrt4bounty\bin>pbrt --upgrade pbrt3.pbrt >my_pbrt4.pbrt

..\pbrt4bounty\bin>pbrt my_pbrt4.pbrt
pbrt version 4 (built May 29 2021 at 21:28:28)
Copyright (c)1998-2021 Matt Pharr, Wenzel Jakob, and Greg Humphreys.
The source code to pbrt (but *not* the book contents) is covered by the Apache 2.0 License.
See the file LICENSE.txt for the conditions of the license.
Rendering: [+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++]  (50.9s)

What do you think @mmp ??
Cheers..

Thanks for checking this out. Looks like PBRT-v4 cannot deal with UTF-16LE encoding formats (and maybe that's ok!). Windows' Powershell creates UTF-16LE files by default while cmd shell uses the legacy encoding windows-1252 / UTF-8 by default. This means, that if I use the Powershell, I face the issue above. If I use "cmd", then everything is fine.

Cheers!

mmp added a commit that referenced this issue Jun 1, 2021
@mmp
Copy link
Owner

mmp commented Jun 1, 2021

Nice detective work @pbrt4bounty! I've just pushed a small fix that at least issues a sensible error message if a UTF-16-encoded file is detected.

I've dug into this a bit and my thinking is that now that it's 2021, pbrt should stop assuming ASCII and should at least support UTF-8-encoded scene description files. That will take a bit of re-plumbing; std::string is used all over the place in the system, for example. I'll rename this issue to cover that work and will eventually take care of it...

@mmp mmp changed the title Convert PBRT-V3 to PBRT-V4 Handle UTF-8 encoded scene description files Jun 1, 2021
@mmp mmp changed the title Handle UTF-8 encoded scene description files Handle UTF encoded scene description files Jun 1, 2021
mmp added a commit that referenced this issue Jun 2, 2021
Beyond the convenience of having them as a vector of strings, this
is where UTF16 -> UTF8 conversion of args happens on Windows.

This led to some adjustments to ParseArg()...

With this (and a number of preceeding commits), #136 should now be fixed.
@mmp
Copy link
Owner

mmp commented Jun 2, 2021

Upon further education about Unicode, turns out that std::string is fine (given UTF8 and then taking things from there.)

In any case, as far as I can tell, pbrt now properly handles(*) UTF8, both in *.pbrt files as well as in command line arguments. So things like ObjectBegin "🚀🙏", or pbrt 🚒.pbrt all work, on Linux, OSX, and Windows. (More prosaically, non-ASCII character sets should now just work.)

(*) The two remaining exceptions are that 1) UTF8 filenames for PNGs don't work, but there is a lodepng PR that would make it possible to address that. There is also an issue in the ext/filesystem dependency that can cause trouble on Windows under some circumstances, also hopefully fixed soon.

@mmp mmp closed this as completed Jun 2, 2021
Dolkar pushed a commit to Dolkar/pbrt-v4-myod-integration that referenced this issue May 8, 2023
Dolkar pushed a commit to Dolkar/pbrt-v4-myod-integration that referenced this issue May 8, 2023
Beyond the convenience of having them as a vector of strings, this
is where UTF16 -> UTF8 conversion of args happens on Windows.

This led to some adjustments to ParseArg()...

With this (and a number of preceeding commits), mmp#136 should now be fixed.
huongoss pushed a commit to huongoss/pbrt-v4-docker that referenced this issue Aug 30, 2024
Automatically adjust to changing monitor scale
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