milakov / nnForge

Convolutional neural networks C++ framework with CPU and GPU (CUDA) backends
http://nnforge.org
177 stars 44 forks source link

stream_duplicator causes assertion failure on Windows #25

Closed wdx04 closed 9 years ago

wdx04 commented 9 years ago

In stream_duplicator constructor, the first cout output statement causes assertion failure in boost/iostreams/tee.hpp, line 176(I'm using Boost 1.57, Visual C++ 2013).

    std::streamsize write(const char_type* s, std::streamsize n)
    {
        BOOST_STATIC_ASSERT((
            is_convertible<
                BOOST_DEDUCED_TYPENAME iostreams::category_of<Device>::type, output
            >::value
        ));
        std::streamsize result1 = iostreams::write(dev_, s, n);
        std::streamsize result2 = iostreams::write(sink_, s, n);
        (void) result1; // Suppress 'unused variable' warning.
        (void) result2;
        BOOST_ASSERT(result1 == n && result2 == n);
        return n;
    }

I placed a breakpoint on the BOOST_ASSERT line and got result1: 0, result2: 41, n: 41 in the debugger window. This is probably because outputs to the log file is buffered and not flushed before iostreams::write returns. In Release mode cout is correctly redirected to the log file.

Please consider using freopen function to redirect standard output to a file.

milakov commented 9 years ago

Hi, do you have a working directory created, where log file is placed?

wdx04 commented 9 years ago

Yes, I can confirm the log file is created, and if I comment out the BOOT_ASSERT line and recompile, the log will be written to the log file correctly. Also I noticed result1 = 0 means std::cout is the stream being buffered, not the log file stream.

milakov commented 9 years ago

I have Boost 1.56 installed locally and have no such problems running debug version built by MSVC 2013. Also I don't see why iostreams::write should return 0 even if the underlying stream is buffered.

milakov commented 9 years ago

Do you have any output to console when you are debugging the app?

wdx04 commented 9 years ago

I'm creating a Windows GUI application so there is no console.

milakov commented 9 years ago

Ok, this is the reason. Will you survive without permament fix for ~2 months? I am doing a major nnforge redesign now, would like to fix the issue afterwards.

wdx04 commented 9 years ago

No problem. Thanks.