dSprintf problem
by Matthew Warner · in Torque 2D Beginner · 07/04/2015 (8:38 pm) · 6 replies
So I was trying to do polygon collisions. I get an error that I am trying to put to much information in my buffer. But I am not setting any information. Infact I used the default toast and got the same problem with that just by switching the shape to a polygon instead of circle. This is where my error is.
int dSprintf(char *buffer, dsize_t bufferSize, const char *format, ...)
{
va_list args;
va_start(args, format);
S32 len = vsprintf(buffer, format, args);
// Sanity!
AssertFatal(len <= bufferSize, "dSprintf - String format exceeded buffer size. This will cause corruption.");
return (len);
}
Sometimes it gives me long lines like this. But when I run the program from the compiler it gives me much smaller numbers. What's the deal? Why am I getting an error because my len is to large??
0 0 0.0000 -1.0000 15.2690 -19.5025 64.0000 -12.8000 14.4800 -19.5025 3823037724445304499356824878417182720.0000 382303138619230
and
0 0 0.0000 -1.0000 15.8125 -19.5025 64.0000 0.0000 14.4800 -19.5025 221831645277151347207202048441319424.0000 221831249136338775885514080721567744.0000
And when compiled and ran from compiler:
0 0 1.0000 0.0000 40.5025 -49.4079 64.0000 -12.8000 40.5025 -51.4079 0.0000 0.0000
int dSprintf(char *buffer, dsize_t bufferSize, const char *format, ...)
{
va_list args;
va_start(args, format);
S32 len = vsprintf(buffer, format, args);
// Sanity!
AssertFatal(len <= bufferSize, "dSprintf - String format exceeded buffer size. This will cause corruption.");
return (len);
}
Sometimes it gives me long lines like this. But when I run the program from the compiler it gives me much smaller numbers. What's the deal? Why am I getting an error because my len is to large??
0 0 0.0000 -1.0000 15.2690 -19.5025 64.0000 -12.8000 14.4800 -19.5025 3823037724445304499356824878417182720.0000 382303138619230
and
0 0 0.0000 -1.0000 15.8125 -19.5025 64.0000 0.0000 14.4800 -19.5025 221831645277151347207202048441319424.0000 221831249136338775885514080721567744.0000
And when compiled and ran from compiler:
0 0 1.0000 0.0000 40.5025 -49.4079 64.0000 -12.8000 40.5025 -51.4079 0.0000 0.0000
About the author
#2
07/08/2015 (2:58 pm)
This could be a problem with using a buffer size that is too small. Could you post the code where you are calling dSprintf?
#3
I loaded the "collision toy".
I changed line 156 in main.cs for the collision toy from
%object.createCircleCollisionShape( 1.5 );
to
%object.createPolygonBoxCollisionShape();
I also tried
% object.createPolygonBoxCollisionShape( 2 );
Didn't matter, just gave an error the second it collided. It's a bug within torque not my code. And I saw some people mention the fix from my second post. But that does nothing. Actually they recommended it without the +1.. on bufferSize+1. which makes the whole program crash because it can't load the module folder because it chops the s from modules. Should be very very very easy to replicate this bug for anyone however I don't know if its isolated to Mac's or if Windows is effected too.
07/08/2015 (3:10 pm)
I didn't call it directly.I loaded the "collision toy".
I changed line 156 in main.cs for the collision toy from
%object.createCircleCollisionShape( 1.5 );
to
%object.createPolygonBoxCollisionShape();
I also tried
% object.createPolygonBoxCollisionShape( 2 );
Didn't matter, just gave an error the second it collided. It's a bug within torque not my code. And I saw some people mention the fix from my second post. But that does nothing. Actually they recommended it without the +1.. on bufferSize+1. which makes the whole program crash because it can't load the module folder because it chops the s from modules. Should be very very very easy to replicate this bug for anyone however I don't know if its isolated to Mac's or if Windows is effected too.
#4
07/08/2015 (3:35 pm)
Okay, I'm on a Windows machine, so my implementation of dSprintf is different. Hopefully someone with an OSX build can help you out.
#5
The odd thing is when I press the compile and run button.. No flaws what-so-ever.. But when I run it outside the compiler it gives me different values and I don't know why. I think its related to why its failing. But I'm not sure.
07/08/2015 (3:47 pm)
The error doesn't reproduce on your machine?The odd thing is when I press the compile and run button.. No flaws what-so-ever.. But when I run it outside the compiler it gives me different values and I don't know why. I think its related to why its failing. But I'm not sure.
#6
But again, I am on Windows, so it may be an issue with the OSX platform.
07/08/2015 (8:50 pm)
Yeah, it seems to work just fine when I replace that line with:%object.createPolygonBoxCollisionShape( 1.5, 1.5 );
But again, I am on Windows, so it may be an issue with the OSX platform.
Matthew Warner
S32 len = vsnprintf(buffer, bufferSize+1, format, args);
Program crashes saying line 424 of osxStrings is the problem. Which goes to the code in the first post.