|
Okay thanks for your inputs. It looks like what I need to do is have the thread that is handling the window events also create the windows. It must be a problem that One thread creates the window, and another is trying to handle the events. Edit: I got it working. I made it so my windowing thread can accept "messages" from other threads about what windowing commands to run. Its more of a pain, but at least it works. Thanks again! Harokey fucked around with this message at 18:27 on Jan 17, 2011 |
# ? Jan 16, 2011 20:08 |
|
|
# ? Jun 8, 2024 08:31 |
|
I think I got all confused in the discussion of threads and windows here. I think the general rule is to assume the GUI toolkit is a single thread--including the code that gets called out of it (your callbacks). You don't have to set up some kind of hierarchy to maintain some kind of drawing context from a master window. Rather, everything you create has to just get in the line on the GUI thread to be handled. I spent a lot of the weekend figuring out some more obscure GUI stuff. I guess you really do have to grind through this a little bit to develop an appreciation for some of the oddball crap. I was finding that a group class containing a GL canvas I was creating in FLTK after I had started the FLTK routines would not display correctly, even if I had told them to be shown. Any that were instantiated before I started the FLTK routine (Fl::run()) drew fine. I guess after Fl::run() starts, you have to tell all the children components of your custom class to be shown too, not just yourself. So it was showing my group was technically being shown, but none of its children were being shown by default. At least the FLTK people are generally responsive and don't sneer at you to google until your fingers fall off, so I will try to send them a simple case of this. I was also hoping to do drag and drop with it. I actually got that working after much gnashing of teeth. However I see it's doing a system-wide drag and drop so my message can get dumped on the desktop even if I don't want it. The alternative is to write your own kind of drag and drop feature, but I found out only the highlighted window handles events. So I can't readily have the target area start accepting mouse events that would suggest something it being sent to it. GUI's really are a pain in the butt.
|
# ? Jan 17, 2011 18:47 |
|
code:
|
# ? Jan 19, 2011 03:01 |
|
GrumpyDoctor posted:
Assuming get_contained returns the field contained, that should be fine. It'll return a pointer to the field inside foo, which will exist as long as foo exists. Just make sure that function_that_needs_a_pointer_to_a_contained doesn't store the pointer for longer than the lifetime of the foo you're passing in and try to use it later.
|
# ? Jan 19, 2011 03:10 |
|
pr0metheus posted:I was having issues with boost's dynamic_bitset. In my program I have a tree data structure where each node is an instance of a class which has one dynamic bitset as a member variable. I allocate my tree on heap, and clean it up when my program is done. The issue I am running into is apparent memory leaking from dynamic_bitset's = operator. Valgrind is reporting that new operator that is called as result of calling = operator on dynamic_bitset at some point in course of my program never has an associated delete. I am quite positive that I am cleaning up my entire tree properly, and valgrind doesn't bitch about any node allocation which makes me think I did my job right. Smells like a leak in your DFA's copy constructor. As a rule of thumb, if Valgrind reports a leak from a standard library class, the real leak is at the boundary between your code and the standard library.
|
# ? Jan 19, 2011 13:10 |
|
I hope this is a good place to ask this question. There isn't an assembly or SIMD thread I can find. I've been writing a raytracer in C++, and recently discovered SIMD and SSE. I've successfully gotten great dividends from vectorizing rays, though I left (currently only) sphere intersection code in normal C++. I recently decided that using a structure of arrays and processing ray packets would be faster than vectorizing single calculations on every ray. I've written a RayPacket class that passes all the unit tests I throw at it, but there's an issue with vectorizing the intersect code in my Sphere class. Edit: It appears that SQRTPS does actually behave as I expected, and generates QNaNs appropriately. I had an ADDPS instruction when determining the discriminant instead of a MULPS instruction. There's still a very strange issue happening with the target test sphere being the color of the background and the background being the color of the sphere, but at least now there's a coherent image. Theseus fucked around with this message at 22:46 on Jan 20, 2011 |
# ? Jan 20, 2011 00:34 |
|
This has got me puzzled in C. I'm opening, and reading, through a file on a machine with fread(). This read works perfectly fine, but I wanted it to be able to handle an error should one arise. I have something like this: code:
|
# ? Jan 21, 2011 16:30 |
|
Risible posted:It looks as if after fread() returns with the error, it also frees what memory was allocated to buffer. Since it frees the memory, my call to free(buffer) causes the program to crash. Is this right? Is fread() suppposed to free memory when it encounters an error like this?
|
# ? Jan 21, 2011 20:22 |
|
I'm having some issues compiling a unicode string class I wrote in GCC 4.5. It used to work fine, but I recently re-programmed the iterator to work in STL algorithms and everything broke horribly. It works just fine in Visual Studio 2010, but it generates a lot of errors in GCC 4.5. Here is a zip file containing the class (irrUString.h), an extremely simple test program, and a couple headers required for irrUString.h to compile (it was developed to be integrated with the Irrlicht engine, so a couple Irrlicht-specific headers are required.) http://irrlicht.suckerfreegames.com/test/ustring.zip Just compile it like this: g++ main.cpp -std=c++0x Can anyone tell me why it is failing to see the typedefs defined in std::iterator? Do I really have to throw in a typename everywhere I use a typedef'ed name in order to get this thing to work? If anyone could tell me what I am doing wrong, I would much appreciate it.
|
# ? Jan 24, 2011 08:26 |
|
http://www.parashift.com/c++-faq-lite/templates.html#faq-35.18
|
# ? Jan 24, 2011 13:42 |
|
OddObserver posted:http://www.parashift.com/c++-faq-lite/templates.html#faq-35.18
|
# ? Jan 24, 2011 15:02 |
|
Here is something to test your pedantic C knowledge:code:
|
# ? Jan 25, 2011 19:43 |
|
CapnBry posted:Here is something to test your pedantic C knowledge:
|
# ? Jan 25, 2011 19:53 |
|
Scaevolus posted:It's doing pointer arithmetic. The type of (buffer - 1) is char*, so it's equivalent to sizeof(char*).
|
# ? Jan 25, 2011 20:31 |
|
Woo! Wrong on all counts. I'm going to go caffeinate myself. pseudorandom name fucked around with this message at 20:49 on Jan 25, 2011 |
# ? Jan 25, 2011 20:33 |
|
CapnBry posted:I got the pointer math part, but how is the type of buffer[-1]/buffer-1 a char*?
|
# ? Jan 25, 2011 20:43 |
|
Sneftel posted:Better you should ask "how is the type of buffer not a pointer"? The answer is, arrays "decay" (automatically convert into) pointers when used in almost any context. buffer[0] converts to a pointer, then applies the subscripting operator. buffer-1 converts to a pointer, then applies subtraction. CapnBry fucked around with this message at 21:20 on Jan 25, 2011 |
# ? Jan 25, 2011 21:02 |
|
I'm writing a C++ program and I've come to a design aspect that I don't know how to nicely solve. My program plays a board game. I will be writing several decision algorithms on how to play (basically variations of one another). Each of these algorithms will use a heuristic to evaluate how good a board position is at various points. How the evaluation heuristic is calculated is totally separate from the specific decision algorithm used. I would like to be able to easily mix and match decision algorithms with heuristics. One obvious solution is multiple inheritance with separate abstract base classes for the decision algorithms and the heuristics. Then a full strategy is formed by inheriting a decision algorithm and a heuristic. I'm not particularly enthusiastic about this option because the number of classes I'd have to write is the product of the number of decision algorithms and evaluation heuristics which grows quickly when trying variations of heuristics, even if the classes are essentially trivial. Is there a better way to do this than multiple inheritance?
|
# ? Jan 26, 2011 07:08 |
|
6174 posted:I'm writing a C++ program and I've come to a design aspect that I don't know how to nicely solve. I like templates a lot with this type of thing.
|
# ? Jan 26, 2011 07:13 |
|
Well, you can solve the problem of having to write M x N classes by using a template which subclasses two classes given by its template parameters, but I think the better solution is to repeatedly electrocute the part of your brain that's convinced itself that these two things absolutely have to be allocated as part of the same object until it sees the error of its ways.
|
# ? Jan 26, 2011 07:15 |
|
TheBoogeyMan posted:I like templates a lot with this type of thing. That sounds like a nice solution, but I'm not sure how to make templates do this. Do you have any examples or search terms which would reveal some examples?
|
# ? Jan 26, 2011 07:15 |
|
As rjmccall said, you absolutely positively want to have your evaluation function over here and the decision algorithm over there. Most likely the former should (in functional terms) simply be passed in to the latter as an argument.
|
# ? Jan 26, 2011 08:17 |
|
Make an algorithm and a heuristic interface (pure abstract class) and write all your code conforming to the interfaces, with both as separate objects. Make factories that can construct the classes by name. Create the two things using the factories. Easily change your algorithm/heuristic at run-time by just swapping the two things out as desired by name. Decide for yourself whether you want to have the caller store both algorithm and heuristic and pass the heuristic to the algorithm when necessary or whether you just want to create an algorithm and pass it the name of the heuristic on creation and it can then store and manage the heuristic object itself.
|
# ? Jan 26, 2011 15:31 |
|
Do it C-style, and just have the object take two function pointers, one "Heuristic" and one "Decision". The functions will take as a parameter a pointer to the object. Or you can make it member function pointers so you don't have to work with an explicit 'this', but member function pointers are horrible and should be shot in the face.
|
# ? Jan 26, 2011 17:18 |
|
I am losing a fight with the preprocessor. A third-party header file has a section that looks like this: code:
I feel like there's something fundamental I don't know about preprocessor defines, but obviously I don't know what it is. How can I fix this or at least figure out what the problem is?
|
# ? Jan 27, 2011 01:18 |
|
GrumpyDoctor posted:I feel like there's something fundamental I don't know about preprocessor defines, but obviously I don't know what it is. It doesn't look like you're doing anything wrong -- is this the exact snippet of code that's exhibiting the behavior you are describing? Also, forgive my asking, but are you absolutely sure it's not taking the 2nd path? Maybe the third file includes the first two anyway which is why you are thinking that the first path is taken. Have you tried putting a #error immediately after the #if or the #else to see where you get? Edit: Just out of curiosity, have you tried explicitly defining the value to be less than 500?
|
# ? Jan 27, 2011 01:31 |
|
I got it working somehow. I'm not sure how, but I did! The #errors helped with debugging, thanks for the tip.
raminasi fucked around with this message at 03:56 on Jan 27, 2011 |
# ? Jan 27, 2011 03:31 |
|
GrumpyDoctor posted:I tried putting CGAL_LEDA_VERSION 630 in the Visual Studio "preprocessor defines" section of the project settings and it didn't work.
|
# ? Jan 27, 2011 16:41 |
|
I'm working with ANSI C for a class assignment to make a buffer:code:
But I'm not allowed to change the function prototype, and can't make it unsigned so that it will accept values greater then 127. Am I missing something obvious?
|
# ? Jan 29, 2011 03:52 |
|
Oxyclean posted:I'm working with ANSI C for a class assignment to make a buffer: Compiler flags?
|
# ? Jan 29, 2011 04:07 |
|
Oxyclean posted:I'm working with ANSI C for a class assignment to make a buffer: Cast the parameter to an unsigned char (example).
|
# ? Jan 29, 2011 04:23 |
|
Mr.Radar posted:Cast the parameter to an unsigned char (example). Would this matter though? Can't the value being sent into the function not be greater then 127 because its a char?
|
# ? Jan 29, 2011 04:25 |
|
True ANSI C shouldn't assume the signedness of char, so if the caller expects you to use a number between 1 and 255, they should have specified "unsigned char" in the function prototype.
|
# ? Jan 29, 2011 04:25 |
|
Oxyclean posted:Would this matter though? Can't the value being sent into the function not be greater then 127 because its a char? Look at my example. I passed the value 224 and recovered it with the cast. It works because the types char and unsigned char both use the same number of bytes/bits which means the cast only impacts how the compiler interprets those bits (i.e. as a signed number in the range -128..127 or an unsigned number in the range 0..255).
|
# ? Jan 29, 2011 04:32 |
|
I've got a question about const. I've got a class that does some mathematical work. It's got several Set functions to set the inputs, and several Get functions to get the outputs. It's set up to use lazy evaluation, so any time a Set, it's marked as dirty, and any time a Get function is called, it recalculates the values only if it's marked as dirty. This has the problem of making the Get functions not const, because they need to modify the data members when updating. I'm currently using const_cast to get around this: code:
|
# ? Jan 29, 2011 17:50 |
|
Paniolo posted:I'm wondering if this is considered an appropriate use of const_cast, or if the "right" thing to do in this case would be to simply not mark the getters as const (which potentially breaks a lot of const correctness throughout the code.) What you are looking for is the 'mutable' key word. It purpose is for lazy evaluation/caching calculations.
|
# ? Jan 29, 2011 18:00 |
|
Brain Candy posted:What you are looking for is the 'mutable' key word. It purpose is for lazy evaluation/caching calculations. Can't believe I didn't know about that. Thanks a lot.
|
# ? Jan 29, 2011 18:09 |
|
Let me preface by saying I'm terrible:quote:
This isn't compiling. Can someone tell me why? The compiler is telling me something about not expecting "<" before the for loop?
|
# ? Jan 30, 2011 03:17 |
Nutsack Rangoon posted:Let me preface by saying I'm terrible: Indentation is your friend. code:
A MIRACLE fucked around with this message at 03:29 on Jan 30, 2011 |
|
# ? Jan 30, 2011 03:22 |
|
|
# ? Jun 8, 2024 08:31 |
|
Nutsack Rangoon posted:Let me preface by saying I'm terrible: You've mistyped "<=" as "=<".
|
# ? Jan 30, 2011 03:32 |