Ok so I've got these typedef structs:
typedef struct {
float objectTransformX;
} Object;
typedef struct {
float lookAtZ;
} SceneCamera;
typedef struct {
Object *Object;
SceneCamera Camera;
bool Active;
} Frames;
And I've got this class:
class Scenario {
private:
int currentFrame;
int fps;
bool allowOverwrite;
Frames *Frame;
.....
}
And I've got the constructor:
Scenario::Scenario(int objectCount,int lengthInSeconds,bool allowOverwrite,int fps) {
frameCount = lengthInSeconds*fps;
Frame = (Frames*)malloc(sizeof(Frames)*frameCount);
Frame->Object = (Object*)malloc(sizeof(Object)*objectCount);
....
Frame[t].Camera.lookAtZ = 0;
for (int i = 0;i < objectCount;i++) {
Frame[t].Active = false;
Frame[t].Object.objectTransformX = 0;
.....
}
}
Why do I get an exception when I try to assign a value to objectTransformX... I did allocate memory didn't I?
I got an unhandled exception, which states that the memory is outside the program.
CXX0030 error in VC++.
Does this code compile ?
Since *Object is a pointer, I think you should use this notation:
Frame[t].Object->objectTransformX = 0;
instead of:
Frame[t].Object.objectTransformX = 0;
As for the memory exception, you are allocating memory for objectCount Objects and frameCount Frames, but we don't know what's the value of 't' (in fact, we don't even see where you declare it) at the time you get the error.
Also, what is this code doing inside a for loop where you only increment 'i' (and 't' remains unchanged) ?:
Free Guide: Managing storage for virtual environments
Complete a brief survey to get a complimentary 70-page whitepaper featuring the best methods and solutions for your virtual environment, as well as hypervisor-specific management advice from TechTarget experts. Don’t miss out on this exclusive content!
Discuss This Question: 1  Reply