PDA

View Full Version : Crashing out when using CreateEntity



Pleng
05-02-2009, 08:43 AM
I am trying to create a new Entity whilst the player is in a conversation dialog with another character. I am using the following line to create the entity

CreateEntity(Map:GetActiveMap(),GetPlayer:GetPos() ,"items/luckystar/luckystar.lua");

When the line of code is executed, Novashell bombs out. I have tried it on both my laptop and desktop computers. When using the desktop I am given the opportunity to debug using Visual Studio, at which point I am given the following message:



Unhandled exception at 0x005c4459 in game.exe: 0xC0000005: Access violation reading location 0x00000000


I have also tried using this:CreateEntity(Map:GetActiveMap(),GetPlayer:Get Pos(),"items/luckystar/luckystar.lua"); but I get the same problem.

Seth
05-02-2009, 09:22 AM
Hmm... maybe GetPlayer is nil. GetPlayer is supposed to be a pointer that the player script can set, so the camera knows who to follow when there are many players (like if you cut and paste a bunch of them in tree world).

But some examples, like that mario-like retro one don't use it all, so if you had started with that script, GetPlayer would be nil, causing the crash.

To test, instead of running that, do:


LogMsg("Player is", GetPlayer);

If it says nil, that is the problem.

As much as I'd like to make novashell totally crash-proof, I left in some direct pointer manipulation for speed and don't always check to see if it's valid.

Note, if that is the problem, the fix is to run
AssignPlayerToCameraIfNeeded(this);
in your player's Update(). (this is in player_utils.lua)

This way, if you cut and paste players around, the game still always knows who your "main" player is, useful for the camera and dialog stuff sometimes.

Pleng
05-02-2009, 10:44 AM
Hmm... maybe GetPlayer is nil. ..
But some examples, like that mario-like retro one don't use it all, so if you had started with that script, GetPlayer would be nil, causing the crash.

To test, instead of running that, do:


LogMsg("Player is", GetPlayer);


Hi Seth, thanks for the response, but I don't think that's the problem. That code gives me the message:

Player is Entity 449(Player)

Seth
05-02-2009, 12:23 PM
That code gives me the message: Player is Entity 449(Player)

Hrm, yeah it must be something in "items/luckystar/luckystar.lua" then. You would need to isolate the exact script command causing the crash by removing everything then adding stuff in until it crashes again.

add some LogMsg() statements and then check log.txt after the crash as well, I'm not sure if those would make it to get written or not...

If you let me know where I can probably fix it to give an error message instead of crash or whatever.

Pleng
05-02-2009, 02:37 PM
I'm baffled.

I've commented out every line in luckystar.lua so it now looks like this:



function OnInit()
//this:SetVisualProfile("items/luckystar/luckystar.xml", "luckystar");
//this:LoadCollisionInfo("~/slash.col");
end

function OnPostInit()

//this:SetDensity(0);
//this:SetCollisionListenCategory(C_CATEGORY_PLAYER, true);
//this:SetCollisionCategories(C_CATEGORIES_NONE);

end

and it's still crashing out :(

Seth
05-03-2009, 12:29 AM
Hmm, I'll bet it's the Map:GetActiveMap() part in your CreateEntity statement?

Did you set the Map variable yourself? If not, you should be using GetMapManager:GetActiveMap(), or simply nil.

Pleng
05-03-2009, 06:35 AM
Thanks Seth, that's solved the problem. :D