Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt with openEXR and the code crashed

Qt with openEXR and the code crashed

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 228 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SisqosS Offline
    SisqosS Offline
    Sisqos
    wrote on last edited by Sisqos
    #1

    Hi everyone.
    I'm writing an image viewer.
    For EXR, I've compiled the source code to get:
    bin, includes, libs and dlls.
    The openEXR is compiled in x64 and the version is 3.
    zlib is x64
    Imath is x64
    My Qt is x64 and the free version.

    In the pro file, I added:
    LIBS += -l$$PWD/openEXR/lib/Iex-3_1_d
    LIBS += -l$$PWD/openEXR/lib/IlmThread-3_1_d
    LIBS += -l$$PWD/openEXR/lib/Imath-3_1_d
    LIBS += -l$$PWD/openEXR/lib/OpenEXR-3_1_d
    LIBS += -l$$PWD/openEXR/lib/OpenEXRUtil-3_1_d
    INCLUDEPATH += $$PWD/openEXR/include/Imath
    INCLUDEPATH += $$PWD/openEXR/include/openEXR

    My test code:
    openexrloader.h

    #ifndef OPENEXRLOADER_H
    #define OPENEXRLOADER_H
    #include <QWidget>
    #include <QtCore>
    #include <QtGui>
    #include <QImageIOPlugin>
    //Imath
    #include <half.h>
    
    //openEXR
    #include <OpenEXRConfig.h>
    #include <ImfRgbaFile.h>
    #include <ImfRgba.h>
    #include <ImfArray.h>
    
    //Namespace
    #include "namespaceAlias.h"
    class openEXRLoader:QObject
    {
    
    public:
        explicit openEXRLoader();
    
    
        void writeRgba1 (const char fileName[],
                        const IMF::Rgba *pixels,
                        int width,
                        int height);
    signals:
    
    };
    #endif // OPENEXRLOADER_H
    
    

    openexrloader.cpp

    #include "openexrloader.h"
    
    openEXRLoader::openEXRLoader():QObject()
    {
        const char fileName[] = "D:/test.exr";
        //Declare a pointer in the memory for RGBA
        IMF::Rgba *pixels = NULL;
        int width = 100;
        int height = 100;
    
        try
        {
            writeRgba1(fileName, pixels, width, height);
        }
        catch (const std::exception &exc)
        {
            std::cerr << exc.what() << std::endl;
        }
    }
    
    void openEXRLoader::writeRgba1 (const char fileName[],
                const IMF::Rgba *pixels,
                int width,
                int height)
    {
        IMF::RgbaOutputFile file (fileName, width, height, IMF::WRITE_RGBA);      // 1
        file.setFrameBuffer (pixels, 1, width);                         // 2
        file.writePixels (height);                                      // 3
    }
    

    NO errors, but the code will crash.

    Which part do I did it incorrectly?

    Thank you for help.

    JonBJ 1 Reply Last reply
    0
    • SisqosS Sisqos

      Hi everyone.
      I'm writing an image viewer.
      For EXR, I've compiled the source code to get:
      bin, includes, libs and dlls.
      The openEXR is compiled in x64 and the version is 3.
      zlib is x64
      Imath is x64
      My Qt is x64 and the free version.

      In the pro file, I added:
      LIBS += -l$$PWD/openEXR/lib/Iex-3_1_d
      LIBS += -l$$PWD/openEXR/lib/IlmThread-3_1_d
      LIBS += -l$$PWD/openEXR/lib/Imath-3_1_d
      LIBS += -l$$PWD/openEXR/lib/OpenEXR-3_1_d
      LIBS += -l$$PWD/openEXR/lib/OpenEXRUtil-3_1_d
      INCLUDEPATH += $$PWD/openEXR/include/Imath
      INCLUDEPATH += $$PWD/openEXR/include/openEXR

      My test code:
      openexrloader.h

      #ifndef OPENEXRLOADER_H
      #define OPENEXRLOADER_H
      #include <QWidget>
      #include <QtCore>
      #include <QtGui>
      #include <QImageIOPlugin>
      //Imath
      #include <half.h>
      
      //openEXR
      #include <OpenEXRConfig.h>
      #include <ImfRgbaFile.h>
      #include <ImfRgba.h>
      #include <ImfArray.h>
      
      //Namespace
      #include "namespaceAlias.h"
      class openEXRLoader:QObject
      {
      
      public:
          explicit openEXRLoader();
      
      
          void writeRgba1 (const char fileName[],
                          const IMF::Rgba *pixels,
                          int width,
                          int height);
      signals:
      
      };
      #endif // OPENEXRLOADER_H
      
      

      openexrloader.cpp

      #include "openexrloader.h"
      
      openEXRLoader::openEXRLoader():QObject()
      {
          const char fileName[] = "D:/test.exr";
          //Declare a pointer in the memory for RGBA
          IMF::Rgba *pixels = NULL;
          int width = 100;
          int height = 100;
      
          try
          {
              writeRgba1(fileName, pixels, width, height);
          }
          catch (const std::exception &exc)
          {
              std::cerr << exc.what() << std::endl;
          }
      }
      
      void openEXRLoader::writeRgba1 (const char fileName[],
                  const IMF::Rgba *pixels,
                  int width,
                  int height)
      {
          IMF::RgbaOutputFile file (fileName, width, height, IMF::WRITE_RGBA);      // 1
          file.setFrameBuffer (pixels, 1, width);                         // 2
          file.writePixels (height);                                      // 3
      }
      

      NO errors, but the code will crash.

      Which part do I did it incorrectly?

      Thank you for help.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Sisqos said in Qt with openEXR and the code crashed:

      NO errors, but the code will crash.

      If code crashes, run under the debugger, and look at the stack trace when it crashes.

      1 Reply Last reply
      1
      • SisqosS Offline
        SisqosS Offline
        Sisqos
        wrote on last edited by
        #3

        I found IMF::RgbaOutputFile is the reason to make a crash.
        We knew FreeImage can work with Qt directly, but openEXR can't.
        Does anyone know the reason?

        1 Reply Last reply
        0
        • SisqosS Offline
          SisqosS Offline
          Sisqos
          wrote on last edited by
          #4

          I've solved the problem.
          I forget to consider that .exe require .dlls to execute.
          Just copy .dlls to the folder where .exe is executed.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved