System.ArgumentOutOfRangeException: Index was out of range. Gamemaker 2 - game-maker-studio-2

I get the error when i compile to HTML target, but not when I use OSX target.
I have the same error on 4 other objects. New to Gamemaker, so having issues on where to look. If I were in another platform I would be able to understand where I had screwed up.
/// #desc add the gun to be part of the player
x = oPlayer.x;
y = oPlayer.y + 10 ;
image_angle = point_direction(x,y,mouse_x,mouse_y); //gun points toward mouse
firingdelay = firingdelay -1; // we we can only shoot every x frames see delay = 5 below
recoil = max(0,recoil -1); // max retrund the biggets of the values given stops us getting a minus number i.e nolower than 0.
if (mouse_check_button(mb_left)) && (firingdelay < 0)
{
recoil = 4;
firingdelay = 5;
ScreenShake(2,10); // add some shake to screen when we fire
with (instance_create_layer(x,y,"Bullets",oBullet))
{
speed = 25; // fixed speed for the object
direction = other.image_angle + random_range(-3,3); //other. is the orginal object outside this created bullet so the gun the random raange offfset the direction a little to get a spread
image_angle = direction;
}
}
x = x - lengthdir_x(recoil,image_angle);
y = y - lengthdir_y(recoil,image_angle);
if (image_angle > 90) && (image_angle < 270) //90 is right , 270 is down this is saying are we left
{
image_yscale = -1;
}
else
{
image_yscale = 1;
}
ERROR
Compiling - gml_Object_oGun_Create_0
Compiling - gml_Object_oGun_Step_1
Error : gml_Object_oGun_Step_1(0) : Fatal Error while compiling gml_Object_oGun_Step_1 - bailing details below
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
at System.ThrowHelper.ThrowArgumentOutOfRange_IndexException () [0x0000c] in :0
at System.Collections.Generic.List`1[T].get_Item (System.Int32 index) [0x00009] in :0
at .. (GMAssetCompiler.GMLToken , System.IO.TextWriter , System.Boolean ) [0x00886] in <07e707e963e944de851ed00054ecf0f5>:0
at .. (GMAssetCompiler.GMLToken , System.IO.TextWriter ) [0x00287] in <07e707e963e944de851ed00054ecf0f5>:0
at .. (GMAssetCompiler.GMLToken , System.IO.TextWriter ) [0x0005a] in <07e707e963e944de851ed00054ecf0f5>:0
at .. (GMAssetCompiler.GMLToken , System.IO.TextWriter , System.Boolean ) [0x000a1] in <07e707e963e944de851ed00054ecf0f5>:0
at .. (GMAssetCompiler.GMLToken , System.IO.TextWriter ) [0x00287] in <07e707e963e944de851ed00054ecf0f5>:0
at .. (GMAssetCompiler.GMLToken , System.IO.TextWriter ) [0x0005a] in <07e707e963e944de851ed00054ecf0f5>:0
at .. (GMAssetCompiler.GMLToken , System.IO.TextWriter ) [0x0019c] in <07e707e963e944de851ed00054ecf0f5>:0
at .. (GMAssetCompiler.GMLToken , System.IO.TextWriter ) [0x00287] in <07e707e963e944de851ed00054ecf0f5>:0
at .. (GMAssetCompiler.GMLToken , System.IO.TextWriter ) [0x0005a] in <07e707e963e944de851ed00054ecf0f5>:0
at .. (GMAssetCompiler.GMLToken , System.IO.TextWriter , System.Boolean ) [0x000a1] in <07e707e963e944de851ed00054ecf0f5>:0
at .. (GMAssetCompiler.GMLToken , System.IO.TextWriter ) [0x00050] in <07e707e963e944de851ed00054ecf0f5>:0
at .. (GMAssetCompiler.GMAssets , . , System.IO.TextWriter ) [0x002d9] in <07e707e963e944de851ed00054ecf0f5>:0

Related

OS X AudioUnit: kAudio_ParamError when setting misc properties on a Generator

I'm building a simple AudioUnit app which should use an AUGraph to connect a generator (which generates, say, a sine wave) to a format converter (because that seems like what I need) to an output device.
Code snippets:
{
AudioComponentDescription desc ;
desc.componentType = kAudioUnitType_Generator ;
desc.componentSubType = kAudioUnitSubType_ScheduledSoundPlayer ;
desc.componentFlags = 0 ;
desc.componentFlagsMask = 0 ;
desc.componentManufacturer = kAudioUnitManufacturer_Apple ;
status = AUGraphAddNode ( mGraph , &desc , &mGeneratorNode ) ;
checkOSStatus ( "creating generator node" , status ) ;
}
I do similarly for mConverterNode with kAudioUnitType_FormatConverter/kAudioUnitSubType_AUConverter and for mOutputNode with kAudioUnitType_Output/kAudioUnitSubType_DefaultOutput.
I then open the graph:
AUGraphOpen ( mGraph ) ; // error checking code omitted from example
I then get references to them:
AUGraphNodeInfo ( mGraph , mGeneratorNode , 0,&mGeneratorRef ) ; // error checking code omitted from example
I then set the format:
{
AudioStreamBasicDescription format ;
format.mSampleRate = mSamplingRate ;
format.mFormatID = kAudioFormatLinearPCM ;
format.mFormatFlags = kAudioFormatFlagIsSignedInteger ;
format.mFramesPerPacket = 1 ;
format.mChannelsPerFrame = 1 ; // mono
format.mBitsPerChannel = 16 ;
format.mBytesPerFrame = format.mBitsPerChannel*format.mChannelsPerFrame/8 ;
format.mBytesPerPacket = format.mBytesPerFrame*format.mFramesPerPacket ;
status = AudioUnitSetProperty ( mGeneratorRef , kAudioUnitProperty_StreamFormat , kAudioUnitScope_Output , kOutputBus , &format,sizeof(format) ) ;
checkOSStatus ( "setting output format" , status ) ;
}
(Note: kOutputBus is an enum to 0; it's an anachronism from a previous example I found. Also, mSamplingRate is a size_t whose value is 48000)
And set the render callback:
{
AURenderCallbackStruct cb ;
cb.inputProc = &_callbackProxy ;
cb.inputProcRefCon = static_cast<void*> ( this ) ;
status = AudioUnitSetProperty ( mGeneratorRef , kAudioUnitProperty_SetRenderCallback , kAudioUnitScope_Output , 0 , &cb,sizeof(cb) ) ;
checkOSStatus ( "setting the generator callback" , status ) ;
}
However, for both the stream format and the render callback I get kAudio_ParamError back as the resultant status.
No matter what I do (mono/stereo, when I place that command, etc), I cannot make it work.
Note: I later do this:
AUGraphConnectNodeInput ( mGraph , mGeneratorNode,0 , mConverterNode,0 ) ;
AUGraphConnectNodeInput ( mGraph , mConverterNode,0 , mOutputNode,0 ) ;
AUGraphInitialize ( mGraph ) ;
AUGraphStart ( mGraph ) ;
// again, error-checking code omitted from example
And it works........ But I can't set those properties and therefore can't generate audio.
What am I missing?
(To people with 1500+ reputation: please make an "osx-sierra" tag; I'm a bit shy of that mark)
From an obscure comment at the end of this:
https://discussions.apple.com/thread/1989797?tstart=0
I ran AUGraphOpen at the very beginning before creating things (why?) and it worked.
But then I was getting invalid format errors, so I set the format on the input of the converter instead of the output of the generator.
But then it wasn't calling the render callback, so I removed the generator altogether and put the render callback on the input of the converter.
At this point, it worked and is generating my sound.
I hope this helps somebody else in the future with this so-horribly-documented API.

MT4 - PERIOD 's

I use below code for #1 screenshot.
int _objfnd = ObjectFind( name );
if ( _objfnd == -1 )
{
ObjectCreate ( _vlineName, OBJ_VLINE, 0, Time[i], 0 );
...
}
and I use below code for #2 screenshot.
int _objfnd = ObjectFind( name );
if ( _objfnd == -1 )
{
datetime _dayTime = Time[i] ;
int _dayNext = PeriodSeconds( _Session_Breaks_Day_Prd ) ;
_dayTime = _dayTime - ( _dayTime % _dayNext ) + _dayNext ;
ObjectCreate ( _vlineName, OBJ_VLINE, 0, _dayTime, 0 ) ;
}
If you figure out my concern,please give me good advice, much appreciate.
A: the code has not handled Daylight Saving Time Shift 2016, Nov-06

QGraphicsView freezes when zooming under Win32

I use QGraphicsView and QGraphicsScene to display a map - a lot of object (lines, images, polygons, etc). I implemented zooming the view this way:
...
void MapView::wheelEvent( QWheelEvent *pEvent )
{
if ( pEvent->modifiers() & Qt::ControlModifier )
{
if ( pEvent->delta() > 0 )
zoomIn();
else
zoomOut();
pEvent->accept();
}
else
{
QGraphicsView::wheelEvent( pEvent );
}
}
...
void MapView::zoomIn( int nValue )
{
m_dZoom = ( nValue == -1 ) ? qMin( ( m_dZoom + m_dZoomStep ), m_dZoomMax ) : qMin( ( m_dZoom + qreal( nValue ) ), m_dZoomMax );
setupTransform();
}
void MapView::zoomOut( int nValue )
{
m_dZoom = ( nValue == -1 ) ? qMax( ( m_dZoom - m_dZoomStep ), m_dZoomMin ) : qMax( ( m_dZoom - qreal( nValue ) ), m_dZoomMin );
setupTransform();
}
...
void MapView::setupTransform()
{
QTransform t = transform();
t.reset();
qreal dScale = qPow( qreal( 2 ), ( m_dZoom - ( m_dZoomMax / 4 ) ) / qreal( 50 ) );
t.scale( dScale, dScale );
setTransform( t );
emit onZoomChanged( m_dZoom );
}
...
When I run application on Linux (CentOS 6.3, Qt 4.8) - zooming the view runs very good (smoothly). But when I run it on Windows (Windows 7 32bit, Qt 5.4) zoomig the view freezes - I constanly rotate the mouse wheel with no effect (no zooming, the view is not responding), and after a second or two later the view starts responding again. When this happens current zoom position turned out to be correctly set - it seems like the view were zooming but not updating the picture. The problem occurs with different zoom values and scroll positions, but always when the view is going to crop map objects (paths).
Do you have any ideas how to fix that problem, or am I doing something wrong?
Thank you very much in advance.

Scrolling and dragging in Corona --> BUG?

I have a event listener assigned to an object. This then triggers the startDrag function. I'm moving my character in the game with dragging. But as soon as I scroll or move the display, my dragging function gets all messed up. It doesn't react as it should and the object(event.target) can't be controlled at all.
Did anyone else had this experience?
Is this a corona bug?
How can I solve this?
Can I temporarily disable the startDrag event listener for the time of scrolling? Or maybe restart it?
All help would be greatly appreciated.
Here is the code...
local physics = require( "physics" )
physics.start()
physics.setContinuous( false )
display.setStatusBar( display.HiddenStatusBar )
physics.setScale( 60 )
physics.setDrawMode( "hybrid" )
local height = display.contentHeight
local width = display.contentWidth
local allElements = display.newGroup()
local texsGroup = display.newGroup()
local backGround = display.newRect(0,0-height,width,2*height)
backGround:setFillColor(91,91,91)
backGround:toBack()
local wallBottom = display.newRect(texsGroup, 0,height-20,width,20)
physics.addBody(wallBottom, "static", { density=5, friction=0.5, bounce=0.3 } )
local tex = {}
local numberRips = 60
local texSize = {
-- w: texwidth, h: texheight, s: strength required
{w=30, h=20, s=1},
{w=20, h=10, s=1.5},
{w=10, h=10, s=2},
}
local r
local lim = display.newGroup()
local function createRips()
local originX = 0
local originY = height -75
for i=0,numberRips do
r = math.random(3)
local x = originX + math.random(width)
local y = originY - math.random(2*height)
tex[i] = display.newRect(lim, x, y, texSize[r].w, texSize[r].h)
tex[i].status = "active"
tex[i].size = texSize[r].s
if (r == 1) then
tex[i]:setFillColor(51,255,0)
elseif (r == 2) then
tex[i]:setFillColor(255,51,51)
elseif (r == 3) then
tex[i]:setFillColor(51,51,255)
end
end
end
createRips()
local w, h, r = width/2, height - 265, 12
local L = display.newCircle(w-115,h+29,r)
local buttonRadius = 35
local button3 = display.newCircle((L.x),(L.y),buttonRadius)
button3.myName = "L"
allElements:insert(button3)
allElements:insert(lim)
allElements:insert(L)
local d, f, b = 15, 1, 0.15
physics.addBody(L, "dynamic", { density=d, friction=f, bounce=b, radius=r } )
button3.isVisible = false
button3.isHitTestable = true
physics.addBody( button3, "static", { density=1, radius=buttonRadius } )
local function addFrictionJoint(a, b, posX, posY, lowerAngle, upperAngle, mT)
local j = physics.newJoint ( "pivot", a, b, posX, posY, rFrom, rTo)
j.isLimitEnabled = true
j:setRotationLimits (lowerAngle, upperAngle)
return j
end
-- JOINTS
addFrictionJoint( button3, L, L.x, L.y, 0, 0 )
local function startDrag( event, params )
local body = event.target
local phase = event.phase
local stage = display.getCurrentStage()
local direction = event.direction
if "began" == phase then
stage:setFocus( body, event.id )
body.isFocus = true
event.target.bodyType = "dynamic"
-- Create a temporary touch joint and store it in the object for later reference
if params and params.center then
-- drag the body from its center point
body.tempJoint = physics.newJoint( "touch", body, body.x, body.y )
else
-- drag the body from the point where it was touched
body.tempJoint = physics.newJoint( "touch", body, event.x, event.y )
end
--body.tempJoint.maxForce = 0.25*body.tempJoint.maxForce
-- Apply optional joint parameters
if params then
local maxForce, frequency, dampingRatio
if params.maxForce then
-- Internal default is (1000 * mass), so set this fairly high if setting manually
body.tempJoint.maxForce = params.maxForce
end
if params.frequency then
-- This is the response speed of the elastic joint: higher numbers = less lag/bounce
body.tempJoint.frequency = params.frequency
end
if params.dampingRatio then
-- Possible values: 0 (no damping) to 1.0 (critical damping)
body.tempJoint.dampingRatio = params.dampingRatio
end
end
elseif body.isFocus then
if "moved" == phase then
-- Update the joint to track the touch
body.tempJoint:setTarget( event.x, event.y )
elseif "ended" == phase or "cancelled" == phase then
stage:setFocus( body, nil )
body.isFocus = false
-- Remove the joint when the touch ends
body.tempJoint:removeSelf()
body.bodyType = "static"
end
end
-- Stop further propagation of touch event
return true
end
function moveCamera(e)
if button3.y < -lim.y + 300 then
allElements.y = -(button3.y - 300)
end
end
Runtime:addEventListener("enterFrame", moveCamera)
button3:addEventListener( "touch", startDrag )
When you scroll the screen the touch event and the physics object are in different coordinate systems. See localToContent/globalToContent

Dynamic image creation with touch action in corona

I have touch problem with dynamic image creation. my code is
local widget = require "widget"
--Hide status bar
display.setStatusBar( display.HiddenStatusBar )
--bg image
local backgroundPortrait = display.newImage( "background.png", 0, 0 )
--local image1Group
--image1Group = display.newGroup()
--3 frames
local frame1 = display.newImageRect( "icon_1.png", 75, 75 )
frame1:setReferencePoint( display.CenterReferencePoint )
frame1.x = 160
frame1.y = 120
local frame2 = display.newImageRect( "icon_2.png", 75, 75 )
frame2:setReferencePoint( display.CenterReferencePoint )
frame2.x = 60
frame2.y = 360
local frame3 = display.newImageRect( "icon_3.png", 75, 75 )
frame3:setReferencePoint( display.CenterReferencePoint )
frame3.x = 260
frame3.y = 360
-- Center image
function createImage()
centerFrame = display.newImageRect( "additionalvampire1.jpg", 75, 75 )
centerFrame:setReferencePoint( display.CenterReferencePoint )
centerFrame.x = display.contentCenterX
centerFrame.y = display.contentCenterY
centerFrame:addEventListener("touch", centerFrame)
end
createImage()
function removeTouchEventFun()
centerFrame:removeEventListener("touch", centerFrame)
end
function transitionCompleted(centerFrame)
print("transitionCompleted called")
removeTouchEventFun()
centerFrame:removeSelf()
centerFrame=nil
createImage()
end
function centerFrame:touch(event)
if event.phase == "began" then
self.markX = self.x -- store x location of object
self.markY = self.y -- store y location of object
elseif event.phase == "moved" then
local x = (event.x - event.xStart) + self.markX
local y = (event.y - event.yStart) + self.markY
self.x, self.y = x, y -- move object based on calculations above
elseif event.phase == "ended" then
if (centerFrame.x<=160 and centerFrame.y>=240) then
transition.to( centerFrame, { time=1000, alpha=1, x=60, y=360, width=1 ,height=1, onComplete= transitionCompleted } )
elseif (centerFrame.x>=160 and centerFrame.y>=240) then
transition.to( centerFrame, { time=1000, alpha=1, x=260, y=360, width=1 ,height=1, onComplete= transitionCompleted } )
else
transition.to( centerFrame, { time=1000, alpha=1, x=160, y=120, width=1 ,height=1, onComplete= transitionCompleted } )
end
end
return true
end
when drag the image to any one frame it is zoom-out and remove the object and create the another image. for this image touch not working...
i need image creation with touch action when the image transition compete method. what should i do?...
local centerFrame
function transitionCompleted(centerFrame)
print("transitionCompleted called")
if(centerFrame) then
centerFrame:removeSelf()
centerFrame=nil
createImage()
end
end
function onCenterFrameTouch(event)
//your code here
end
function createImage()
centerFrame = display.newImageRect( "additionalvampire1.jpg", 75, 75 )
centerFrame:setReferencePoint( display.CenterReferencePoint )
centerFrame.x = display.contentCenterX
centerFrame.y = display.contentCenterY
centerFrame:addEventListener("touch", onCenterFrameTouch)
end

Resources