neoragex2015 / nvidia-texture-tools

Automatically exported from code.google.com/p/nvidia-texture-tools
Other
0 stars 0 forks source link

.toGamma(float) on a Surface when processing volume texture causes crash #191

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
When we use .toGamma(2.2f) function on a Surface while processing the attached 
volume texture, nvtt crashes internally. Settings we use:
- Format: A8R8G8B8
- Wrap mode: mirror
- Mipmap filter: kaiser (alpha 4, stretch 1, width 3)
- Alpha mode: transparency

Cheers

Original issue reported on code.google.com by karl.zyl...@northplay.com on 9 Jul 2013 at 8:56

Attachments:

GoogleCodeExporter commented 9 years ago
At first glance I don't see any problem with that code. Can you describe the 
sequence of operations performed on that surface? Any chance of getting a stack 
trace showing the crash location?

Original comment by cast...@gmail.com on 9 Jul 2013 at 5:17

GoogleCodeExporter commented 9 years ago
Here is our the call stack that our data compiler spits out.

09:51:05.58  [Context] While compiling: rendering/color_grading_identity.texture
09:51:05.58  [Crash] Access violation (0xc0000005) in build 13705
09:51:05.58  [Crash]     accessing address 0000000005C20DC8 from 
000000005A68C1BE
0x5a68c1be memcpy
0x8002b6b0 struct nvtt::Surface __cdecl nvtt::diff(struct nvtt::Surface const & 
__ptr64,struct nvtt::Surface const & __ptr64,float)
0x01e51c90 
0x0013e270 
0x00000008 
0x01e51a20 
0x00000001 
0x0013e138 
0x0013e218 
0x8000f4db public: void __cdecl nvtt::Surface::operator=(struct nvtt::Surface 
const & __ptr64) __ptr64
0x01e5ae50 
0x00000002 
0x0013e220 
0x80001283 
0xfffffffe 

I'll try to create the smallest possible reprocase and post it here (right now 
all I have is real in-engine code).

Original comment by karl.zyl...@northplay.com on 10 Jul 2013 at 7:52

GoogleCodeExporter commented 9 years ago
Hello again. I have created a small reprocase:

////// CODE START
#include <nvtt/nvtt.h>
#include <fstream>

int main()
{       
    nvtt::CompressionOptions nvtt_compression;
    nvtt_compression.setQuality(nvtt::Quality_Normal);
    nvtt_compression.setFormat(nvtt::Format::Format_RGBA);
    nvtt::InputFormat input_format = nvtt::InputFormat_BGRA_8UB;
    nvtt::OutputOptions nvtt_output;
    nvtt::Context nvtt_context;
    nvtt_context.enableCudaAcceleration(false);
    using namespace std;

    ifstream::pos_type size;
    char image[16512];
    std::ifstream file ("color_grading_identity.dds", ios::in|ios::binary|ios::ate);
    if (file.is_open())
    {
        size = file.tellg();
        file.seekg (0, ios::beg);
        file.read (image, size);
        file.close();
    }

    nvtt::Surface surface, tmp_surface;
    unsigned layers = 16;

    nvtt::TextureType tt = nvtt::TextureType_3D;

    nvtt_context.outputHeader(tt, 16, 16, layers, 0, false, nvtt_compression, nvtt_output);

    surface.setImage(input_format, 16, 16, layers, image);
    surface.setAlphaMode(nvtt::AlphaMode_Transparency);
    surface.setWrapMode(nvtt::WrapMode_Mirror);
    tmp_surface = surface;
    tmp_surface.toGamma(2.2f);

    return 0;
}
////// CODE END

The issue seems to be related to the assignment tmp_surface = surface (we do 
that in our code inside a mipmap loop). It does not matter if I run 
surface.toGamma(2.2f) or tmp_surface.toGamma(2.2f) on the last line, it still 
crashes as long as the assignment of tmp_surface is present.

Original comment by karl.zyl...@northplay.com on 10 Jul 2013 at 9:36

GoogleCodeExporter commented 9 years ago
Hmm... on what platform are you seeing this problem? I just tried your example 
on win32 and win64 and it worked fine in both cases. I'll give it a try on OSX 
when I have some time.

Original comment by cast...@gmail.com on 10 Jul 2013 at 5:37

GoogleCodeExporter commented 9 years ago
I'm seeing it on Win32 and Win64. I'll poke around a bit with the code, maybe 
there's some compiler setting that causes it to behave like this on only my 
computer.

Original comment by karl.zyl...@northplay.com on 11 Jul 2013 at 7:25

GoogleCodeExporter commented 9 years ago
I wanted to try with a fresh copy of NVTT since our build system has a repo 
which automatically pulls stuff from yours. My thought was that this might have 
caused some kind of inconsistency, causing my crash. However; I can't get the 
fresh copy to compile (in VS2010 or VS2010), the solution cmake spits out does 
not build. nvtt can't link nvcore because nvcore can't compile, one of the 
error messages it spits out is this:

2>  Debug.cpp
2>c:\projects\nvidia-texture-tools\src\nvcore\StrLib.h(165): error C2487: 
'separator' : member of dll interface class may not be declared with dll 
interface
2>c:\projects\nvidia-texture-tools\src\nvcore\StrLib.h(166): error C2487: 
'fileName' : member of dll interface class may not be declared with dll 
interface
2>c:\projects\nvidia-texture-tools\src\nvcore\StrLib.h(167): error C2487: 
'extension' : member of dll interface class may not be declared with dll 
interface
2>  StrLib.cpp
2>c:\projects\nvidia-texture-tools\src\nvcore\StrLib.h(165): error C2487: 
'separator' : member of dll interface class may not be declared with dll 
interface
2>c:\projects\nvidia-texture-tools\src\nvcore\StrLib.h(166): error C2487: 
'fileName' : member of dll interface class may not be declared with dll 
interface
2>c:\projects\nvidia-texture-tools\src\nvcore\StrLib.h(167): error C2487: 
'extension' : member of dll interface class may not be declared with dll 
interface
2>  TextWriter.cpp
2>c:\projects\nvidia-texture-tools\src\nvcore\StrLib.h(165): error C2487: 
'separator' : member of dll interface class may not be declared with dll 
interface
2>c:\projects\nvidia-texture-tools\src\nvcore\StrLib.h(166): error C2487: 
'fileName' : member of dll interface class may not be declared with dll 
interface
2>c:\projects\nvidia-texture-tools\src\nvcore\StrLib.h(167): error C2487: 
'extension' : member of dll interface class may not be declared with dll 
interface

Tried to remove the dll export from the functions, but then I got a huge list 
of linker errors. Feeling like I'm drifting away from my original bug report 
here...

Original comment by karl.zyl...@northplay.com on 11 Jul 2013 at 9:27

GoogleCodeExporter commented 9 years ago
There's a vc10 solution in project/vc10, but it may not be up to date. I don't 
usually use cmake on windows, so that build configuration may be broken. Let me 
know if the vc10 solution works for you and otherwise I'll take a look at the 
cmake problems.

Original comment by cast...@gmail.com on 11 Jul 2013 at 6:42

GoogleCodeExporter commented 9 years ago
The vc10 solution didn't work out of the box. I had to remove the missing file 
CompressorDXT.cpp from the project and also add BlockCompressor.h/cpp in order 
for it to build.

Once I had successfully built it my crash did not happen any more. Thank you 
for your quick and helpful answers!

Original comment by karl.zyl...@northplay.com on 12 Jul 2013 at 8:47

GoogleCodeExporter commented 9 years ago
OK, I'll close the issue then!

Original comment by cast...@gmail.com on 19 Jul 2013 at 11:49