The C library function
malloc() returns a
void*. You have to cast the result to the appropriate type to placate the compiler.
That said, you have other problems. You are allocating enough space for 5 scene nodes, but you need to allocate space for 5 scene node pointers. The correct code would be...
Code: Select all
scene::ISceneNode** nodes = 0;
u32 nnodes = 0;
// figure out value for nnodes
nodes = (scene::ISceneNode**)malloc (nnodes * sizeof (scene::ISceneNode*));
for (u32 i = 0; i < nnodes; ++i) {
nodes [i] = //...
}
// avoid leaking memory
free (nodes);
To eliminate the cast, you could use the C++ new operator.
Code: Select all
scene::ISceneNode** nodes = 0;
u32 nnodes = 0;
// figure out value for nnodes
nodes = new scene::ISceneNode*[nnodes];
for (u32 i = 0; i < nnodes; ++i) {
nodes [i] = //...
}
// avoid leaking memory
delete [] nodes;
To simplify this greatly, you could just use a
core::array<scene::ISceneNode*> or even a
std::vector<scene::ISceneNode*>. Both will manage memory allocation and will dynamically resize as is necessary.
Code: Select all
core::array<scene::ISceneNode*> nodes;
u32 nnodes = 0;
// figure out a value for nnodes
for (u32 i = 0; i < nnodes; ++i) {
nodes.push_back(/*...*/);
}
// no need to deallocate, it is done automatically
Travis