|
So, possibly a newbie question. I'm trying to figure out what the heck I'm doing wrong to cause a crash. This works. C++ code:
C++ code:
C++ code:
(I don't think it's terribly relevant, but as you might infer this is using ffmpeg libraries.)
|
# ? Oct 21, 2015 05:26 |
|
|
# ? Jun 1, 2024 13:03 |
|
Doctor w-rw-rw- posted:(I don't think it's terribly relevant, but as you might infer this is using ffmpeg libraries.) It might be relevant. According to this, the library is allowed to free and reallocate the buffer that you pass to it. You're supposed to free avioContext->buffer instead of the original buffer. I've never used FFmpeg so I'm not sure if this is correct, but it would explain the double free. Example #2 most likely also has this problem. The error is probably just not detected in this specific case; perfect fault detection is too expensive for a production allocator, so all you'll ever get is the subset of true positives that can be confirmed with low overhead. You can always try a debug allocator or dynamic analysis (e.g. valgrind) if you want to know for sure.
|
# ? Oct 21, 2015 07:41 |
|
Null Pointer posted:It might be relevant. According to this, the library is allowed to free and reallocate the buffer that you pass to it. You're supposed to free avioContext->buffer instead of the original buffer. I've never used FFmpeg so I'm not sure if this is correct, but it would explain the double free. Yes, this is correct. A correct implementation would be something like: C++ code:
|
# ? Oct 21, 2015 15:29 |
|
Ah, thanks! The function is somewhat long and involved, so I had been hoping to avoid figuring out cleanup by just returning and cleaning up on scope exit.
|
# ? Oct 21, 2015 15:41 |
|
I have to include some code that still uses tr1, and this causes some redefinition errors in google test. This can be fixed by defining these macros: -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_USE_OWN_TR1_TUPLE=1 but why does it happen in the first place? Isn't everything in separate namespaces?
|
# ? Oct 22, 2015 12:50 |
|
What's considered the best unit test framework these days? Specifically, I am trying to construct a basic testing framework for a project that already has several KLOC of code with just BOOST_ASSERTs sprinkled around to keep it in check.
|
# ? Oct 23, 2015 00:42 |
|
Chuu posted:What's considered the best unit test framework these days? Specifically, I am trying to construct a basic testing framework for a project that already has several KLOC of code with just BOOST_ASSERTs sprinkled around to keep it in check. I think googletest works fine. Easy setup, painless to use, I was happy with it.
|
# ? Oct 23, 2015 01:11 |
|
Google test is decent and usable. There's a bunch of interesting-looking C++11/14 libs on github that I haven't yet tinkered with as well, which promise to be much less macro-heavy and perhaps more actively maintained.
|
# ? Oct 23, 2015 02:30 |
|
Ralith posted:Google test is decent and usable. There's a bunch of interesting-looking C++11/14 libs on github that I haven't yet tinkered with as well, which promise to be much less macro-heavy and perhaps more actively maintained. Google test (and by extension google mock) are generally quite good, and generally bug free. They are a bit slack with updating when compilers add new language features (e.g. override), however it's not that big a deal. We have our own implementation of a std::uniqe_ptr wrapper, but I'm not sure if anything has been done in Google's framework. Google test and mock also have a heap of ways of dealing with side effects, which is very useful if you need to deal with C lang based interfaces. Also support parameterized (but not typed parameterized) tests. The main disadvantages are marcos, and no way to mock out free functions (other than doing it yourself with namespace tricks). Some other frameworks allow you to mock out free functions, but their implementations are terrifying. Jinx fucked around with this message at 07:27 on Oct 23, 2015 |
# ? Oct 23, 2015 07:24 |
|
I quite enjoy bandit.
|
# ? Oct 23, 2015 15:40 |
|
I have a little OLED hooked up to my Raspberry Pi like this: The library for it is written in C++. I'm a web developer and know nothing about how to approach this project: I want the OS's console to be displayed on this little OLED. I guess a way for C++ to see what the console currently is, including what is being typed on it. Does anyone know how I can do that? Just the getting console info part, I can figure out the printing to the OLED probably. Whatever the final script winds up being is just something I'll have autolaunch at start, so I know I won't get the pre-boot stuff, but I am ok with that.
|
# ? Oct 24, 2015 06:04 |
Two ways I see of getting a console on an extra display like that: 1) Write a kernel console driver, that actually uses the display as system console. (Keep in mind Linux kernel is C, not C++.) 2) The Xterm approach, write a usermode application that launches a new login shell and renders the input/output for that process on the display. Option 2 can optionally be run through init or similar, so you always get a console on it. Note that for option 2, a regular keyboard still counts as belonging to the system console, and if the system console has multiple virtual consoles, as Linux systems often have, your application only runs on one virtual console so you can actually switch "keyboard focus" away.
|
|
# ? Oct 24, 2015 07:21 |
|
I'm getting stuck in circular header dependency hell due to inline code requiring the definitions of things that are themselves dependent on the type that the header is for. Is there a good pattern for breaking the circular dependencies in something like this? i.e.: code:
|
# ? Oct 25, 2015 08:11 |
|
OneEightHundred posted:I'm getting stuck in circular header dependency hell due to inline code requiring the definitions of things that are themselves dependent on the type that the header is for. Pull the struct definition out into its own header: code:
|
# ? Oct 25, 2015 08:35 |
|
OneEightHundred posted:I'm getting stuck in circular header dependency hell due to inline code requiring the definitions of things that are themselves dependent on the type that the header is for. Not to be a style nudge (and recognizing this may be existing code you just can't re-factor), but every case I can think of where you'd do this you will never including A without B (as is explicit in your include file anyways) so I would say there's a very strong argument that the two files should just be combined into a larger "conceptually-organized" file rather than separate "implementation-organized" ones: code:
|
# ? Oct 25, 2015 16:16 |
|
nielsm posted:Two ways I see of getting a console on an extra display like that: Thanks! There's a library someone wrote already that I will try first, and if not I will look into these.
|
# ? Oct 26, 2015 01:37 |
|
Seeking some advice on how to clean up some code I recently wrote for my Operating Systems class. Everything in my assignment "Pirates.c" appears to function to the assignment requirements but I feel like I wrote the solution like poo poo; anyone mind pointing out some glaringly obvious things I can clean up? I've attached an incorrect solution but it uses a struct for each threads data. I believe that idea might lead to a better solution but could anyone take a look at it and tell me if that method is even possible for this assignment. I also need to create a secondary program that fails to protect the critical section (The num of pearls in this case). Meaning more than one thread would be able to take from the "pearls" at the same time resulting in an incorrect output. I've tried removing the mutex locks from my program and it still functions correctly, what am I missing here? Please keep in mind, I've never threaded anything in my life, I still don't fully understand some of the basics, let alone the intricate details. Anyone have any decent reading to fill in some of the blanks for me? I'm pretty much teaching myself here. Code GIST e:If you would like to compile "gcc pirates.c -lpthread -lm"
|
# ? Oct 26, 2015 05:50 |
Your function prototypes for the thread main functions are wrong. A pthreads thread function also takes a parameter, that is pointer-sized, and contains data passed to the pthread_create call. You should really use the correct function prototype, avoid having to typecast the function pointer, and be able to have just one single "pirate" thread. That is, pass each thread as parameter how many pearls it can take, and what its name is.
|
|
# ? Oct 26, 2015 06:30 |
|
I've been using msvc which I know does a lot of non-standard stuff, but why doesn't the following code work on gcc?code:
|
# ? Oct 27, 2015 00:13 |
|
Sex Bumbo posted:I've been using msvc which I know does a lot of non-standard stuff, but why doesn't the following code work on gcc? It doesn't work on gcc because the compiler isn't supposed to do multiple implicit user-defined conversions on a value (from int to A, then from A to B). This, of course, does not mean that you can't write explicit conversions: C++ code:
|
# ? Oct 27, 2015 00:29 |
|
Bonfire Lit posted:It doesn't work on gcc because the compiler isn't supposed to do multiple implicit user-defined conversions on a value (from int to A, then from A to B). This, of course, does not mean that you can't write explicit conversions: What I mostly want is an unobtrusive way to prevent msvc users from writing code that will break on gcc. Simply using the above notation wouldn't prevent them from writing it incorrectly and building cleanly on msvc.
|
# ? Oct 27, 2015 00:50 |
|
Sex Bumbo posted:What I mostly want is an unobtrusive way to prevent msvc users from writing code that will break on gcc.
|
# ? Oct 27, 2015 00:54 |
|
Plorkyeran posted:People who are not intimately familiar with msvc's quirks will not be able to reliably write code which works in gcc without testing it in gcc. Also the main way to avoid unexpected behavior from implicit conversions is to use "explicit" and not use implicit conversions. Hubis posted:Not to be a style nudge (and recognizing this may be existing code you just can't re-factor)
|
# ? Oct 27, 2015 02:58 |
|
Multiple implicit conversion is scary as hell to me anyway. A might have a really big overhead. B = 5 would construct an A and then copy it to B completely silently without you even knowing it was happening. And if you did know, why didn't you just make the A and assign it (= A(5)) in the first place. Also even without overhead it still seems hosed to me because A could do whatever wacky things with the arguments to then pass in to B, and you wouldn't even know it was happening unless you knew B didn't have an int constructor and it was being delegated through A. Sounds like the source of some potential really nasty bugs, where A is buggy and you never made an A yourself but now B is being silently bugged out because of it. Jewel fucked around with this message at 04:01 on Oct 27, 2015 |
# ? Oct 27, 2015 03:58 |
|
That's why constructors like that should be marked as explicit unless you have a good reason not to.
|
# ? Oct 27, 2015 10:26 |
|
Diametunim posted:Seeking some advice on how to clean up some code I recently wrote for my Operating Systems class. Everything in my assignment "Pirates.c" appears to function to the assignment requirements but I feel like I wrote the solution like poo poo; anyone mind pointing out some glaringly obvious things I can clean up? I've attached an incorrect solution but it uses a struct for each threads data. I believe that idea might lead to a better solution but could anyone take a look at it and tell me if that method is even possible for this assignment. Do you really need both a mutex and a condition variable to wait on the "occupied" value? Doesn't the mutex being locked already model the condition that only one pirate (thread) can be in the cave (critical section)? I think your problem in Incorrect.c might just be that you're doing "occupied = 1; if (occupied == 1) {"? Like, each thread is gonna block itself. Otherwise it looks about right. Also please compile with warnings.
|
# ? Oct 27, 2015 21:05 |
|
Jewel posted:Multiple implicit conversion is scary as hell to me anyway. A might have a really big overhead. The above code would work fine if I wrote B c(5); or B c = { 5 }; instead of B c = 5; which is a little puzzling to me. But also that seems like it's still going to incorporate the potential problems you mentioned -- it's not at all obvious by looking at that that an A constructor is being called, right? I suppose enforcing a style of always making explicit constructors would solve it? The same issue can come up beyond initializing a variable: void Foo(B); Foo(5); // works on msvc Foo({5}); // works on gcc However, whoever wrote B should have some idea of what A is doing in its constructors because it's using it. It's not like some mystery code is being wedged in between the two, at least in this case. Sex Bumbo fucked around with this message at 22:37 on Oct 27, 2015 |
# ? Oct 27, 2015 22:28 |
|
Good code or best code?code:
|
# ? Oct 28, 2015 12:53 |
|
Mozilla's rr reverse debugger has a stable release with the reversing stuff fully enabled (they describe being able to reverse from exit to invocation of main for a Firefox run): http://robert.ocallahan.org/2015/10/rr-40-released-with-reverse-execution.html I've only played with it a little bit, but it is pretty incredible so far.
|
# ? Oct 28, 2015 14:32 |
|
I'm currently having some trouble converting a 32 bit string into a 32 bit unsigned intcode:
I've tried using std::bitset<32> chunkWord(chunkString) but I get an invalid argument exception. Any help would be great.
|
# ? Oct 31, 2015 19:42 |
|
Bitsets do input/output with strings using the ASCII digits "0" and "1" (or some locale-specific digits!), not the raw bits of the characters. You'd be better off casting the characters in the std::string to unsigned char, and casting that to uint32_t, and then combining them together with bitwise ops. Or use a union or something, depending on whether you want platform-specific byte order...
sarehu fucked around with this message at 19:58 on Oct 31, 2015 |
# ? Oct 31, 2015 19:56 |
|
I'm currently working on an assignment for a graphics class using Opengl, but I've run into a snag. I want to use glPushMatrix/glPopMatrix to affect translations/rotations on individual objects in my scene, but... well it isn't having any effect. My display function currently looks like:code:
code:
I've read some examples that have the matrix mode set to GL_MODELVIEW and some that don't, but setting it to Model View right before pushing the matrix, and then back to Projection after popping the matrix does nothing either. What am I missing here? Other potentially pertinent info: Main code:
code:
JawKnee fucked around with this message at 20:21 on Oct 31, 2015 |
# ? Oct 31, 2015 20:16 |
JawKnee posted:I'm currently working on an assignment for a graphics class using Opengl, but I've run into a snag. I want to use glPushMatrix/glPopMatrix to affect translations/rotations on individual objects in my scene, but... well it isn't having any effect. I don't really know much about OpenGL, but aren't glPushMatrix/glPopMatrix from the old-style fixed-function rendering pipeline? Which should be inactive since you're using a vertex shader?
|
|
# ? Oct 31, 2015 20:36 |
|
JawKnee posted:I feel like I must be missing something simple wrt using the push/pop functions properly. Your vertex shader doesn't use any of the builtin matrices so pushing and popping a matrix doesn't do anything.
|
# ? Oct 31, 2015 20:39 |
|
nielsm posted:I don't really know much about OpenGL, but aren't glPushMatrix/glPopMatrix from the old-style fixed-function rendering pipeline? Which should be inactive since you're using a vertex shader? Hmm, yeah it appears so. So many deprecated functions!
|
# ? Oct 31, 2015 20:41 |
|
sarehu posted:Bitsets do input/output with strings using the ASCII digits "0" and "1" (or some locale-specific digits!), not the raw bits of the characters. You'd be better off casting the characters in the std::string to unsigned char, and casting that to uint32_t, and then combining them together with bitwise ops. Or use a union or something, depending on whether you want platform-specific byte order... Hey, thanks for the suggestion. Here's what i ended up doing to get it working: code:
|
# ? Oct 31, 2015 20:44 |
|
JawKnee posted:Hmm, yeah it appears so. So many deprecated functions! Nothing in your shader accesses the fixed-function matrices anyway. Compute the matrixes you need on the CPU, since you typically only need to change them once per frame, and sometimes even less often than that (like the projection matrix), and pass them into your vertex shader as uniforms. That way you aren't recomputing them for every vertex. Pass in the modelViewProjection matrix, plus occasionally the model matrix and/or viewProjection matrix and a normal matrix depending on what lighting effects etc you're going for. And you'll save yourself a lot of headaches in the future of you learn the difference between the model, view, and projection matrix (and why the OpenGL fixed-function pipeline combined the model & view matrices into one modelView matrix). I speak from experience
|
# ? Oct 31, 2015 23:29 |
|
elite_garbage_man posted:Hey, thanks for the suggestion. Here's what i ended up doing to get it working: or code:
|
# ? Nov 1, 2015 00:27 |
|
That alternative will have different behavior on little-endian systems, if I'm reading the documentation correctly.
|
# ? Nov 1, 2015 00:37 |
|
|
# ? Jun 1, 2024 13:03 |
|
Doc Block posted:Nothing in your shader accesses the fixed-function matrices anyway. Thanks for the advice, I appreciate it. I'm currently working on implementing my own matrix stack and it appears to be working as intended so far.
|
# ? Nov 1, 2015 01:04 |