Very weird pointer error in 2005 in release

This is a discussion on Very weird pointer error in 2005 in release within the C++ Programming forums, part of the General Programming Boards category; While in the process of compiling my game engine thus far into a static lib I ran into a very ...

  1. #1
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,584

    Very weird pointer error in 2005 in release

    While in the process of compiling my game engine thus far into a static lib I ran into a very strange error.

    The declarations in my class are:

    Code:
    ...
    DXInput *m_pInput;
    DXMouse *m_pMouse;
    DXKeyboard *m_pKeyboard;
    ...
    And the code to new them up is:
    Code:
    ...
    m_pInput = new DXInput();
    if (!m_pInput)
    {
        return false;
    }
    m_pInput->Init(m_hAppInstance);
    
    m_pKeyboard = new DXKeyboard();
    if (!m_pKeyboard) 
    {
        return false;
    }
    m_pKeyboard->Init(m_pInput,m_hAppInstance,m_hwndAppWindowHandle);
    
    m_pMouse = new DXMouse(m_pInput->GetInterface());
    if (!m_pMouse) 
    {
        return false;
    }
    m_pMouse->Init(m_hwndAppWindowHandle);
    ...
    The errors in release mode - and only in release mode:
    1>..\src\D3DApp.cpp(61) : error C2440: '=' : cannot convert from 'DXInput' to 'DXInput *'
    1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
    1>..\src\D3DApp.cpp(64) : error C2440: '=' : cannot convert from 'DXKeyboard' to 'DXKeyboard *'
    1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
    1>..\src\D3DApp.cpp(71) : error C2440: '=' : cannot convert from 'DXMouse' to 'DXMouse *'
    1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
    Release build wants me to put the address of operator before the new but debug build then throws up this which is expected:

    1>e:\dev\x3dlib\src\d3dapp.cpp(61) : error C2102: '&' requires l-value
    1>e:\dev\x3dlib\src\d3dapp.cpp(64) : error C2102: '&' requires l-value
    1>e:\dev\x3dlib\src\d3dapp.cpp(71) : error C2102: '&' requires l-value
    This is clearly a compiler goof up and I do not know how to get past it.
    Last edited by VirtualAce; 08-27-2009 at 09:11 PM.

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,383
    Damn me if that isn't the weirdest thing.

    Are you using templates? Might be a long shot but move the DXInput header file to the top of your includes list and see if that gets you rid of the first error.

    EDIT: To clarify, assuming everything is indeed alright with your code, what I'm thinking is you may be able to circumvent this apparent bug by juggling your includes around.

    EDIT 2: Do also a full rebuild... are you by chance reusing an old object file that the compiler didn't catch?... I'm fishing here but once I couldn't find a t-shirt anywhere that I had just finished ironing. After going nuts I found it in my freezer. It turns out absent mindedly I left it there when I took the chicken out. nuff said.
    Last edited by Mario F.; 08-27-2009 at 09:36 PM.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,584
    Hahahaha. I'm a total idiot.

    You can spot the error here:

    Code:
    #ifdef _DEBUG
       #define new   new( _CLIENT_BLOCK, __FILE__, __LINE__)
    #else
       #define new
    #endif
    Might be nice if I actually defined new back to what it is supposed to be in release mode eh?
    That's why the compiler couldn't figure out what was going on. I tried this line:

    Code:
    int *pArray = new int[50];
    And it said type 'int' unexpected. Hahahahaha.

    What a waste of time tonight hunting down a compile error that had nothing to do with the lines of code the compiler was complaining about. I love macros. Ok so coming home after a long day at work and doing yet more programming might not be such a good idea after all.

  4. #4
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,383
    Ah. You found your t-shirt!
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  5. #5
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489
    Quote Originally Posted by Bubba View Post
    Code:
    ...
    m_pInput = new DXInput();
    if (!m_pInput)
    {
        return false;
    }
    m_pInput->Init(m_hAppInstance);
    
    m_pKeyboard = new DXKeyboard();
    if (!m_pKeyboard) 
    {
        return false;
    }
    m_pKeyboard->Init(m_pInput,m_hAppInstance,m_hwndAppWindowHandle);
    
    m_pMouse = new DXMouse(m_pInput->GetInterface());
    if (!m_pMouse) 
    {
        return false;
    }
    m_pMouse->Init(m_hwndAppWindowHandle);
    ...
    Why you don't destroy anything before the return statement?
    Just GET it OFF out my mind!!

  6. #6
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    Quote Originally Posted by audinue View Post
    Why you don't destroy anything before the return statement?
    Actually he is right Bubba, the first allocation is fine, but the second and third should delete the objects that did succeed, unless you are handling those conditions elsewhere that we don't see.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  7. #7
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,584
    Nope it will just crash which will take about 1 minute to find and fix. That was not the point of this thread, however. The error has been fixed and now it works just fine.

    Why you don't destroy anything before the return statement?
    And the code to new them up is:
    Why do you assume I have to destroy anything in this section of code? I gave you no indication as to where this code was but if you must know it is the setup for the system. Wouldn't do much good to destroy what I just created. If I was really concerned with checking the pointers, and I'm not, I would not use raw pointers and would switch to boost pointers. If you cannot get directinput, the mouse, or the keyboard up and running the system is dead in the water anyways and the only way to recover would be to exit...which is going to happen if it crashes.
    Last edited by VirtualAce; 08-28-2009 at 04:34 PM.

  8. #8
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    611
    Cmon, now don't be too harsh on him, anybody can write a piece of code in which 45% will never ever execute. I'm sure it's great in other areas.

    Quote Originally Posted by Bubba View Post
    Even my crappy little D3D framework...
    Oh...
    Last edited by adeyblue; 08-28-2009 at 05:39 PM.

  9. #9
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,584
    Why are you quoting items that are not in this thread?

  10. #10
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,159
    Quote Originally Posted by Bubba View Post
    Why are you quoting items that are not in this thread?
    There's no need to get defensive... It's natural for any good programmer, when looking at a piece of code, to point out potential problems. If I were looking at that piece of code during a review I'd be asking the same questions -- where are those allocations handled if a failure occurs?

    This week at work I spent a total of about 10 hours defending my code in code review. (I mean "defending" in the sense of a Ph.D thesis, not that people were attacking my code.) It was exhausting, but I'm glad we did it, as it found a few problems I hadn't seen.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  11. #11
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,584
    Not getting defensive. Feel free to critique the code or do whatever makes you feel happy and I'll move on to other things. I did not ask for a code review and when the answer was found I stated it very clearly meaning I thought the discussion was over. If I wanted a code review maybe I would have titled the thread something along those lines. But if you want to review it feel free - if that's what really gets you going then go for it.

    We all have code reviews and we all learn from them but this thread is not a code review. However if you wish to review my code then perhaps I will post some of it in a thread and get your take on it. I'm certainly not above learning.
    Last edited by VirtualAce; 08-29-2009 at 12:38 PM.

  12. #12
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    Quote Originally Posted by Bubba View Post
    Not getting defensive.
    :/ Didn't mean to take a dump in your cheerios man, just pointing out a mistake I myself have made before. That's the thing about DirectX, 90% of your code is error detection/correction stuff that will rarely if ever get executed, but you gotta have it there as a safeguard. Particularly for your demo code, since it looks really unprofessional if your applications crashes without giving some indicator of what happened.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. weird pointer issue
    By Chaplin27 in forum C++ Programming
    Replies: 5
    Last Post: 08-01-2006, 09:20 AM
  2. VC++ 2005 Express: Weird Behaviour
    By psychopath in forum Tech Board
    Replies: 2
    Last Post: 06-21-2006, 07:47 PM
  3. Weird struct pointer return
    By Devil Panther in forum C Programming
    Replies: 2
    Last Post: 07-24-2005, 12:05 PM
  4. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 08:32 AM
  5. Multithreads & Pointer to bool :: MFC
    By kuphryn in forum Windows Programming
    Replies: 7
    Last Post: 06-26-2002, 10:50 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21