🔒 Locked
std::string == NULL???
Advertisement
Original Post
For some odd reason my CBitmap class doesn''t seem to like the following line (m_strFileName is a std::string):
cout << "Loading bitmap: " << m_strFileName.c_str() << endl;
Everytime it throws a System.NullReferenceException on the first line that uses m_strFileName.c_str() (if i take out that line the error is on the line hBitmap = (HBITMAP)LoadImage(NULL, m_strFileName.c_str(), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION)
Any ideas as to why or how to fix it?
P.S. If it means anything sometimes I get errors(from my debugger) saying that it can''t find media file cbàààà~ or can''t find media file [white background, black dot(bullet) that i think is like ASCII char 2].
Well here''s all my constructors for my CBitmap class as well as the first bit of Init:
So i don''t think it could possibly not exist
CBitmap::CBitmap()
{
...
m_strFileName = "";
}
CBitmap::CBitmap(char* strFileName)
{
...
m_strFileName = strFileName;
}
CBitmap::CBitmap(char* strFileName, D3DCOLOR ColorKey)
{
...
m_strFileName = strFileName;
}
CBitmap::CBitmap(char* strFileName, D3DCOLOR ColorKey, int x, int y)
{
...
m_strFileName = strFileName;
}
void CBitmap::Init()
{
HBITMAP hBitmap;
cout << "Loading bitmap: " << m_strFileName << endl;
hBitmap = (HBITMAP)LoadImage(NULL, m_strFileName.c_str(), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);
...
}
So i don''t think it could possibly not exist
quote:
Original post by Leiarchy9
Comparing a char* to a std::string could cause some problems........
--------
"Do you believe in Ghost?"
He is taking the c_str() conversion of the string which should return a pointer to the char array.
If your string is empty then the pointer returned by c_str() should be null.
To see if the string is empty add this:
if(m_strFileName.length() > 0)
{
cout << "Loading bitmap: " << m_strFileName.c_str() << endl;
hBitmap = (HBITMAP)LoadImage(NULL, m_strFileName.c_str(), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);
}
Leiarchy9:
I don''t see where he is comparing it. m_strFileName.c_str() returns a const char* anyway.
if(m_strFileName.length() > 0)
{
cout << "Loading bitmap: " << m_strFileName.c_str() << endl;
hBitmap = (HBITMAP)LoadImage(NULL, m_strFileName.c_str(), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);
}
Leiarchy9:
I don''t see where he is comparing it. m_strFileName.c_str() returns a const char* anyway.
Did you include the header like this:
#include <string>
using namespace std;
I don't know if it would make a difference or not?
EDIT:
I'm not sure then... I don't do .net yet.
-UltimaX-
"You wished for a white christmas... Now go shovel your wishes!"
[edited by - UltimaX on January 1, 2004 11:51:32 PM]
#include <string>
using namespace std;
I don't know if it would make a difference or not?
EDIT:
I'm not sure then... I don't do .net yet.
-UltimaX-
"You wished for a white christmas... Now go shovel your wishes!"
[edited by - UltimaX on January 1, 2004 11:51:32 PM]
quote:
Original post by UltimaX
Did you include the header like this:
#include <string>
using namespace std;
I don''t know if it would make a difference or not?
EDIT:
I''m not sure then... I don''t do .net yet.
-UltimaX-
"You wished for a white christmas... Now go shovel your wishes!"
[edited by - UltimaX on January 1, 2004 11:51:32 PM]
You know what. I have a feeling it might be that
#include <d3dx9.h>
#include <string>
#include <iostream>
#include "cbitmap.h"
#include "output.h"
#include "errors.h"
#define SAFE_RELEASE(p) if(p != NULL){(p)->Release();(p)=NULL;}
using namespace std;
Also, some it successfully loads a few files, then it comes to one (apparently with either no or some weird ascii name) and bombs out.
#include <string>
#include <iostream>
#include "cbitmap.h"
#include "output.h"
#include "errors.h"
#define SAFE_RELEASE(p) if(p != NULL){(p)->Release();(p)=NULL;}
using namespace std;
Also, some it successfully loads a few files, then it comes to one (apparently with either no or some weird ascii name) and bombs out.
VC.NET compiler really messes up the old iostream libraries with the new ones, therefore you must make sure that you dont include any old iostream header files like: iostreams.h
instead always use iostreams
A warning is issued when compiling with the wrong iostream version like this: warning(xxxx): OLD_IOSTREAMS_ARE_DEPRECATED.
If you cannot resolve this problem anyway then I suggest you turn back to vc6.0 because I dont think there is a solution to your problem other than that the compiler handles your std libs inaccurate. Unless M$ has any hints or bugfixes.
I have the same problem porting my game engine to compile with VC.NET so if you DO find a solution, please post something here.
Otherwise dont use std iostreams or strings, write your own.
M$ really rawks, dont they........
[edited by - Hull on January 1, 2004 12:01:40 AM]
instead always use iostreams
A warning is issued when compiling with the wrong iostream version like this: warning(xxxx): OLD_IOSTREAMS_ARE_DEPRECATED.
If you cannot resolve this problem anyway then I suggest you turn back to vc6.0 because I dont think there is a solution to your problem other than that the compiler handles your std libs inaccurate. Unless M$ has any hints or bugfixes.
I have the same problem porting my game engine to compile with VC.NET so if you DO find a solution, please post something here.
Otherwise dont use std iostreams or strings, write your own.
M$ really rawks, dont they........
[edited by - Hull on January 1, 2004 12:01:40 AM]
After extensive commenting out of my CBitmap class I have it not fully functioning (well, not really doing anything at all) but my app runs again but now I'm getting the same exception at here:
if(strPath == NULL || strlen(strPath) > 990)
return;
m_FileName = new char[999];
strcpy(m_FileName, strPath); //This line
(strPath is a char* argument to the function and m_FileName is a member of my MESH class)
This is just rediculously strange
Edited to add that it would seem as though either these functions are being called without the constructors of their classes being called first, or my app is, for some reason, feeding bullshit into these functions (pardon the french).
[edited by - ms291052 on January 1, 2004 12:23:04 AM]
if(strPath == NULL || strlen(strPath) > 990)
return;
m_FileName = new char[999];
strcpy(m_FileName, strPath); //This line
(strPath is a char* argument to the function and m_FileName is a member of my MESH class)
This is just rediculously strange
Edited to add that it would seem as though either these functions are being called without the constructors of their classes being called first, or my app is, for some reason, feeding bullshit into these functions (pardon the french).
[edited by - ms291052 on January 1, 2004 12:23:04 AM]
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement