Thread: C2668 - Ambiguous Call to Overloaded Function

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    23

    C2668 - Ambiguous Call to Overloaded Function

    I have a problem with my code, and I need some help... I'm doing some testing with DirectX8 and I'm trying to use sin() and cos() to assist me(yes, I have math.h included), but when I do, I get a C2668(error referenced in thread title). The code in question is below... Can someone help me?

    Code:
    	int iX, iY;
    	for(iY = 0; iY < 256; iY++) {
    		for(iX = 0; iX < 256; iX++) {
    			int iPower = (int)(sin(iX * iY) * 128 + cos(iX * iY) * 128);
    			piSurfaceBuffer[iX + iY* (kLockedRect.Pitch >> 2)] = D3DCOLOR_XRGB(iPower, iPower, iPower);
    		}
    	}

  2. #2
    Registered User
    Join Date
    Oct 2005
    Posts
    23
    Oh, right. I forgot to tell which functions are generating the error. lol It's sin() and cos()... Which is what makes it so damn confusing.

  3. #3
    Unregistered User
    Join Date
    Sep 2005
    Location
    Antarctica
    Posts
    341
    are you using stl and using namespace std globally? Try casting:

    Code:
     
    sin((double)iX * iY);
    
    or just:
    
    ::sin(iX * iY);

  4. #4
    Registered User
    Join Date
    Oct 2005
    Posts
    23
    The first one got it, thanks. =) But now I'm getting a runtime error... =/

    Code:
    Unhandled exception at 0x6d9ee684 in game_prog_2.exe: 0xC0000005: Access violation reading location 0x00000000.
    And then when I break it off, this is the line of code it points me to as having generated that error:

    Code:
    m_pD3DDevice->CopyRects(m_pD3DSurface, NULL, 0, pBackBuffer, NULL);
    Any ideas?

  5. #5
    Unregistered User
    Join Date
    Sep 2005
    Location
    Antarctica
    Posts
    341
    I don't understand what you are doing, You are trying to read 0 bytes from a NULL pointer and write to a buffer given a NULL position? Whatever the problem is, it involves a NULL pointer since the access error is given at location 0x00000000. It could be that CopyRects does not allow a source pointer to be NULL even if the byte size is 0, it also could be that m_pD3DDevice is NULL, and it could be that you can't give it a NULL parameter for the last parameter either. pBackBuffer should be ok since that's a write and this error is on a read.

  6. #6
    Registered User
    Join Date
    Oct 2005
    Posts
    23
    I narrowed it down to a problematic function:

    Code:
    m_pD3DDevice-&gt;CreateImageSurface(256, 256, (D3DFORMAT) m_iD3DFormat, &m_pD3DSurface)
    It assigns a memory value of 00000000 to m_pD3DSurface and the function fails... Any ideas as to how to fix it?

  7. #7
    Unregistered User
    Join Date
    Sep 2005
    Location
    Antarctica
    Posts
    341
    make sure that your D3DFORMAT structure is properly initialized, also check the return value of the function

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. dllimport function not allowed
    By steve1_rm in forum C++ Programming
    Replies: 5
    Last Post: 03-11-2008, 03:33 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. how to get function call stack
    By George2 in forum C Programming
    Replies: 18
    Last Post: 11-11-2006, 07:51 AM
  4. Calling a Thread with a Function Pointer.
    By ScrollMaster in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2006, 08:56 AM
  5. ambiguous call to overloaded function
    By LurPak in forum C++ Programming
    Replies: 2
    Last Post: 09-05-2003, 03:37 AM