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

Error on Windows: "thread 'main' panicked at 'attempt to divide by zero'" #4

Open
mattwilson1024 opened this issue May 30, 2021 · 3 comments

Comments

@mattwilson1024
Copy link

First of all thanks for a great tool! I'm trying to use swizzler to create a channel packed image for Unity's URP Lit Shader (https://docs.unity3d.com/Packages/[email protected]/manual/lit-shader.html) - with metallic in the red channel and smoothness in the alpha channel.

Running the tool with manual parameters like below works perfectly and produces output.png as desired:

swizzler manual -i MaterialTestObject_Bake1_pbr_metalness.png:0 -i none -i none -i MaterialTestObject_Bake1_pbr_roughness.png:0

However I get an error if I try to use the "session" mode for an easier workflow. I've created config.json containing the following:

{
  "base": "(.*)_.*",
  "matchers": [
      { "id": "metalness", "matcher": "(?i)metal(ness)?" },
      { "id": "roughness", "matcher": "(?i)rough(ness)?" },
      { "id": "albedo", "matcher": "(?i)diffuse?" }
  ],
  "targets": [
    {
      "name": "-metalness-roughness.png",
      "output_format": "png",
      "inputs": [
          [ "metalness", 0 ],
          null,
          null,
          [ "roughness", 0 ]
      ]
    }
  ]
}

and tried running it like so:

swizzler session --folder .\ --config C:\Users\matt\Home\tools\swizzler-0.1.0-windows\config.json

But this prints the following error and does not produce any output files:

swizzler session --folder .\ --config C:\Users\matt\Home\tools\swizzler-0.1.0-windows\config.json
Building assets from folder '.\'...
Running session on 1 assets
thread 'main' panicked at 'attempt to divide by zero', C:\Users\z003ws7c\Projects\Albedo\swizzler\lib\src\session\mod.rs:85:33
stack backtrace:
   0:     0x7ff7afefff59 - <unknown>
   1:     0x7ff7aff164fb - <unknown>
   2:     0x7ff7afefc724 - <unknown>
   3:     0x7ff7aff02b8c - <unknown>
   4:     0x7ff7aff027dc - <unknown>
   5:     0x7ff7aff0336f - <unknown>
   6:     0x7ff7aff02ef5 - <unknown>
   7:     0x7ff7aff14f40 - <unknown>
   8:     0x7ff7aff14e8c - <unknown>
   9:     0x7ff7afd26a9c - <unknown>
  10:     0x7ff7afd2f9e2 - <unknown>
  11:     0x7ff7afd25886 - <unknown>
  12:     0x7ff7aff02d97 - <unknown>
  13:     0x7ff7aff07ba2 - <unknown>
  14:     0x7ff7aff036a2 - <unknown>
  15:     0x7ff7afd31fa7 - <unknown>
  16:     0x7ff7aff1d154 - <unknown>
  17:     0x7ffe84407034 - BaseThreadInitThunk
  18:     0x7ffe84542651 - RtlUserThreadStart

If it helps, I'm using Windows 10 and downloaded the binary from Github Releases (swizzler-0.1.0-windows.tgz)

Would be very grateful for any ideas what I might be doing wrong or how to get this to work. Thanks again

@DavidPeicho
Copy link
Member

Hi, thanks for the detailed issue! I just had a look and I see what the error is. I will fix that after work and let you know so you can try it. I don't have a windows on my hand right now, do you think you will be able to build it yourself? Do you have cargo / rustc installed?

@DavidPeicho
Copy link
Member

BTW the error occurs because no assets is found (so the division by 0). I don't know if that's a difference on Windows / Macos / Linux, but did you have assets in your folder?

@mattwilson1024
Copy link
Author

mattwilson1024 commented Jun 1, 2021

Thanks for getting back to me. Below is the list of files I have in the directory and my config just in case it's just me configuring it wrong.

I have the following files:

01/06/2021  16:51    <DIR>          .
01/06/2021  16:51    <DIR>          ..
01/06/2021  16:56               391 config.json
01/06/2021  16:39           257,664 Cube_ao.png
01/06/2021  16:39            93,140 Cube_diffuse.png
01/06/2021  16:39            79,570 Cube_emission.png
01/06/2021  16:39            25,469 Cube_glossy.png
01/06/2021  16:39            86,091 Cube_metalness.png
01/06/2021  16:39           889,332 Cube_normal.png

with config.json looking like this:

{
  "base": "(.*)_.*",
  "matchers": [
      { "id": "metalness", "matcher": "(?i)metal(ness)?" },
      { "id": "ao", "matcher": "(?i)ao" },
      { "id": "glossy", "matcher": "(?i)glossy" }
  ],
  "targets": [
    {
      "name": "-unity-urp.png",
      "output_format": "png",
      "inputs": [
          [ "metalness", 0 ],
          [ "ao", 0 ],
          null,
          [ "glossy", 0 ]
      ]
    }
  ]
}

and I'm running:

swizzler session --folder .\ --config .\config.json

I also tried full paths with both forward and backwards slashes in case that revealed any clues regarding platform differences, but they all come back with the divide by zero error

swizzler session --folder C:\Users\matt\Desktop\MaterialTestNew\SimpleBake_Bakes --config C:\Users\matt\Desktop\MaterialTestNew\SimpleBake_Bakes\config.json

swizzler session --folder C:/Users/matt/Desktop/MaterialTestNew/SimpleBake_Bakes --config C:/Users/matt/Desktop/MaterialTestNew/SimpleBake_Bakes/config.json

If you have a potential fix in mind then I'd be happy to test it out on my Windows machine if you wouldn't mind letting me know how to build & run it (I've not used Rust before so not familiar with the tools). I have installed Rust and now have rustc and cargo available. Guessing cargo would allow me to install from a git branch or something like that?

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

2 participants