Advertisement

Global variable NULL pointer on PS3

Started by June 03, 2010 08:48 AM
3 comments, last by midnite 14 years, 5 months ago
Hello,

I have a problem concerning global variables declared in the scripts on PS3. At first it breaks in as_scriptfunction.cpp (459) :
		// Global variables		case asBC_PGA:		case asBC_LDG:		case asBC_PshG4:		case asBC_LdGRdR4:		case asBC_CpyGtoV4:		case asBC_CpyVtoG4:		case asBC_SetG4:			// Need to increase the reference for each global variable			{				void *gvarPtr = (void*)(size_t)asBC_PTRARG(&byteCode[n]);				asCGlobalProperty *prop = GetPropertyByGlobalVarPtr(gvarPtr);				// Only addref the properties once				if( !ptrs.Exists(gvarPtr) )				{					prop->AddRef();					ptrs.PushLast(gvarPtr);				}				asCConfigGroup *group = engine->FindConfigGroupForGlobalVar(prop->id);				if( group != 0 ) group->AddRef();			}			break;


It appears that gvarPtr is NULL (and thus prop as well) and I was able to track this down to the bytecode instruction asBC_SetG4.

This is my script and the generate debug output on PC :
float ttf = 42.42f;Temps: 1    0   0 *    PshC4    0x0          (i:0, f:0)    2   1 *    SetG4    55911208, 1110027796    5   0 *    RET      0


On PC, it works well and the "arg" variable of the bytecode instruction is correctly set but on PS3 this same arg is 0 as you can see here :



I don't know why it does that but here is the faulty code, where the "arg" value is modified and set to 0 somehow in as_bytecode.cpp (547) :
	// The constant is copied to a global variable and then never used again	if( curr->op == asBC_SetV4 && curr->next && curr->next->op == asBC_CpyVtoG4 &&		curr->wArg[0] == curr->next->wArg[0] &&		IsTemporary(curr->wArg[0]) &&		!IsTempVarRead(curr->next, curr->wArg[0]) )	{		curr->op = asBC_SetG4;		curr->size = asBCTypeSize[asBCInfo[asBC_SetG4].type];		*(((asDWORD*)&curr->arg) + AS_PTR_SIZE) = (asDWORD)curr->arg;		*(asPTRWORD*)&curr->arg = (asPTRWORD)curr->next->arg;		DeleteInstruction(curr->next);		*next = GoBack(curr);		return true;	}


If anyone has any idea why that might happen. I tried to set AS_64BIT_PTR and it seemed to work but it crashed elsewhere (in string factory actually) because PS3 is 32 bits for pointers.

Thanks!

Remi Gillig.
Can you try changing the piece of code that you posted to the following?

	// The constant is copied to a global variable and then never used again	if( curr->op == asBC_SetV4 && curr->next && curr->next->op == asBC_CpyVtoG4 &&		curr->wArg[0] == curr->next->wArg[0] &&		IsTemporary(curr->wArg[0]) &&		!IsTempVarRead(curr->next, curr->wArg[0]) )	{		curr->op = asBC_SetG4;		curr->size = asBCTypeSize[asBCInfo[asBC_SetG4].type];		*(((asDWORD*)&curr->arg)+AS_PTR_SIZE) = *ARG_DW(curr->arg);		*ARG_PTR(curr->arg) = *ARG_PTR(curr->next->arg);		DeleteInstruction(curr->next);		*next = GoBack(curr);		return true;	}


Since the arg member is a 64bit word, the way I had written the code would probably not work right on big endian CPUs.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Advertisement
It seems to have solved the problem :) Thanks a lot!

AngelScript is really amazing, I can confirm it works very well on PS3 (but you have to use GCC instead of SNC, which isn't a really big deal for our project).

Remi Gillig.
Great. Thanks for validating the fix, and for the bug report in the first place.

Let me know if you encounter any other problems.

I look forward to seeing what you will produce with the library. :)

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Is the requirement for GCC on the PS3 a new thing? When I originally ported AngelScript to PS3 we were using the SN Systems compiler. Though, we had used the Visual Studio integration of SN and just made a VS project and put the source files in there to copy (so, we didn't use AngelScript's makefiles)

This topic is closed to new replies.

Advertisement