Not logged in, Join Here! or Log In Below:  
News Articles Search    

 Home / 3D Theory & Graphics / SetTexture() quits app without error msg Account Manager
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.

March 16, 2005, 05:58 AM

hi guys!

a new member, and already bursting in with questions (;

I'm new to DX9 coding , so this is a newbie question:

I want to change the texture of a billboard, depending on user input....
(ie.the mouse moves over a button and changes its texture or if the cursor hovers above a clickable button(billboard) it changes its appearence....etc. you get the idea)

so I implemented several textures in the cursor class and want to switch between those depending on a status variable.
so instead of just calling in the RenderCursor()

  2. g_pd3dDevice->SetTexture( 0, CursorTexturGreen->pTexture );

I use

  3. switch (myCursorTextureID)
  4. {
  5.  case 0:
  6.    g_pd3dDevice->SetTexture( 0, CursorTextureGreen->pTexture );
  7.    break;
  8.  case 1:
  9.    g_pd3dDevice->SetTexture( 0, CursorTextureBlue->pTexture );
  10.    break;
  11.  default:
  12.   g_pd3dDevice->SetTexture( 0, CursorTextureGreen->pTexture );
  13.   break;
  14. }

the problem is, when I change the myCursorTextureID, my app simply quits
without saying anything );

the textures are loaded ok, because when the constructor is called(no matter what the ID is) it displays that texture.... only afterwards when I change it ...boom....

so, what am I doing wrong?

if you want, I cant post the class and the calling code too, but maybe you allready know whats the prob.....

thx in advance!

btw. pTexture is a LPDIRECT3DTEXTURE9 created using D3DXCreateTextureFromFileEx()


March 16, 2005, 06:37 AM

Check the HRESULT return codes of both the file loading routine and the set texture routine. Then check, using the debugger, if all the CursorTexture~ pointers are valid.


March 16, 2005, 07:52 AM

thx 4 the quick reply illco!

and....I just "love" windows....

it just crashed...but the advantage is, after rebooting and compling my prog again, it throws now an access violation error and I could check it out with the debugger :
in the cursor class member SetMyTextureID() just when I try to access the myTextureID it throws CXX0030 and CXX0017 for the texturepointers and all the other class members
so obviously the pointers have gone wild.....

why is this happening?
I didn't mean to harm them (; ... nice pointers....nice....
ehm .... how can I fix it.....any suggestions?...

Rui Martins

March 16, 2005, 09:12 AM

how can I fix it.....any suggestions?


The debugger is your friend.
If it supports break on condition, the make a break when the pointers change.


March 16, 2005, 10:19 AM

oh yes, it is indeed...I tend to forget that ); (I'm using MS VC++6 Stdrd btw)

the app (well it's nothing more than a cursor, some text and 2-3 billboards) performs well..I can move the mouse and its cursor does the desired movement...whoa (;.....
-> so rendering is ok all the time
keyboard and mouse directinput routines work also...and the prog responses as intended (i.e hit esc to quit etc.)

the code doesn't mess with the pointers once the d3dinit functions and the class constructors did their job(at least I'm not aware of any)

it's actually when I try to access the member of the cursor class, to change the Texture, when it throws me out....and the debugger sais mentioned....
however the method of the cursor class can be executed(that is where the member it wants to write to is missing...well not missing, but vanished somehow....into nirvana....pointing to a memory out of the memory of the outer space.....I drift away....).

seriously...I don't quite understand that...

is it possible, that the calling function is missing the class?
... even though the linker said its all ok?

I WILL get this work......ehm...or I start from scratch again (;


Rui Martins

March 16, 2005, 10:46 AM

Did any of your objects get out of scope, and hence the destructor was called, and the memory released, but a pointer you kept (or some api internal datastructure) now has a bogus address, and will blow up, when you use it (directly or indirectly).

As I said, make a Data Break Point on change, and you will carch it in the act.
Step to when you initializes the offending variable/obvject whatever, after inicialization, create a Data BreakPoint, and set it's trigger condition to != of it's current value.

Everytime an instruction is run, the compiler checks your data, and if condition is true, it trigger the brak point, showing you which code is messing it.


March 16, 2005, 03:14 PM

hey rui! thanks to your tip I could track down the problem.

It is a bit strange, but anyways, I could "solve" it....well sort of....

I did a step by step debug, monitoring the relevant values through the whole prog to see this:
The curosr class and the others are intact, but the calling function somehow doesn't see them?!
the values were ok and not deleted(no destructor call), but when the prog jumped to the calling function they were null or pointing to nirvana and inside the classes(for rendering etc) the values are allright again..or never were changed in the first place...whatever...I don't really understand, but I think somehow the calling function calls not the method of the cursor class that was initialized during init or it is not aware of the class(but this one doesn't make sense because the linker would have thrown an error plus the calling function wouldn't be able to call the method in the first place)....

the code uses inline and extern functions in different .h and .cpp files defining classes and functions so this might somehow mess up things.....

but I do a workaround. instead of calling a method in the cursorclass(wich would have made more sense) I declared a global variable with enum stats for changing the cursorstatus and that one is tested in the switch case block.....

but again, thanx guys 4 the help! least I got it working....yeah!!

This thread contains 7 messages.
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.