Jump to content
  • Advertisement
Sign in to follow this  
tom_mai78101

Can't seem to pass inherited class members to D3DXLoadSurfaceFromFile()

This topic is 2766 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Here are the codes:


Test.cpp

[source lang="cpp"]


#include "Sprites.h"

LPCTSTR Test_BMP::getFileName()
{
LPCTSTR file = "C:\\test.bmp";
Test_BMP::FileName = file;
return file;
}

bool Test_BMP::getAttributes()
{
HRESULT hResult = D3DXGetImageInfoFromFile(Test_BMP::getFileName(), &(Test_BMP::Image_Info));
if (hResult != D3D_OK)
{
DWORD error = GetLastError();
char errorString[32];
sprintf_s(errorString, "Error: %x", error);
MessageBox(NULL, TEXT(errorString), TEXT(__FUNCTION__), MB_OK);
return false;
}
if (Test_BMP::FileName != NULL)
{
hResult = D3DXLoadSurfaceFromFile(Test_BMP::Surface, NULL, NULL, Test_BMP::FileName, NULL, D3DX_DEFAULT, 0, NULL);
if (hResult != D3D_OK) //D3DERR_INVALIDCALL Problem!!
{
char errorString[32];
sprintf_s(errorString, "Error: Line %d", __LINE__ - 4);
MessageBox(NULL, TEXT(errorString), TEXT(__FUNCTION__), MB_OK);
return false;
}
}
else
return false;
return true;
}


[/source]


And this is "Sprite.h"

[source lang="cpp"]

#include "Core.h"
#include "main.h"

class Sprite
{
public:
LPCTSTR FileName;
RECT SourceRect;
RECT DestinationRect;
LPDIRECT3DSURFACE9 Surface;
D3DCOLOR TransparentColor;
D3DXIMAGE_INFO Image_Info;
//-----------------------------------------------------
Sprite();
~Sprite();
bool Blit();
bool SetRects(RECT Source, RECT Destination);
virtual LPCTSTR getFileName();
virtual bool getAttributes() = 0;
};

class Test_BMP : public Sprite
{
public:
LPCTSTR getFileName();
bool getAttributes();
};

[/source]


What it will do when the program run, it will pop-up a message box saying that on Line 23, it returned D3DERR_INVALIDCALL error. There are some functions I didn't use from Sprite.h. I have given the D3DXLoadSurfaceFromFile() the most minimal valid parameters, yet it still failed. That, my friend, is a nutty problem.

Due to that, I've decided to upload all of my project's source code, so as to let everyone see what's the problem. Thanks in advance to those who are helping out, as I'm beat from debugging this for over [size="4"]56 hours straight... since 5/12/2011.


[size="5"]EDIT: I have uploaded my project folder, along with a README.txt inside. That way, everyone can see it obviously.

[attachment=2189:My Project.zip]

Share this post


Link to post
Share on other sites
Advertisement
Through the process of debugging when you stepped through each param are they valid? i.e. Surface = LPDIRECT3DSURFACE9 & FileName = LPCTSTR?
I know you probably debugged this six ways to Sunday...cool.gif just trying to wrap my head around why an inherited member would be causing you an issue...strange indeed.

Share this post


Link to post
Share on other sites

Through the process of debugging when you stepped through each param are they valid? i.e. Surface = LPDIRECT3DSURFACE9 & FileName = LPCTSTR?
I know you probably debugged this six ways to Sunday...cool.gif just trying to wrap my head around why an inherited member would be causing you an issue...strange indeed.





Yes. All returned valid. It has all correct content in each of the parameters.

Also, for some reason, the first post does not contain my project files. I'd better put them here. My project requires a BMP picture in the C: hard drive, or a valid file path for any BMP files. The BMP image is included in the project ZIP file.

EDIT 2: Forum file upload is broken. ZIP files become headerless ZIP files. Please add the extension name ".ZIP" at the end.


EDIT 3: ZIP file is now located at the very top and at very bottom.

Share this post


Link to post
Share on other sites
Hey Tom :cool: just now getting back to this post. Thanks for uploading the project. I'll look at it today and get back to you later this evening unless you have already figured it out or moved on.

Share this post


Link to post
Share on other sites
You're all set...you are going to kick yourself when you see what I changed wink.gif I've attached a screenshot to show I got it running.

Cheers...

Share this post


Link to post
Share on other sites

You're all set...you are going to kick yourself when you see what I changed wink.gif I've attached a screenshot to show I got it running.

Cheers...


Um. I couldn't see what changes have you added (it's not obvious :unsure: ). Is it okay if you can tell me? Can you blit out the "test.bmp" via inheritence?

I did check the source code you've uploaded, and then I looked at your screenshot. You might have mistaken the problem with with the error at hand. :(

The correct results should be a "test.bmp" being blit to the screen, while at the same time, it is able to inherit the Sprite class.

Share this post


Link to post
Share on other sites

What it will do when the program run, it will pop-up a message box saying that on Line 23, it returned D3DERR_INVALIDCALL error. There are some functions I didn't use from Sprite.h. I have given the D3DXLoadSurfaceFromFile() the most minimal valid parameters, yet it still failed. That, my friend, is a nutty problem....



Hi Tom ;)

No biggie, I was only stating that you were going to kick yourself because I only changed one thing code wise. The source you posted for download had this line in it...

[source lang="cpp"]
HRESULT hResult = D3DXGetImageInfoFromFile(&Test_BMP::getFileName(), &(Test_BMP::Image_Info));
[/source]

When I initially attempted to compile, the compiler complained about the LPDIRECT3DSURFACE9 property for that method couldnt be converted to something else.

After changing it to this...

[font="Arial"][source lang="cpp"][/font]
HRESULT hResult = D3DXGetImageInfoFromFile(Test_BMP::getFileName(), &(Test_BMP::Image_Info));
[/source]


It compiled with no issues. The other thing I did was go through and add all the proper DX lib files to the project but I assuming you were not getting any linker errors either. Anyway, I did not alter the rest of the source code in any other way. When the application executed, it followed whatever logic you had in place; something that appeared to be an endless loop of changing the background color from "Yellow" and then to "Black". Also, there were message boxes from your code displaying on the screen which appeared to validate entry into other methods.

That's about it bro...no errors, compiled...executed...I never got that "Line 23, D3DERR_INVALIDCALL error" ... :unsure:

Share this post


Link to post
Share on other sites
Untitled.png



Huh? All I did was replace the source codes in my project with yours, did check to see if it contains your change, which it did, then rebuild, compile, run it, and I get this. :o As far as I can tell, that error you get in your screenshot, it meant to say that the "test.bmp" is missing. I should revise my error messages so that it's more understandable. I apologize about that.

Did you have the "test.bmp" in the C:\ directory? (The file location should be in full name: "[color="#00bfff"]C:\test.bmp") I've already placed the picture in the ZIP file in my earlier post, and just wanting to check to see if you have that picture there. ;)

Share this post


Link to post
Share on other sites
Bump. Please help while you can. I can guarantee you, I can confuse you with my code. :rolleyes:

Here's the project folder, in case you have actually missed the first post. Instructions inside! ;)



[attachment=2336:My Project.zip]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!