Crystal Space
Welcome, Guest. Please login or register.
July 28, 2014, 01:50:29 pm

Login with username, password and session length
Search:     Advanced search
9005 Posts in 2043 Topics by 8247 Members
Latest Member: Sarahjean
* Home Help Search Login Register
+  Crystal Space
|-+  Crystal Space Development
| |-+  Support
| | |-+  Problem initializing a csRef
« previous next »
Pages: [1] Print
Author Topic: Problem initializing a csRef  (Read 1726 times)
koocake
Jr. Member
**
Posts: 54


View Profile
« on: March 14, 2006, 10:58:11 pm »

Hi there

levelmeshes is a global declared as
Code:
csRef<iMeshList> levelmeshes;

The following function is supposed to initialise levelmeshes and perform some stuff on it.
The function itself runs fine, but when I try to use levelmeshes later on in the code, I get a segfault as though it has not been initialised. Im guessing this is something to do with the fact that levelmeshes is initialised only within the scope of this function?

I also tried to return the raw iMeshList pointer and assigning it to a csRef outside the function but this didnt work either.

Your help with this would be much appreciated!

Code:
void Game::InitialiseLevelColliders()
{
  levelmeshes = engine->GetMeshes(); //initialise levelmeshes

  for(int i=0;i<levelmeshes->GetCount();i++)
  {
     //Do stuff with meshes - works ok
  }
}

regards, Kate
Logged
jorrit
Administrator
Hero Member
*****
Posts: 1706


View Profile
« Reply #1 on: March 14, 2006, 11:07:35 pm »

csRef<iMeshList> levelmeshes; just declares a variable 'levelmeshes' that will be initialized to 0. If you want to use it you'll have to assign some value to it (like a list of meshes you get from somehwere). You cannot just use a reference without first associating an object with it.

Greetings,
Logged
koocake
Jr. Member
**
Posts: 54


View Profile
« Reply #2 on: March 14, 2006, 11:14:40 pm »

The second code block i pasted shows where i initialise levelmeshes.
I can use it within that function with no problems, it is when I try to use it after this outside that function that I get a segfault.

Any ideas?

Kate

Logged
bernardofd
Jr. Member
**
Posts: 74


59948732 bernardofd@click21.com.br
View Profile WWW
« Reply #3 on: March 15, 2006, 12:19:33 am »

Well;

Probably is that the value of the pointer 'levelmeshes' is not set when you try to acess it from outside the function.

1) Is 'levelmeshes' an attribute of a class or just a variable?
    If yes, try to initialize it in your class's constructor function.
2) If not, try to add this code before using the 'levelmeshes' for the first time in any block:

Code:
if (!levelmeshes)
   \\ initialize 'levelmeshes'

\\ uses 'levelmeshes'

I hope this helped.

Regards
Logged

__________________________
Bernardo Figuerêdo Domingues
Computer Science - UFMG - Brazil
Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 5.224 seconds with 15 queries.