ataylor Posted April 14, 2015 Share Posted April 14, 2015 #include <core/unigine.h> class MyClass{ int memberVar=1; MyClass() { int localVar=2; log.message("localVar %d memberVar %d", localVar, memberVar); breakpoint; } }; int init() { MyClass foo=new MyClass(); return 1; } log.message output shows localVar as 2 and memberVar as 1, as expected. breakpoint hits, I type 'list' in debugger window: list Variables: MyClass::localVar: int: 2 MyClass::memberVar: int: 0 I would expect debugger to report MyClass::memberVar with value of 1, but it reports 0. Why is this? Link to comment
unclebob Posted April 16, 2015 Share Posted April 16, 2015 Hi Adam! You can't initialize member variables that way (think of them as C++ member variables, not C#) and by default all member variables are initialized to zero. That explains why you have such values. Link to comment
ataylor Posted April 16, 2015 Author Share Posted April 16, 2015 Hi Andrey. Sorry, it's still not clear to me what I did incorrectly vs. what the right way to do this is. Could you clarify by posting wrong vs. right example, or link me to specific place in documentation where this is explained? If my member variable initialization is incorrect, why does log.message show "correct" value of 1 while debugger still shows 0? Whether I did something properly or not, I would expect them to agree. I tried altering MyClass, moving memberVar initialization to constructor instead of declaration: class MyClass{ int memberVar; MyClass() { int localVar=2; memberVar=1; log.message("localVar %d memberVar %d", localVar, memberVar); breakpoint; } }; but this gives me identical behavior as first post -- log.message reports memberVar as 1 while debugger reports it as 0. Please help. Link to comment
unclebob Posted April 19, 2015 Share Posted April 19, 2015 Adam, Thanks for clarification! It could be a bug in debugger, I'll check that and report back. Link to comment
unclebob Posted April 21, 2015 Share Posted April 21, 2015 Adam, I checked debugger code and indeed it has a bug. What it's trying to show is namespace and local variables, not instance variables. Since interpreter knows "MyClass" is a namespace, it tries to see "MyClass::memberVar" variable value and prints zero instead. On the other hand, log.message function use instance variable and will print correct value. Thanks again for noticing that! Link to comment
ataylor Posted April 21, 2015 Author Share Posted April 21, 2015 Okay. Thanks for investigating this. I will leave that portion of the debugger alone for now. Link to comment
silent Posted April 29, 2015 Share Posted April 29, 2015 This bug was added to our internal bug tracker. Thanks for the test case! How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN Link to comment
Recommended Posts