• Advertisement

a light breeze

Member
  • Content count

    14
  • Joined

  • Last visited

  • Days Won

    1

a light breeze last won the day on March 29

a light breeze had the most liked content!

Community Reputation

14 Neutral

About a light breeze

  • Rank
    Member

Personal Information

  • Interests
    Art
    Audio
    Business
    Design
    Production
    Programming
    QA

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

Enable
  1. a light breeze

    DX11 Gap between Sky and Terrain

    Make your sky a cube or a sphere or something else that completely surrounds the world on all sides.
  2. a light breeze

    C++ Finish std::thread from another thread

    Is that your real code? Because "problematic" doesn't begin to describe it. Let's see... #ifndef WINDOWS_CMP struct TStringList #endif { This will of course blow up if WINDOWS_CMP is ever defined. int Count; This variable is both redundant and uninitialized. This could be the bug you're looking for. Just use Strings.size() instead. void Add(AnsiString text) { AnsiString p = text; Strings.push_back(text); Count = Count + 1; } I hope you're not calling this function on the same object from multiple threads, because it is not thread-safe. If you are, then this could also be the bug you're looking for. AnsiString GetText() { AnsiString res = ""; int i; for (i=0; i < Count; i++) res = res + Strings[i] + "\n"; return res; } This is a performance pig if you call it more than once per object, but otherwise harmless. void SaveToFile(AnsiString fname) { pc = GetText(); std::ofstream outfile (fname.c_str(),std::ofstream::binary); int len = pc.length(); char * buff = new char[ len ]; memcpy(buff, pc.c_str(), sizeof(char) * len); outfile.write (buff, len); outfile.close(); } You're rewriting the entire file each time this function is called. This is terrible for performance, but it's also bad because any data you write is getting erased in each iteration before being rewritten. This could also be the bug you're looking for, especially if you are calling this function from multiple threads. Also, you're leaking memory. buff here serves no purpose. Better approach: struct Logger { Logger(std::string const& fname) : file(fname.c_str()) { // Open the file once, and keep it open. } void Add(std::string const& s) { std::lock_guard<std::mutex> lock(mtx); // To make this thread-safe file << s << '\n' << std::flush; } std::mutex mtx; // To make this thread-safe. std::ofstream file; }
  3. a light breeze

    Why is this an "access violation"?

    By far the most likely culprit is that 'pic' is invalid (e.g. null, uninitialized, or pointing to an object that no longer exists). However, there are some other possibilities: 'RenderEx' could be an invalid function pointer (e.g. null or uninitialized) or an invalid callable object. The function 'RenderEx' could be compiled without debugging information, in which case the problem could be deep within its bowels. This is especially likely if it is not your own code but provided by some library. The parameters could be invalid (e.g. member variables of an object that no longer exists or that never was created).
  4. This cannot be done in the general case, because boost::function is a generic wrapper around a callable object that may or may not be equality comparable. Consider: #include <boost/function.hpp> #include <iostream> struct uncomparable_fn() { void operator()() const { std::cout << "Hello world.\n" << std::flush; } }; int main() { uncomparable_fn f1, f2; boost::function<void()> fn1(f1), fn2(f2); // The following line cannot compile, because uncomparable_fn has no operator==. if (f1 == f2) { } // Therefore the following line also cannot compile. if (fn1 == fn2) { } }
  • Advertisement